20 #include <epicsAssert.h>
22 #include <pv/pvIntrospect.h>
23 #include <pv/typeCast.h>
24 #include <pv/anyscalar.h>
25 #include <pv/sharedVector.h>
28 #include <compilerDependencies.h>
30 #if defined(vxWorks) && !defined(_WRS_VXWORKS_MAJOR)
31 typedef class std::ios std::ios_base;
34 namespace epics {
namespace pvData {
100 typedef std::tr1::shared_ptr<PVStructureArray> PVStructureArrayPtr;
102 typedef std::tr1::shared_ptr<PVStructureArrayPtrArray> PVStructureArrayPtrArrayPtr;
120 typedef std::tr1::shared_ptr<PVUnionArray> PVUnionArrayPtr;
122 typedef std::tr1::shared_ptr<PVUnionArrayPtrArray> PVUnionArrayPtrArrayPtr;
125 typedef std::tr1::shared_ptr<PVDataCreate> PVDataCreatePtr;
142 virtual void postPut() = 0;
154 public std::tr1::enable_shared_from_this<PVField>
181 std::size_t getFieldOffset()
const;
188 std::size_t getNextFieldOffset()
const;
193 std::size_t getNumberFields()
const;
203 virtual void setImmutable();
214 inline const PVStructure * getParent()
const {
return parent;}
224 void setPostHandler(PostHandlerPtr
const &postHandler);
230 virtual bool equals(PVField &pv);
238 void copy(
const PVField& from);
239 void copyUnchecked(
const PVField& from);
241 static size_t num_instances;
244 PVField::shared_pointer getPtrSelf()
246 return shared_from_this();
248 explicit PVField(FieldConstPtr field);
249 void setParentAndName(PVStructure *parent,
std::string const & fieldName);
251 static void computeOffset(
const PVField *pvField);
252 static void computeOffset(
const PVField *pvField,std::size_t offset);
257 size_t nextFieldOffset;
260 friend class PVDataCreate;
261 friend class PVStructure;
262 EPICS_NOT_COPYABLE(PVField)
308 virtual void getAs(
void *,
ScalarType)
const = 0;
311 virtual void getAs(
AnyScalar& v)
const =0;
329 virtual void putFrom(
const void *,
ScalarType) = 0;
331 inline void putFrom(
const AnyScalar& v) {
333 putFrom(v.unsafe(), v.
type());
336 virtual void assign(
const PVScalar&) = 0;
338 virtual void copy(
const PVScalar& from) = 0;
339 virtual void copyUnchecked(
const PVScalar& from) = 0;
342 explicit PVScalar(ScalarConstPtr
const & scalar);
343 EPICS_NOT_COPYABLE(PVScalar)
351 inline void store(T v) {
362 if (maxLength > 0 && val.
length() > maxLength)
382 typedef T value_type;
384 typedef const T* const_pointer;
416 virtual void operator<<=(
typename storage_t::arg_type value);
418 template<
typename T1>
419 inline T1 getAs()
const {
420 T1 result(castUnsafe<T1,T>(
get()));
424 template<
typename T1>
425 inline void putFrom(
typename detail::ScalarStorageOps<T1>::arg_type val) {
426 put(castUnsafe<T,T1>(val));
429 inline void putFrom(
const AnyScalar& v) {
431 PVScalar::putFrom(v);
434 virtual void assign(
const PVScalar& scalar) OVERRIDE FINAL;
435 virtual void copy(
const PVScalar& from) OVERRIDE FINAL;
436 virtual void copyUnchecked(
const PVScalar& from) OVERRIDE FINAL;
438 virtual void serialize(ByteBuffer *pbuffer,
439 SerializableControl *pflusher)
const OVERRIDE;
440 virtual void deserialize(ByteBuffer *pbuffer,
441 DeserializableControl *pflusher) OVERRIDE FINAL;
444 explicit PVScalarValue(ScalarConstPtr
const & scalar)
445 : PVScalar(scalar), storage() {}
446 virtual void getAs(
void * result, ScalarType rtype)
const OVERRIDE FINAL
449 castUnsafeV(1, rtype, result, typeCode, (
const void*)&src);
452 virtual void getAs(AnyScalar& v)
const OVERRIDE FINAL
459 castUnsafeV(1, typeCode, (
void*)&result, stype, src);
475 return o << static_cast<int>(
get());
481 return o << static_cast<unsigned int>(
get());
487 return o << std::boolalpha << static_cast<bool>(
get());
504 typedef std::tr1::shared_ptr<PVBoolean> PVBooleanPtr;
505 typedef std::tr1::shared_ptr<PVByte> PVBytePtr;
506 typedef std::tr1::shared_ptr<PVShort> PVShortPtr;
507 typedef std::tr1::shared_ptr<PVInt> PVIntPtr;
508 typedef std::tr1::shared_ptr<PVLong> PVLongPtr;
509 typedef std::tr1::shared_ptr<PVUByte> PVUBytePtr;
510 typedef std::tr1::shared_ptr<PVUShort> PVUShortPtr;
511 typedef std::tr1::shared_ptr<PVUInt> PVUIntPtr;
512 typedef std::tr1::shared_ptr<PVULong> PVULongPtr;
513 typedef std::tr1::shared_ptr<PVFloat> PVFloatPtr;
514 typedef std::tr1::shared_ptr<PVDouble> PVDoublePtr;
540 typedef std::tr1::shared_ptr<PVString> PVStringPtr;
567 virtual void setImmutable() OVERRIDE;
572 virtual std::
size_t getLength() const = 0;
577 virtual
void setLength(std::
size_t length) = 0;
582 virtual std::
size_t getCapacity() const = 0;
587 bool isCapacityMutable() const;
592 void setCapacityMutable(
bool isMutable);
597 virtual
void setCapacity(std::
size_t capacity) = 0;
600 virtual std::
ostream& dumpValue(std::
ostream& o, std::
size_t index) const = 0;
604 void checkLength(
size_t length) const;
606 bool capacityMutable;
611 epicsShareExtern std::
ostream& operator<<(format::array_at_internal const& manip, const PVArray& array);
651 out = shared_vector_convert<const T>(temp);
691 void copyUnchecked(
const PVScalarArray& from) {
694 shared_vector<const void> temp;
695 from._getAsVoid(temp);
700 explicit PVScalarArray(ScalarArrayConstPtr
const & scalarArray);
702 friend class PVDataCreate;
703 EPICS_NOT_COPYABLE(PVScalarArray)
726 virtual void setImmutable() OVERRIDE FINAL;
746 return getSubFieldImpl(a,
false);
750 FORCE_INLINE std::tr1::shared_ptr<const PVField> getSubField(A a)
const
752 return getSubFieldImpl(a,
false);
765 template<
typename PVD,
typename A>
768 STATIC_ASSERT(PVD::isPVField);
772 template<
typename PVD,
typename A>
773 inline std::tr1::shared_ptr<const PVD> getSubField(A a)
const
775 STATIC_ASSERT(PVD::isPVField);
788 return getSubFieldImpl(a,
true);
792 FORCE_INLINE std::tr1::shared_ptr<const PVField> getSubFieldT(A a)
const
794 return getSubFieldImpl(a,
true);
798 static void throwBadFieldType(
const char *name);
799 static void throwBadFieldType(std::size_t fieldOffset);
800 static FORCE_INLINE
void throwBadFieldType(
const std::string& name) {
801 throwBadFieldType(name.
c_str());
805 template<
typename PVD,
typename A>
806 inline std::tr1::shared_ptr<PVD> getSubFieldT(A a)
808 STATIC_ASSERT(PVD::isPVField);
809 std::tr1::shared_ptr<PVD> ret(std::tr1::dynamic_pointer_cast<PVD>(getSubFieldImpl(a,
true)));
811 throwBadFieldType(a);
815 template<
typename PVD,
typename A>
816 inline std::tr1::shared_ptr<const PVD> getSubFieldT(A a)
const
818 STATIC_ASSERT(PVD::isPVField);
819 std::tr1::shared_ptr<const PVD> ret(std::tr1::dynamic_pointer_cast<const PVD>(getSubFieldImpl(a,
true)));
821 throwBadFieldType(a);
830 virtual void serialize(
831 ByteBuffer *pbuffer,SerializableControl *pflusher)
const OVERRIDE FINAL;
837 virtual void deserialize(
838 ByteBuffer *pbuffer,DeserializableControl *pflusher) OVERRIDE FINAL;
845 virtual void serialize(ByteBuffer *pbuffer,
846 SerializableControl *pflusher,BitSet *pbitSet)
const OVERRIDE FINAL;
853 virtual void deserialize(ByteBuffer *pbuffer,
854 DeserializableControl*pflusher,BitSet *pbitSet) OVERRIDE FINAL;
859 explicit PVStructure(StructureConstPtr
const & structure);
865 PVStructure(StructureConstPtr
const & structure,PVFieldPtrArray
const & pvFields);
869 void copy(
const PVStructure& from);
871 void copyUnchecked(
const PVStructure& from);
872 void copyUnchecked(
const PVStructure& from,
const BitSet& maskBitSet,
bool inverse =
false);
901 FORCE_INLINE
Formatter& show(
const BitSet& set) { xshow = &set;
return *
this; }
903 FORCE_INLINE
Formatter& highlight(
const BitSet& set) { xhighlight = &set;
return *
this; }
905 FORCE_INLINE
Formatter& mode(mode_t m) { xmode = m;
return *
this; }
907 FORCE_INLINE
Formatter& format(format_t f) { xfmt = f;
return *
this; }
918 return getSubFieldImpl(name.
c_str(),
throws);
920 PVFieldPtr getSubFieldImpl(
const char *name,
bool throws)
const;
921 PVFieldPtr getSubFieldImpl(std::size_t fieldOffset,
bool throws)
const;
923 PVFieldPtrArray pvFields;
924 StructureConstPtr structurePtr;
926 friend class PVDataCreate;
927 EPICS_NOT_COPYABLE(PVStructure)
949 typedef const PVUnion & const_reference;
969 inline PVField::const_shared_pointer
get()
const {
return value; }
971 template<
typename PVT>
972 inline std::tr1::shared_ptr<PVT>
get() {
973 STATIC_ASSERT(PVT::isPVField);
977 template<
typename PVT>
978 inline std::tr1::shared_ptr<const PVT>
get()
const {
979 STATIC_ASSERT(PVT::isPVField);
991 template<
typename PVT>
992 inline std::tr1::shared_ptr<PVT> select(int32 index) {
993 STATIC_ASSERT(PVT::isPVField);
1005 template<
typename PVT>
1006 inline std::tr1::shared_ptr<PVT> select(
std::string const & fieldName) {
1029 set(selector, value);
1058 virtual void serialize(
1065 virtual void deserialize(
1076 void copyUnchecked(
const PVUnion& from);
1079 static PVDataCreatePtr pvDataCreate;
1081 friend class PVDataCreate;
1094 template<
typename T>
1096 typedef std::tr1::shared_ptr<std::vector<T> > shared_vector;
1100 void operator()(T*){vec.reset();}
1104 template<
typename T,
class Base>
1108 typedef T value_type;
1110 typedef const T* const_pointer;
1113 typedef ::epics::pvData::shared_vector<T>
svector;
1114 typedef ::epics::pvData::shared_vector<const T>
const_svector;
1118 template<
typename A>
1159 return thaw(result);
1174 template<
typename T>
1175 class epicsShareClass PVValueArray :
public detail::PVVectorStorage<T,PVScalarArray> {
1176 typedef detail::PVVectorStorage<T,PVScalarArray> base_t;
1178 POINTER_DEFINITIONS(PVValueArray);
1179 typedef T value_type;
1181 typedef const T* const_pointer;
1184 typedef ::epics::pvData::shared_vector<T> svector;
1185 typedef ::epics::pvData::shared_vector<const T> const_svector;
1188 static const ScalarType typeCode;
1193 virtual ~PVValueArray();
1198 virtual ArrayConstPtr getArray() const OVERRIDE FINAL;
1200 virtual std::
ostream& dumpValue(std::
ostream& o) const OVERRIDE FINAL;
1201 virtual std::
ostream& dumpValue(std::
ostream& o,
size_t index) const OVERRIDE FINAL;
1203 virtual
size_t getLength() const OVERRIDE FINAL {
return value.size();}
1204 virtual size_t getCapacity() const OVERRIDE FINAL {
return value.capacity();}
1206 virtual void setCapacity(
size_t capacity) OVERRIDE FINAL;
1207 virtual void setLength(
size_t length) OVERRIDE FINAL;
1210 virtual void swap(const_svector &other) OVERRIDE FINAL;
1211 virtual void replace(
const const_svector& next) OVERRIDE FINAL;
1224 const_svector value;
1225 friend class PVDataCreate;
1248 typedef ::epics::pvData::shared_vector<PVStructurePtr>
svector;
1249 typedef ::epics::pvData::shared_vector<const PVStructurePtr>
const_svector;
1260 virtual size_t getLength() const OVERRIDE FINAL {
return value.size();}
1261 virtual size_t getCapacity() const OVERRIDE FINAL {
return value.capacity();}
1267 virtual void setCapacity(
size_t capacity) OVERRIDE FINAL;
1272 virtual void setLength(std::size_t length) OVERRIDE FINAL;
1284 std::size_t append(std::size_t number);
1291 bool remove(std::size_t offset,std::size_t number);
1298 virtual void swap(const_svector &other) OVERRIDE FINAL;
1300 checkLength(other.size());
1322 const_svector value;
1323 friend class PVDataCreate;
1347 typedef ::epics::pvData::shared_vector<PVUnionPtr>
svector;
1348 typedef ::epics::pvData::shared_vector<const PVUnionPtr>
const_svector;
1359 virtual size_t getLength() const OVERRIDE FINAL {
return value.size();}
1360 virtual size_t getCapacity() const OVERRIDE FINAL {
return value.capacity();}
1366 virtual void setCapacity(
size_t capacity) OVERRIDE FINAL;
1371 virtual void setLength(std::size_t length) OVERRIDE FINAL;
1383 std::size_t append(std::size_t number);
1390 bool remove(std::size_t offset,std::size_t number);
1397 virtual void swap(const_svector &other) OVERRIDE;
1399 checkLength(other.size());
1421 const_svector value;
1422 friend class PVDataCreate;
1431 typedef std::tr1::shared_ptr<PVBooleanArray> PVBooleanArrayPtr;
1434 typedef std::tr1::shared_ptr<PVByteArray> PVByteArrayPtr;
1437 typedef std::tr1::shared_ptr<PVShortArray> PVShortArrayPtr;
1440 typedef std::tr1::shared_ptr<PVIntArray> PVIntArrayPtr;
1443 typedef std::tr1::shared_ptr<PVLongArray> PVLongArrayPtr;
1446 typedef std::tr1::shared_ptr<PVUByteArray> PVUByteArrayPtr;
1449 typedef std::tr1::shared_ptr<PVUShortArray> PVUShortArrayPtr;
1452 typedef std::tr1::shared_ptr<PVUIntArray> PVUIntArrayPtr;
1455 typedef std::tr1::shared_ptr<PVULongArray> PVULongArrayPtr;
1458 typedef std::tr1::shared_ptr<PVFloatArray> PVFloatArrayPtr;
1461 typedef std::tr1::shared_ptr<PVDoubleArray> PVDoubleArrayPtr;
1464 typedef std::tr1::shared_ptr<PVStringArray> PVStringArrayPtr;
1467 struct pvfield_factory;
1474 class epicsShareClass PVDataCreate {
1475 friend struct detail::pvfield_factory;
1520 template<
typename PVT>
1589 template<
typename PVAT>
1610 return createPVStructureArray(fieldCreate->createStructureArray(structure));
1628 return createPVUnionArray(fieldCreate->createUnionArray(punion));
1634 PVUnionArrayPtr createPVVariantUnionArray();
1638 FieldCreatePtr fieldCreate;
1639 EPICS_NOT_COPYABLE(PVDataCreate)
1652 bool epicsShareExtern
operator==(
const PVField&,
const PVField&);
1654 static inline bool operator!=(
const PVField& a,
const PVField& b)
PVStructure * getParent()
const std::string & getFieldName() const
PVUnionArrayPtr createPVUnionArray(UnionConstPtr const &punion)
virtual size_t getLength() const OVERRIDE FINAL
PVStructureArrayPtr createPVStructureArray(StructureConstPtr const &structure)
Class that holds the data for each possible scalar type.
virtual size_t getCapacity() const OVERRIDE FINAL
std::tr1::shared_ptr< const StructureArray > StructureArrayConstPtr
virtual const_svector view() const OVERRIDE FINAL
Fetch a read-only view of the current array data.
ScalarType type() const
Type code of contained value. Or (ScalarType)-1 is empty.
Data class for a structureArray.
virtual ArrayConstPtr getArray() const OVERRIDE FINAL
std::tr1::shared_ptr< PVUnion > PVUnionPtr
PVArray is the base class for all array types.
Data interface for a structure,.
std::tr1::shared_ptr< PVScalar > PVScalarPtr
void put(typename storage_t::arg_type v)
std::tr1::shared_ptr< const Structure > StructureConstPtr
int32 getSelectedIndex() const
virtual void replace(const const_svector &other) OVERRIDE FINAL
const PVFieldPtrArray & getPVFields() const
UnionArrayConstPtr getUnionArray() const
constexpr void replace(_ForwardIterator __first, _ForwardIterator __last, const _Tp &__old_value, const _Tp &__new_value)
This class implements introspection object for Array.
std::tr1::shared_ptr< PVT > createPVScalar()
Callback class for serialization.
std::tr1::shared_ptr< PVAT > createPVScalarArray()
std::tr1::shared_ptr< const UnionArray > UnionArrayConstPtr
PVString is special case, since it implements SerializableArray.
std::tr1::shared_ptr< const Field > FieldConstPtr
const FieldConstPtr & getField() const
static const openmode out
void getAs(shared_vector< const T > &out) const
Base class for a scalarArray.
This class implements a Bytebuffer that is like the java.nio.ByteBuffer.
basic_string< char > string
std::tr1::shared_ptr< PVScalarArray > PVScalarArrayPtr
constexpr _Require< __not_< __is_tuple_like< _Tp > >, is_move_constructible< _Tp >, is_move_assignable< _Tp > > swap(_Tp &, _Tp &) noexcept(__and_< is_nothrow_move_constructible< _Tp >, is_nothrow_move_assignable< _Tp > >::value)
static const int32 UNDEFINED_INDEX
std::tr1::shared_ptr< PVField > PVFieldPtr
bool operator==(const _CharT *__lhs, const basic_string< _CharT, _Traits, _Alloc > &__rhs)
PVScalar is the base class for each scalar field.
virtual ArrayConstPtr getArray() const OVERRIDE FINAL
virtual size_t getLength() const OVERRIDE FINAL
std::tr1::shared_ptr< const Union > UnionConstPtr
constexpr iterator_traits< _InputIterator >::difference_type count(_InputIterator __first, _InputIterator __last, const _Tp &__value)
Data class for a unionArray.
shared_ptr< _Tp > static_pointer_cast(const shared_ptr< _Up > &__r) noexcept
const UnionConstPtr & getUnion() const
constexpr _OI copy(_II __first, _II __last, _OI __result)
This is a singleton class for creating data instances.
This class is implemented by code that calls setPostHander.
const _CharT * c_str() const noexcept
template class for all extensions of PVArray.
const StructureConstPtr & getStructure() const
void set(PVFieldPtr const &value)
std::tr1::shared_ptr< PVField > getSubField(A a)
Callback class for deserialization.
virtual void replace(const const_svector &other) OVERRIDE FINAL
PVField is the base class for each PVData field.
std::tr1::shared_ptr< PVStructure > PVStructurePtr
shared_ptr< _Tp > dynamic_pointer_cast(const shared_ptr< _Up > &__r) noexcept
void putFrom(const shared_vector< const T > &inp)
basic_ostream< char > ostream
virtual const_svector view() const OVERRIDE
Fetch a read-only view of the current array data.
virtual size_t getCapacity() const OVERRIDE FINAL
std::tr1::shared_ptr< const ScalarArray > ScalarArrayConstPtr
Class for serializing arrays.
bool operator!=(const _CharT *__lhs, const basic_string< _CharT, _Traits, _Alloc > &__rhs)
std::tr1::shared_ptr< PVD > getSubField(A a)
size_type length() const noexcept
std::tr1::shared_ptr< const Scalar > ScalarConstPtr
valarray< _Tp > & operator<<=(const _Tp &)
Class for serializing bitSets.
std::tr1::shared_ptr< PVField > getSubFieldT(A a)
PVUnion has a single subfield.
Base class for serialization.
void assign(const PVScalarArray &pv)
StructureArrayConstPtr getStructureArray() const
__rvalue_stream_insertion_t< _Ostream, _Tp > operator<<(_Ostream &&__os, const _Tp &__x)
virtual size_t getCapacity() const OVERRIDE FINAL
Common code for PV*Array.
std::tr1::shared_ptr< const Array > ArrayConstPtr
FORCE_INLINE const PVDataCreatePtr & getPVDataCreate()
std::tr1::shared_ptr< PostHandler > PostHandlerPtr
virtual void putFrom(const void *src, ScalarType stype)
Convert and assign.
virtual const_svector view() const OVERRIDE FINAL
Fetch a read-only view of the current array data.
valarray< _Tp > & operator>>=(const _Tp &)