PVData C++  8.0.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
pvData.h
1 /* pvData.h */
2 /*
3  * Copyright information and license terms for this software can be
4  * found in the file LICENSE that is included with the distribution
5  */
9 #ifndef PVDATA_H
10 #define PVDATA_H
11 
12 #include <string>
13 #include <map>
14 #include <stdexcept>
15 #include <algorithm>
16 #include <iterator>
17 #include <iostream>
18 #include <iomanip>
19 
20 #include <epicsAssert.h>
21 
22 #include <pv/pvIntrospect.h>
23 #include <pv/typeCast.h>
24 #include <pv/anyscalar.h>
25 #include <pv/sharedVector.h>
26 
27 #include <shareLib.h>
28 #include <compilerDependencies.h>
29 
30 #if defined(vxWorks) && !defined(_WRS_VXWORKS_MAJOR)
31 typedef class std::ios std::ios_base;
32 #endif
33 
34 namespace epics { namespace pvData {
35 
41 class PostHandler;
42 
43 class PVField;
44 class PVScalar;
45 
46 class PVScalarArray;
47 
48 class PVStructure;
49 
50 class PVUnion;
51 
52 
53 
54 template<typename T> class PVScalarValue;
55 template<typename T> class PVValueArray;
56 
57 
61 typedef std::tr1::shared_ptr<PostHandler> PostHandlerPtr;
62 
66 typedef std::tr1::shared_ptr<PVField> PVFieldPtr;
71 typedef std::vector<PVFieldPtr>::iterator PVFieldPtrArray_iterator;
72 typedef std::vector<PVFieldPtr>::const_iterator PVFieldPtrArray_const__iterator;
73 
77 typedef std::tr1::shared_ptr<PVScalar> PVScalarPtr;
78 
82 typedef std::tr1::shared_ptr<PVScalarArray> PVScalarArrayPtr;
83 
87 typedef std::tr1::shared_ptr<PVStructure> PVStructurePtr;
92 typedef std::vector<PVStructurePtr>::iterator PVStructurePtrArray_iterator;
93 typedef std::vector<PVStructurePtr>::const_iterator PVStructurePtrArray_const__iterator;
94 
100 typedef std::tr1::shared_ptr<PVStructureArray> PVStructureArrayPtr;
102 typedef std::tr1::shared_ptr<PVStructureArrayPtrArray> PVStructureArrayPtrArrayPtr;
103 
107 typedef std::tr1::shared_ptr<PVUnion> PVUnionPtr;
112 typedef std::vector<PVUnionPtr>::iterator PVUnionPtrArray_iterator;
113 typedef std::vector<PVUnionPtr>::const_iterator PVUnionPtrArray_const__iterator;
114 
120 typedef std::tr1::shared_ptr<PVUnionArray> PVUnionArrayPtr;
122 typedef std::tr1::shared_ptr<PVUnionArrayPtrArray> PVUnionArrayPtrArrayPtr;
123 
124 class PVDataCreate;
125 typedef std::tr1::shared_ptr<PVDataCreate> PVDataCreatePtr;
126 
131 class epicsShareClass PostHandler
132 {
133 public:
134  POINTER_DEFINITIONS(PostHandler);
138  virtual ~PostHandler(){}
142  virtual void postPut() = 0;
143 };
144 
152 class epicsShareClass PVField
153 : virtual public Serializable,
154  public std::tr1::enable_shared_from_this<PVField>
155 {
156 public:
157  POINTER_DEFINITIONS(PVField);
161  virtual ~PVField();
166  inline const std::string& getFieldName() const {return fieldName;}
172  std::string getFullName() const;
181  std::size_t getFieldOffset() const;
188  std::size_t getNextFieldOffset() const;
193  std::size_t getNumberFields() const;
198  inline bool isImmutable() const {return immutable;}
203  virtual void setImmutable();
208  inline const FieldConstPtr & getField() const {return field;}
213  inline PVStructure * getParent() {return parent;}
214  inline const PVStructure * getParent() const {return parent;}
218  void postPut() ;
224  void setPostHandler(PostHandlerPtr const &postHandler);
230  virtual bool equals(PVField &pv);
236  virtual std::ostream& dumpValue(std::ostream& o) const = 0;
237 
238  void copy(const PVField& from);
239  void copyUnchecked(const PVField& from);
240 
241  static size_t num_instances; // use atomic::get() or volatile* access
242  enum {isPVField=1};
243 protected:
244  PVField::shared_pointer getPtrSelf()
245  {
246  return shared_from_this();
247  }
248  explicit PVField(FieldConstPtr field);
249  void setParentAndName(PVStructure *parent, std::string const & fieldName);
250 private:
251  static void computeOffset(const PVField *pvField);
252  static void computeOffset(const PVField *pvField,std::size_t offset);
253  std::string fieldName;
254  PVStructure *parent;
255  const FieldConstPtr field;
256  size_t fieldOffset;
257  size_t nextFieldOffset;
258  bool immutable;
259  PostHandlerPtr postHandler;
260  friend class PVDataCreate;
261  friend class PVStructure;
262  EPICS_NOT_COPYABLE(PVField)
263 };
264 
265 epicsShareExtern std::ostream& operator<<(std::ostream& o, const PVField& f);
266 
272 class epicsShareClass PVScalar : public PVField {
273  // friend our child class(s) so that it
274  // can call protected methods of other
275  // PVScalar instances.
276  template<typename E> friend class PVScalarValue;
277 public:
278  POINTER_DEFINITIONS(PVScalar);
282  virtual ~PVScalar();
283  typedef PVScalar &reference;
284  typedef const PVScalar& const_reference;
289  const ScalarConstPtr getScalar() const ;
290 
301  template<typename T>
302  inline T getAs() const {
303  T result;
304  this->getAs((void*)&result, (ScalarType)ScalarTypeID<T>::value);
305  return result;
306  }
307 protected:
308  virtual void getAs(void *, ScalarType) const = 0;
309 public:
310 
311  virtual void getAs(AnyScalar& v) const =0;
312 
323  template<typename T>
324  inline void putFrom(T val) {
325  this->putFrom((const void*)&val, (ScalarType)ScalarTypeID<T>::value);
326  }
327 
329  virtual void putFrom(const void *, ScalarType) = 0;
330 
331  inline void putFrom(const AnyScalar& v) {
332  if(v)
333  putFrom(v.unsafe(), v.type());
334  }
335 
336  virtual void assign(const PVScalar&) = 0;
337 
338  virtual void copy(const PVScalar& from) = 0;
339  virtual void copyUnchecked(const PVScalar& from) = 0;
340 
341 protected:
342  explicit PVScalar(ScalarConstPtr const & scalar);
343  EPICS_NOT_COPYABLE(PVScalar)
344 };
345 
346 namespace detail {
347 template<typename T>
349  T value;
350  typedef T arg_type;
351  inline void store(T v) {
352  value = v;
353  }
354  ScalarStorageOps() :value(0) {}
355 };
356 template<>
357 struct ScalarStorageOps<std::string> {
358  std::string value;
359  size_t maxLength;
360  typedef const std::string& arg_type;
361  void store(const std::string& val) {
362  if (maxLength > 0 && val.length() > maxLength)
363  throw std::overflow_error("string too long");
364 
365  value = val;
366  }
367 
368  ScalarStorageOps(): value(), maxLength(0) {} // initialized in PVString::PVString
369 };
370 } // namespace detail
371 
377 template<typename T>
378 class epicsShareClass PVScalarValue : public PVScalar {
379  typedef detail::ScalarStorageOps<T> storage_t;
380 public:
381  POINTER_DEFINITIONS(PVScalarValue);
382  typedef T value_type;
383  typedef T* pointer;
384  typedef const T* const_pointer;
385 
386  static const ScalarType typeCode;
387 
391  virtual ~PVScalarValue();
396  typename storage_t::arg_type get() const { return storage.value; }
401  inline void put(typename storage_t::arg_type v) {
402  storage.store(v);
403  PVField::postPut();
404  }
405 
406  virtual std::ostream& dumpValue(std::ostream& o) const OVERRIDE;
407 
408  // get operator
409  // double value; doubleField >>= value;
410  // NOTE: virtual is needed for MS C++ compiler to get this operator exported
411  virtual void operator>>=(T& value) const;
412 
413  // put operator
414  // double value = 12.8; doubleField <<= value;
415  // NOTE: virtual is needed for MS C++ compiler to get this operator exported
416  virtual void operator<<=(typename storage_t::arg_type value);
417 
418  template<typename T1>
419  inline T1 getAs() const {
420  T1 result(castUnsafe<T1,T>(get()));
421  return result;
422  }
423 
424  template<typename T1>
425  inline void putFrom(typename detail::ScalarStorageOps<T1>::arg_type val) {
426  put(castUnsafe<T,T1>(val));
427  }
428 
429  inline void putFrom(const AnyScalar& v) {
430  // the template form of putFrom() hides the base class AnyScalar overload
431  PVScalar::putFrom(v);
432  }
433 
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;
437 
438  virtual void serialize(ByteBuffer *pbuffer,
439  SerializableControl *pflusher) const OVERRIDE;
440  virtual void deserialize(ByteBuffer *pbuffer,
441  DeserializableControl *pflusher) OVERRIDE FINAL;
442 
443 protected:
444  explicit PVScalarValue(ScalarConstPtr const & scalar)
445  : PVScalar(scalar), storage() {}
446  virtual void getAs(void * result, ScalarType rtype) const OVERRIDE FINAL
447  {
448  const T src = get();
449  castUnsafeV(1, rtype, result, typeCode, (const void*)&src);
450  }
451 public:
452  virtual void getAs(AnyScalar& v) const OVERRIDE FINAL
453  {
454  v = get();
455  }
456  virtual void putFrom(const void *src, ScalarType stype) OVERRIDE FINAL
457  {
458  T result;
459  castUnsafeV(1, typeCode, (void*)&result, stype, src);
460  put(result);
461  }
462 protected:
463 
464  friend class PVDataCreate;
465  storage_t storage;
466  EPICS_NOT_COPYABLE(PVScalarValue)
467 };
468 
472 template<> inline
474 {
475  return o << static_cast<int>(get());
476 }
477 
478 template<> inline
480 {
481  return o << static_cast<unsigned int>(get());
482 }
483 
484 template<> inline
486 {
487  return o << std::boolalpha << static_cast<bool>(get());
488 }
489 
490 /*
491  * typedefs for the various possible scalar types.
492  */
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;
515 
521 class epicsShareClass PVString : public PVScalarValue<std::string>, SerializableArray {
522 public:
526  virtual ~PVString() {}
527 
528  virtual std::ostream& dumpValue(std::ostream& o) const OVERRIDE FINAL;
529 
530  virtual void serialize(ByteBuffer *pbuffer,
531  SerializableControl *pflusher) const OVERRIDE FINAL;
532  virtual void serialize(ByteBuffer *pbuffer,
533  SerializableControl *pflusher, size_t offset, size_t count) const OVERRIDE FINAL;
534 protected:
535  explicit PVString(ScalarConstPtr const & scalar);
536 
537  friend class PVDataCreate;
538  EPICS_NOT_COPYABLE(PVString)
539 };
540 typedef std::tr1::shared_ptr<PVString> PVStringPtr;
541 
542 
551 class epicsShareClass PVArray : public PVField, public SerializableArray {
552 public:
553  POINTER_DEFINITIONS(PVArray);
557  virtual ~PVArray(){};
562  virtual ArrayConstPtr getArray() const = 0;
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;
598 
599  using PVField::dumpValue;
600  virtual std::ostream& dumpValue(std::ostream& o, std::size_t index) const = 0;
601 
602 protected:
603  explicit PVArray(FieldConstPtr const & field);
604  void checkLength(size_t length) const;
605 private:
606  bool capacityMutable;
607  friend class PVDataCreate;
608  EPICS_NOT_COPYABLE(PVArray)
609 };
610 
611 epicsShareExtern std::ostream& operator<<(format::array_at_internal const& manip, const PVArray& array);
612 
618 class epicsShareClass PVScalarArray : public PVArray {
619 public:
620  POINTER_DEFINITIONS(PVScalarArray);
624  virtual ~PVScalarArray();
625  typedef PVScalarArray &reference;
626  typedef const PVScalarArray& const_reference;
631  const ScalarArrayConstPtr getScalarArray() const ;
632 
633 protected:
634  virtual void _getAsVoid(shared_vector<const void>&) const = 0;
635  virtual void _putFromVoid(const shared_vector<const void>&) = 0;
636 public:
637 
645  template<typename T>
646  void
648  {
650  _getAsVoid(temp);
651  out = shared_vector_convert<const T>(temp);
652  }
653 
665  template<typename T>
666  inline void putFrom(const shared_vector<const T>& inp)
667  {
668  shared_vector<const void> temp(static_shared_vector_cast<const void>(inp));
669  _putFromVoid(temp);
670  }
671 
681  void assign(const PVScalarArray& pv) {
682  if (isImmutable())
683  throw std::invalid_argument("destination is immutable");
684  copyUnchecked(pv);
685  }
686 
687  void copy(const PVScalarArray& from) {
688  assign(from);
689  }
690 
691  void copyUnchecked(const PVScalarArray& from) {
692  if (this==&from)
693  return;
694  shared_vector<const void> temp;
695  from._getAsVoid(temp);
696  _putFromVoid(temp);
697  }
698 
699 protected:
700  explicit PVScalarArray(ScalarArrayConstPtr const & scalarArray);
701 private:
702  friend class PVDataCreate;
703  EPICS_NOT_COPYABLE(PVScalarArray)
704 };
705 
706 
712 class epicsShareClass PVStructure : public PVField, public BitSetSerializable
713 {
714 public:
715  POINTER_DEFINITIONS(PVStructure);
719  virtual ~PVStructure();
720  typedef PVStructure & reference;
721  typedef const PVStructure & const_reference;
726  virtual void setImmutable() OVERRIDE FINAL;
731  inline const StructureConstPtr &getStructure() const { return structurePtr; }
736  inline const PVFieldPtrArray & getPVFields() const { return pvFields; }
737 
743  template<typename A>
744  FORCE_INLINE std::tr1::shared_ptr<PVField> getSubField(A a)
745  {
746  return getSubFieldImpl(a, false);
747  }
748 
749  template<typename A>
750  FORCE_INLINE std::tr1::shared_ptr<const PVField> getSubField(A a) const
751  {
752  return getSubFieldImpl(a, false);
753  }
754 
765  template<typename PVD, typename A>
766  inline std::tr1::shared_ptr<PVD> getSubField(A a)
767  {
768  STATIC_ASSERT(PVD::isPVField); // only allow cast from PVField sub-class
769  return std::tr1::dynamic_pointer_cast<PVD>(getSubFieldImpl(a, false));
770  }
771 
772  template<typename PVD, typename A>
773  inline std::tr1::shared_ptr<const PVD> getSubField(A a) const
774  {
775  STATIC_ASSERT(PVD::isPVField); // only allow cast from PVField sub-class
776  return std::tr1::dynamic_pointer_cast<const PVD>(getSubFieldImpl(a, false));
777  }
778 
785  template<typename A>
786  FORCE_INLINE std::tr1::shared_ptr<PVField> getSubFieldT(A a)
787  {
788  return getSubFieldImpl(a, true);
789  }
790 
791  template<typename A>
792  FORCE_INLINE std::tr1::shared_ptr<const PVField> getSubFieldT(A a) const
793  {
794  return getSubFieldImpl(a, true);
795  }
796 
797 private:
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());
802  }
803 public:
804 
805  template<typename PVD, typename A>
806  inline std::tr1::shared_ptr<PVD> getSubFieldT(A a)
807  {
808  STATIC_ASSERT(PVD::isPVField); // only allow cast from PVField sub-class
809  std::tr1::shared_ptr<PVD> ret(std::tr1::dynamic_pointer_cast<PVD>(getSubFieldImpl(a, true)));
810  if(!ret)
811  throwBadFieldType(a);
812  return ret;
813  }
814 
815  template<typename PVD, typename A>
816  inline std::tr1::shared_ptr<const PVD> getSubFieldT(A a) const
817  {
818  STATIC_ASSERT(PVD::isPVField); // only allow cast from PVField sub-class
819  std::tr1::shared_ptr<const PVD> ret(std::tr1::dynamic_pointer_cast<const PVD>(getSubFieldImpl(a, true)));
820  if(!ret)
821  throwBadFieldType(a);
822  return ret;
823  }
824 
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);
866 
867  virtual std::ostream& dumpValue(std::ostream& o) const OVERRIDE FINAL;
868 
869  void copy(const PVStructure& from);
870 
871  void copyUnchecked(const PVStructure& from);
872  void copyUnchecked(const PVStructure& from, const BitSet& maskBitSet, bool inverse = false);
873 
874  struct Formatter {
875  enum mode_t {
876  Auto,
877  Plain,
878  ANSI,
879  };
880  enum format_t {
881  Raw,
882  NT,
883  JSON,
884  };
885  private:
886  const PVStructure& xtop;
887  const BitSet* xshow;
888  const BitSet* xhighlight;
889  mode_t xmode;
890  format_t xfmt;
891  public:
892  explicit Formatter(const PVStructure& top)
893  :xtop(top)
894  ,xshow(0)
895  ,xhighlight(0)
896  ,xmode(Auto)
897  ,xfmt(NT)
898  {}
899 
900  // those fields (and their parents) to be printed. non-NT mode.
901  FORCE_INLINE Formatter& show(const BitSet& set) { xshow = &set; return *this; }
902  // those fields (and not their parents) to be specially highlighted. non-NT mode.
903  FORCE_INLINE Formatter& highlight(const BitSet& set) { xhighlight = &set; return *this; }
904 
905  FORCE_INLINE Formatter& mode(mode_t m) { xmode = m; return *this; }
906 
907  FORCE_INLINE Formatter& format(format_t f) { xfmt = f; return *this; }
908 
909  friend epicsShareFunc std::ostream& operator<<(std::ostream& strm, const Formatter& format);
910  friend void printRaw(std::ostream& strm, const PVStructure::Formatter& format, const PVStructure& cur);
911  };
912 
913  FORCE_INLINE Formatter stream() const { return Formatter(*this); }
914 
915 private:
916 
917  inline PVFieldPtr getSubFieldImpl(const std::string& name, bool throws) const {
918  return getSubFieldImpl(name.c_str(), throws);
919  }
920  PVFieldPtr getSubFieldImpl(const char *name, bool throws) const;
921  PVFieldPtr getSubFieldImpl(std::size_t fieldOffset, bool throws) const;
922 
923  PVFieldPtrArray pvFields;
924  StructureConstPtr structurePtr;
925  std::string extendsStructureName;
926  friend class PVDataCreate;
927  EPICS_NOT_COPYABLE(PVStructure)
928 };
929 
930 epicsShareFunc
931 std::ostream& operator<<(std::ostream& strm, const PVStructure::Formatter& format);
932 
940 class epicsShareClass PVUnion : public PVField
941 {
942 public:
943  POINTER_DEFINITIONS(PVUnion);
947  virtual ~PVUnion();
948  typedef PVUnion & reference;
949  typedef const PVUnion & const_reference;
950 
956  static const int32 UNDEFINED_INDEX;
957 
962  inline const UnionConstPtr& getUnion() const { return unionPtr; }
963 
968  inline const PVFieldPtr& get() { return value; }
969  inline PVField::const_shared_pointer get() const { return value; }
970 
971  template<typename PVT>
972  inline std::tr1::shared_ptr<PVT> get() {
973  STATIC_ASSERT(PVT::isPVField); // only allow cast from PVField sub-class
974  return std::tr1::dynamic_pointer_cast<PVT>(get());
975  }
976 
977  template<typename PVT>
978  inline std::tr1::shared_ptr<const PVT> get() const {
979  STATIC_ASSERT(PVT::isPVField); // only allow cast from PVField sub-class
980  return std::tr1::dynamic_pointer_cast<const PVT>(get());
981  }
982 
989  PVFieldPtr select(int32 index);
990 
991  template<typename PVT>
992  inline std::tr1::shared_ptr<PVT> select(int32 index) {
993  STATIC_ASSERT(PVT::isPVField); // only allow cast from PVField sub-class
994  return std::tr1::dynamic_pointer_cast<PVT>(select(index));
995  }
996 
1003  PVFieldPtr select(std::string const & fieldName);
1004 
1005  template<typename PVT>
1006  inline std::tr1::shared_ptr<PVT> select(std::string const & fieldName) {
1007  return std::tr1::dynamic_pointer_cast<PVT>(select(fieldName));
1008  }
1009 
1014  inline int32 getSelectedIndex() const { return selector; }
1015 
1020  std::string getSelectedFieldName() const;
1021 
1028  inline void set(PVFieldPtr const & value) {
1029  set(selector, value);
1030  }
1040  void set(int32 index, PVFieldPtr const & value);
1041 
1051  void set(std::string const & fieldName, PVFieldPtr const & value);
1052 
1058  virtual void serialize(
1059  ByteBuffer *pbuffer,SerializableControl *pflusher) const OVERRIDE FINAL;
1065  virtual void deserialize(
1066  ByteBuffer *pbuffer,DeserializableControl *pflusher) OVERRIDE FINAL;
1071  explicit PVUnion(UnionConstPtr const & punion);
1072 
1073  virtual std::ostream& dumpValue(std::ostream& o) const OVERRIDE FINAL;
1074 
1075  void copy(const PVUnion& from);
1076  void copyUnchecked(const PVUnion& from);
1077 
1078 private:
1079  static PVDataCreatePtr pvDataCreate;
1080 
1081  friend class PVDataCreate;
1082  UnionConstPtr unionPtr; // same as PVField::getField()
1083 
1084  int32 selector;
1085  PVFieldPtr value;
1086  bool variant;
1087  EPICS_NOT_COPYABLE(PVUnion)
1088 };
1089 
1090 
1091 namespace detail {
1092  // adaptor to allow epics::pvData::shared_vector to hold a reference
1093  // to a shared_ptr<std::vector<> >
1094  template<typename T>
1096  typedef std::tr1::shared_ptr<std::vector<T> > shared_vector;
1097  shared_vector vec;
1098  shared_ptr_vector_deletor(const shared_vector& v)
1099  :vec(v) {}
1100  void operator()(T*){vec.reset();}
1101  };
1102 
1104  template<typename T, class Base>
1105  class PVVectorStorage : public Base
1106  {
1107  public:
1108  typedef T value_type;
1109  typedef T* pointer;
1110  typedef const T* const_pointer;
1111 
1112  //TODO: full namespace can be removed along with local typedef 'shared_vector'
1113  typedef ::epics::pvData::shared_vector<T> svector;
1114  typedef ::epics::pvData::shared_vector<const T> const_svector;
1115 
1116 
1117  protected:
1118  template<typename A>
1119  explicit PVVectorStorage(A a) : Base(a) {}
1120  public:
1121  virtual ~PVVectorStorage(){}
1122 
1123  // Primitive array manipulations
1124 
1126  virtual const_svector view() const = 0;
1127 
1138  virtual void swap(const_svector& other) = 0;
1139 
1143  virtual void replace(const const_svector& next) = 0;
1144 
1145  // Derived operations
1146 
1155  inline svector reuse()
1156  {
1157  const_svector result;
1158  this->swap(result);
1159  return thaw(result);
1160  }
1161 
1162  EPICS_NOT_COPYABLE(PVVectorStorage)
1163  };
1164 } // namespace detail
1165 
1174 template<typename T>
1175 class epicsShareClass PVValueArray : public detail::PVVectorStorage<T,PVScalarArray> {
1176  typedef detail::PVVectorStorage<T,PVScalarArray> base_t;
1177 public:
1178  POINTER_DEFINITIONS(PVValueArray);
1179  typedef T value_type;
1180  typedef T* pointer;
1181  typedef const T* const_pointer;
1182 
1183  //TODO: full namespace can be removed along with local typedef 'shared_vector'
1184  typedef ::epics::pvData::shared_vector<T> svector;
1185  typedef ::epics::pvData::shared_vector<const T> const_svector;
1186 
1187 
1188  static const ScalarType typeCode;
1189 
1193  virtual ~PVValueArray();
1194 
1198  virtual ArrayConstPtr getArray() const OVERRIDE FINAL;
1199 
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;
1202 
1203  virtual size_t getLength() const OVERRIDE FINAL {return value.size();}
1204  virtual size_t getCapacity() const OVERRIDE FINAL {return value.capacity();}
1205 
1206  virtual void setCapacity(size_t capacity) OVERRIDE FINAL;
1207  virtual void setLength(size_t length) OVERRIDE FINAL;
1208 
1209  virtual const_svector view() const OVERRIDE FINAL {return value;}
1210  virtual void swap(const_svector &other) OVERRIDE FINAL;
1211  virtual void replace(const const_svector& next) OVERRIDE FINAL;
1212 
1213  // from Serializable
1214  virtual void serialize(ByteBuffer *pbuffer,SerializableControl *pflusher) const OVERRIDE FINAL;
1215  virtual void deserialize(ByteBuffer *pbuffer,DeserializableControl *pflusher) OVERRIDE FINAL;
1216  virtual void serialize(ByteBuffer *pbuffer,
1217  SerializableControl *pflusher, size_t offset, size_t count) const OVERRIDE FINAL;
1218 
1219 protected:
1220  virtual void _getAsVoid(epics::pvData::shared_vector<const void>& out) const OVERRIDE FINAL;
1221  virtual void _putFromVoid(const epics::pvData::shared_vector<const void>& in) OVERRIDE FINAL;
1222 
1223  explicit PVValueArray(ScalarArrayConstPtr const & scalar);
1224  const_svector value;
1225  friend class PVDataCreate;
1226  EPICS_NOT_COPYABLE(PVValueArray)
1227 };
1228 
1229 
1235 template<>
1236 class epicsShareClass PVValueArray<PVStructurePtr> : public detail::PVVectorStorage<PVStructurePtr,PVArray>
1237 {
1239 public:
1240  POINTER_DEFINITIONS(PVStructureArray);
1241  typedef PVStructurePtr value_type;
1242  typedef PVStructurePtr* pointer;
1243  typedef const PVStructurePtr* const_pointer;
1244  typedef PVStructureArray &reference;
1245  typedef const PVStructureArray& const_reference;
1246 
1247  //TODO: full namespace can be removed along with local typedef 'shared_vector'
1248  typedef ::epics::pvData::shared_vector<PVStructurePtr> svector;
1249  typedef ::epics::pvData::shared_vector<const PVStructurePtr> const_svector;
1253  virtual ~PVValueArray() {}
1254 
1255  virtual ArrayConstPtr getArray() const OVERRIDE FINAL
1256  {
1258  }
1259 
1260  virtual size_t getLength() const OVERRIDE FINAL {return value.size();}
1261  virtual size_t getCapacity() const OVERRIDE FINAL {return value.capacity();}
1262 
1267  virtual void setCapacity(size_t capacity) OVERRIDE FINAL;
1272  virtual void setLength(std::size_t length) OVERRIDE FINAL;
1273 
1284  std::size_t append(std::size_t number);
1291  bool remove(std::size_t offset,std::size_t number);
1295  void compress();
1296 
1297  virtual const_svector view() const OVERRIDE FINAL { return value; }
1298  virtual void swap(const_svector &other) OVERRIDE FINAL;
1299  virtual void replace(const const_svector &other) OVERRIDE FINAL {
1300  checkLength(other.size());
1301  value = other;
1302  PVField::postPut();
1303  }
1304 
1305  virtual void serialize(ByteBuffer *pbuffer,
1306  SerializableControl *pflusher) const OVERRIDE FINAL;
1307  virtual void deserialize(ByteBuffer *buffer,
1308  DeserializableControl *pflusher) OVERRIDE FINAL;
1309  virtual void serialize(ByteBuffer *pbuffer,
1310  SerializableControl *pflusher, std::size_t offset, std::size_t count) const OVERRIDE FINAL;
1311 
1312  virtual std::ostream& dumpValue(std::ostream& o) const OVERRIDE FINAL;
1313  virtual std::ostream& dumpValue(std::ostream& o, std::size_t index) const OVERRIDE FINAL;
1314 
1315  void copy(const PVStructureArray& from);
1316  void copyUnchecked(const PVStructureArray& from);
1317 
1318 protected:
1319  PVValueArray(StructureArrayConstPtr const & structureArray);
1320 private:
1322  const_svector value;
1323  friend class PVDataCreate;
1324  EPICS_NOT_COPYABLE(PVValueArray)
1325 };
1326 
1327 
1328 
1334 template<>
1335 class epicsShareClass PVValueArray<PVUnionPtr> : public detail::PVVectorStorage<PVUnionPtr,PVArray>
1336 {
1338 public:
1339  POINTER_DEFINITIONS(PVUnionArray);
1340  typedef PVUnionPtr value_type;
1341  typedef PVUnionPtr* pointer;
1342  typedef const PVUnionPtr* const_pointer;
1343  typedef PVUnionArray &reference;
1344  typedef const PVUnionArray& const_reference;
1345 
1346  //TODO: full namespace can be removed along with local typedef 'shared_vector'
1347  typedef ::epics::pvData::shared_vector<PVUnionPtr> svector;
1348  typedef ::epics::pvData::shared_vector<const PVUnionPtr> const_svector;
1352  virtual ~PVValueArray() {}
1353 
1354  virtual ArrayConstPtr getArray() const OVERRIDE FINAL
1355  {
1357  }
1358 
1359  virtual size_t getLength() const OVERRIDE FINAL {return value.size();}
1360  virtual size_t getCapacity() const OVERRIDE FINAL {return value.capacity();}
1361 
1366  virtual void setCapacity(size_t capacity) OVERRIDE FINAL;
1371  virtual void setLength(std::size_t length) OVERRIDE FINAL;
1372 
1383  std::size_t append(std::size_t number);
1390  bool remove(std::size_t offset,std::size_t number);
1394  void compress();
1395 
1396  virtual const_svector view() const OVERRIDE { return value; }
1397  virtual void swap(const_svector &other) OVERRIDE;
1398  virtual void replace(const const_svector &other) OVERRIDE FINAL {
1399  checkLength(other.size());
1400  value = other;
1401  PVField::postPut();
1402  }
1403 
1404  virtual void serialize(ByteBuffer *pbuffer,
1405  SerializableControl *pflusher) const OVERRIDE FINAL;
1406  virtual void deserialize(ByteBuffer *buffer,
1407  DeserializableControl *pflusher) OVERRIDE FINAL;
1408  virtual void serialize(ByteBuffer *pbuffer,
1409  SerializableControl *pflusher, std::size_t offset, std::size_t count) const OVERRIDE FINAL;
1410 
1411  virtual std::ostream& dumpValue(std::ostream& o) const OVERRIDE FINAL;
1412  virtual std::ostream& dumpValue(std::ostream& o, std::size_t index) const OVERRIDE FINAL;
1413 
1414  void copy(const PVUnionArray& from);
1415  void copyUnchecked(const PVUnionArray& from);
1416 
1417 protected:
1418  explicit PVValueArray(UnionArrayConstPtr const & unionArray);
1419 private:
1421  const_svector value;
1422  friend class PVDataCreate;
1423  EPICS_NOT_COPYABLE(PVValueArray)
1424 };
1425 
1426 
1431 typedef std::tr1::shared_ptr<PVBooleanArray> PVBooleanArrayPtr;
1432 
1434 typedef std::tr1::shared_ptr<PVByteArray> PVByteArrayPtr;
1435 
1437 typedef std::tr1::shared_ptr<PVShortArray> PVShortArrayPtr;
1438 
1440 typedef std::tr1::shared_ptr<PVIntArray> PVIntArrayPtr;
1441 
1443 typedef std::tr1::shared_ptr<PVLongArray> PVLongArrayPtr;
1444 
1446 typedef std::tr1::shared_ptr<PVUByteArray> PVUByteArrayPtr;
1447 
1449 typedef std::tr1::shared_ptr<PVUShortArray> PVUShortArrayPtr;
1450 
1452 typedef std::tr1::shared_ptr<PVUIntArray> PVUIntArrayPtr;
1453 
1455 typedef std::tr1::shared_ptr<PVULongArray> PVULongArrayPtr;
1456 
1458 typedef std::tr1::shared_ptr<PVFloatArray> PVFloatArrayPtr;
1459 
1461 typedef std::tr1::shared_ptr<PVDoubleArray> PVDoubleArrayPtr;
1462 
1464 typedef std::tr1::shared_ptr<PVStringArray> PVStringArrayPtr;
1465 
1466 namespace detail {
1467 struct pvfield_factory;
1468 }
1469 
1474 class epicsShareClass PVDataCreate {
1475  friend struct detail::pvfield_factory;
1476 public:
1481  static const PVDataCreatePtr &getPVDataCreate();
1482 
1488  PVFieldPtr createPVField(FieldConstPtr const & field);
1495  PVFieldPtr createPVField(PVFieldPtr const & fieldToClone);
1501  PVScalarPtr createPVScalar(ScalarConstPtr const & scalar);
1507  PVScalarPtr createPVScalar(ScalarType scalarType);
1514  PVScalarPtr createPVScalar(PVScalarPtr const & scalarToClone);
1520  template<typename PVT>
1521  std::tr1::shared_ptr<PVT> createPVScalar()
1522  {
1523  return std::tr1::static_pointer_cast<PVT>(createPVScalar(PVT::typeCode));
1524  }
1525 
1531  PVStructurePtr createPVStructure(StructureConstPtr const & structure);
1538  PVStructurePtr createPVStructure(
1539  StringArray const & fieldNames,PVFieldPtrArray const & pvFields);
1545  PVStructurePtr createPVStructure(PVStructurePtr const & structToClone);
1546 
1552  PVUnionPtr createPVUnion(UnionConstPtr const & punion);
1558  PVUnionPtr createPVUnion(PVUnionPtr const & unionToClone);
1563  PVUnionPtr createPVVariantUnion();
1564 
1570  PVScalarArrayPtr createPVScalarArray(ScalarArrayConstPtr const & scalarArray);
1576  PVScalarArrayPtr createPVScalarArray(ScalarType elementType);
1583  PVScalarArrayPtr createPVScalarArray(PVScalarArrayPtr const & scalarArrayToClone);
1589  template<typename PVAT>
1590  std::tr1::shared_ptr<PVAT> createPVScalarArray()
1591  {
1592  return std::tr1::static_pointer_cast<PVAT>(createPVScalarArray(PVAT::typeCode));
1593  }
1594 
1601  PVStructureArrayPtr createPVStructureArray(StructureArrayConstPtr const & structureArray);
1608  PVStructureArrayPtr createPVStructureArray(StructureConstPtr const & structure)
1609  {
1610  return createPVStructureArray(fieldCreate->createStructureArray(structure));
1611  }
1612 
1619  PVUnionArrayPtr createPVUnionArray(UnionArrayConstPtr const & unionArray);
1626  PVUnionArrayPtr createPVUnionArray(UnionConstPtr const & punion)
1627  {
1628  return createPVUnionArray(fieldCreate->createUnionArray(punion));
1629  }
1634  PVUnionArrayPtr createPVVariantUnionArray();
1635 
1636 private:
1637  PVDataCreate();
1638  FieldCreatePtr fieldCreate;
1639  EPICS_NOT_COPYABLE(PVDataCreate)
1640 };
1641 
1648 FORCE_INLINE const PVDataCreatePtr& getPVDataCreate() {
1650 }
1651 
1652 bool epicsShareExtern operator==(const PVField&, const PVField&);
1653 
1654 static inline bool operator!=(const PVField& a, const PVField& b)
1655 {return !(a==b);}
1656 
1657 }}
1658 
1662 namespace std{
1663  epicsShareExtern std::ostream& operator<<(std::ostream& o, const epics::pvData::PVField *ptr);
1664 }
1665 
1666 #endif /* PVDATA_H */
PVStructure * getParent()
Definition: pvData.h:213
const std::string & getFieldName() const
Definition: pvData.h:166
PVUnionArrayPtr createPVUnionArray(UnionConstPtr const &punion)
Definition: pvData.h:1626
virtual size_t getLength() const OVERRIDE FINAL
Definition: pvData.h:1359
PVStructureArrayPtr createPVStructureArray(StructureConstPtr const &structure)
Definition: pvData.h:1608
Class that holds the data for each possible scalar type.
Definition: pvData.h:54
static const seekdir cur
virtual size_t getCapacity() const OVERRIDE FINAL
Definition: pvData.h:1360
std::tr1::shared_ptr< const StructureArray > StructureArrayConstPtr
Definition: pvIntrospect.h:158
virtual const_svector view() const OVERRIDE FINAL
Fetch a read-only view of the current array data.
Definition: pvData.h:1297
ScalarType type() const
Type code of contained value. Or (ScalarType)-1 is empty.
Definition: anyscalar.h:158
Data class for a structureArray.
Definition: pvData.h:1236
static const openmode in
virtual ArrayConstPtr getArray() const OVERRIDE FINAL
Definition: pvData.h:1354
std::tr1::shared_ptr< PVUnion > PVUnionPtr
Definition: pvData.h:107
PVArray is the base class for all array types.
Definition: pvData.h:551
bool isImmutable() const
Definition: pvData.h:198
virtual ~PVString()
Definition: pvData.h:526
Data interface for a structure,.
Definition: pvData.h:712
std::tr1::shared_ptr< PVScalar > PVScalarPtr
Definition: pvData.h:77
void put(typename storage_t::arg_type v)
Definition: pvData.h:401
std::tr1::shared_ptr< const Structure > StructureConstPtr
Definition: pvIntrospect.h:154
void putFrom(T val)
Definition: pvData.h:324
int32 getSelectedIndex() const
Definition: pvData.h:1014
virtual void replace(const const_svector &other) OVERRIDE FINAL
Definition: pvData.h:1398
const PVFieldPtrArray & getPVFields() const
Definition: pvData.h:736
UnionArrayConstPtr getUnionArray() const
Definition: pvData.h:1377
constexpr void replace(_ForwardIterator __first, _ForwardIterator __last, const _Tp &__old_value, const _Tp &__new_value)
This class implements introspection object for Array.
Definition: pvIntrospect.h:454
std::tr1::shared_ptr< PVT > createPVScalar()
Definition: pvData.h:1521
Callback class for serialization.
Definition: serialize.h:42
std::tr1::shared_ptr< PVAT > createPVScalarArray()
Definition: pvData.h:1590
std::tr1::shared_ptr< const UnionArray > UnionArrayConstPtr
Definition: pvIntrospect.h:166
PVString is special case, since it implements SerializableArray.
Definition: pvData.h:521
std::tr1::shared_ptr< const Field > FieldConstPtr
Definition: pvIntrospect.h:129
const FieldConstPtr & getField() const
Definition: pvData.h:208
static const openmode out
void getAs(shared_vector< const T > &out) const
Definition: pvData.h:647
Base class for a scalarArray.
Definition: pvData.h:618
This class implements a Bytebuffer that is like the java.nio.ByteBuffer.
Definition: byteBuffer.h:236
virtual ~PostHandler()
Definition: pvData.h:138
basic_string< char > string
std::tr1::shared_ptr< PVScalarArray > PVScalarArrayPtr
Definition: pvData.h:82
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
Definition: pvData.h:956
virtual ~PVArray()
Definition: pvData.h:557
std::tr1::shared_ptr< PVField > PVFieldPtr
Definition: pvData.h:66
bool operator==(const _CharT *__lhs, const basic_string< _CharT, _Traits, _Alloc > &__rhs)
PVScalar is the base class for each scalar field.
Definition: pvData.h:272
virtual ArrayConstPtr getArray() const OVERRIDE FINAL
Definition: pvData.h:1255
virtual size_t getLength() const OVERRIDE FINAL
Definition: pvData.h:1260
std::tr1::shared_ptr< const Union > UnionConstPtr
Definition: pvIntrospect.h:162
constexpr iterator_traits< _InputIterator >::difference_type count(_InputIterator __first, _InputIterator __last, const _Tp &__value)
Data class for a unionArray.
Definition: pvData.h:1335
shared_ptr< _Tp > static_pointer_cast(const shared_ptr< _Up > &__r) noexcept
const UnionConstPtr & getUnion() const
Definition: pvData.h:962
constexpr _OI copy(_II __first, _II __last, _OI __result)
This is a singleton class for creating data instances.
Definition: pvData.h:1474
This class is implemented by code that calls setPostHander.
Definition: pvData.h:131
const _CharT * c_str() const noexcept
template class for all extensions of PVArray.
Definition: pvData.h:55
const StructureConstPtr & getStructure() const
Definition: pvData.h:731
int32_t int32
Definition: pvType.h:83
void set(PVFieldPtr const &value)
Definition: pvData.h:1028
std::tr1::shared_ptr< PVField > getSubField(A a)
Definition: pvData.h:744
Callback class for deserialization.
Definition: serialize.h:93
virtual void replace(const const_svector &other) OVERRIDE FINAL
Definition: pvData.h:1299
PVField is the base class for each PVData field.
Definition: pvData.h:152
std::tr1::shared_ptr< PVStructure > PVStructurePtr
Definition: pvData.h:87
shared_ptr< _Tp > dynamic_pointer_cast(const shared_ptr< _Up > &__r) noexcept
void putFrom(const shared_vector< const T > &inp)
Definition: pvData.h:666
basic_ostream< char > ostream
virtual const_svector view() const OVERRIDE
Fetch a read-only view of the current array data.
Definition: pvData.h:1396
virtual size_t getCapacity() const OVERRIDE FINAL
Definition: pvData.h:1261
T getAs() const
Definition: pvData.h:302
std::tr1::shared_ptr< const ScalarArray > ScalarArrayConstPtr
Definition: pvIntrospect.h:150
Class for serializing arrays.
Definition: serialize.h:229
bool operator!=(const _CharT *__lhs, const basic_string< _CharT, _Traits, _Alloc > &__rhs)
std::tr1::shared_ptr< PVD > getSubField(A a)
Definition: pvData.h:766
size_type length() const noexcept
std::tr1::shared_ptr< const Scalar > ScalarConstPtr
Definition: pvIntrospect.h:142
valarray< _Tp > & operator<<=(const _Tp &)
Class for serializing bitSets.
Definition: serialize.h:200
std::tr1::shared_ptr< PVField > getSubFieldT(A a)
Definition: pvData.h:786
PVUnion has a single subfield.
Definition: pvData.h:940
Base class for serialization.
Definition: serialize.h:138
void assign(const PVScalarArray &pv)
Definition: pvData.h:681
StructureArrayConstPtr getStructureArray() const
Definition: pvData.h:1278
A vector of bits.
Definition: bitSet.h:56
__rvalue_stream_insertion_t< _Ostream, _Tp > operator<<(_Ostream &&__os, const _Tp &__x)
virtual size_t getCapacity() const OVERRIDE FINAL
Definition: pvData.h:1204
Common code for PV*Array.
Definition: pvData.h:1105
std::tr1::shared_ptr< const Array > ArrayConstPtr
Definition: pvIntrospect.h:146
FORCE_INLINE const PVDataCreatePtr & getPVDataCreate()
Definition: pvData.h:1648
std::tr1::shared_ptr< PostHandler > PostHandlerPtr
Definition: pvData.h:55
virtual void putFrom(const void *src, ScalarType stype)
Convert and assign.
Definition: pvData.h:456
virtual const_svector view() const OVERRIDE FINAL
Fetch a read-only view of the current array data.
Definition: pvData.h:1209
valarray< _Tp > & operator>>=(const _Tp &)