PVData C++  8.0.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
pvIntrospect.h
1 /* pvIntrospect.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 PVINTROSPECT_H
10 #define PVINTROSPECT_H
11 
12 #include <string>
13 #include <stdexcept>
14 #include <iostream>
15 #include <map>
16 
17 #include <epicsAssert.h>
18 
19 #include <pv/lock.h>
20 #include <pv/noDefaultMethods.h>
21 #include <pv/pvType.h>
22 #include <pv/byteBuffer.h>
23 #include <pv/serialize.h>
24 #include <pv/pvdVersion.h>
25 
26 #include <shareLib.h>
27 #define PVD_DEPRECATED_52 PVD_DEPRECATED("See https://github.com/epics-base/pvDataCPP/issues/52")
28 
29 /* C++11 keywords
30  @code
31  struct Base {
32  virtual void foo();
33  };
34  struct Class : public Base {
35  virtual void foo() OVERRIDE FINAL;
36  };
37  @endcode
38  */
39 #ifndef FINAL
40 # if __cplusplus>=201103L
41 # define FINAL final
42 # else
43 # define FINAL
44 # endif
45 #endif
46 #ifndef OVERRIDE
47 # if __cplusplus>=201103L
48 # define OVERRIDE override
49 # else
50 # define OVERRIDE
51 # endif
52 #endif
53 
54 namespace epics { namespace pvData {
55 
56 namespace format {
57 
59 {
60  long level;
61 
62  indent_level(long l) : level(l) {}
63 };
64 
65 epicsShareExtern long& indent_value(std::ios_base& ios);
66 
67 epicsShareExtern std::ostream& operator<<(std::ostream& os, indent_level const& indent);
68 
70 {
71  long saved_level;
72  std::ios_base& stream;
73 
75  stream(ios)
76  {
77  long& l = indent_value(ios);
78  saved_level = l;
79  l = saved_level + 1;
80  }
81 
82  ~indent_scope()
83  {
84  indent_value(stream) = saved_level;
85  }
86 };
87 
88 struct indent
89 {
90 };
91 
92 epicsShareExtern std::ostream& operator<<(std::ostream& os, indent const&);
93 
94 struct array_at
95 {
96  std::size_t index;
97 
98  array_at(std::size_t ix) : index(ix) {}
99 };
100 
102 {
103  std::size_t index;
104  std::ostream& stream;
105 
106  array_at_internal(std::size_t ix, std::ostream& str) : index(ix), stream(str) {}
107 };
108 
109 epicsShareExtern array_at_internal operator<<(std::ostream& str, array_at const& manip);
110 
111 };
112 
113 class Field;
114 class Scalar;
115 class Array;
116 class ScalarArray;
117 class Structure;
118 class StructureArray;
119 class Union;
120 class UnionArray;
121 
122 class BoundedString;
123 
124 class PVField;
125 class PVScalar;
126 class PVScalarArray;
127 class PVStructure;
128 class PVUnion;
129 template<typename T> class PVValueArray;
130 
134 typedef std::tr1::shared_ptr<const Field> FieldConstPtr;
142 typedef std::tr1::shared_ptr<const Scalar> ScalarConstPtr;
146 typedef std::tr1::shared_ptr<const Array> ArrayConstPtr;
150 typedef std::tr1::shared_ptr<const ScalarArray> ScalarArrayConstPtr;
154 typedef std::tr1::shared_ptr<const Structure> StructureConstPtr;
158 typedef std::tr1::shared_ptr<const StructureArray> StructureArrayConstPtr;
162 typedef std::tr1::shared_ptr<const Union> UnionConstPtr;
166 typedef std::tr1::shared_ptr<const UnionArray> UnionArrayConstPtr;
170 typedef std::tr1::shared_ptr<const BoundedString> BoundedStringConstPtr;
171 
175 enum Type {
200 };
201 
206 namespace TypeFunc {
212  epicsShareExtern const char* name(Type type);
213 };
214 
215 epicsShareExtern std::ostream& operator<<(std::ostream& o, const Type& type);
216 
217 
270 };
271 
272 #define MAX_SCALAR_TYPE pvString
273 
278 namespace ScalarTypeFunc {
284  epicsShareExtern bool isInteger(ScalarType scalarType);
290  epicsShareExtern bool isUInteger(ScalarType scalarType);
296  epicsShareExtern bool isNumeric(ScalarType scalarType);
302  epicsShareExtern bool isPrimitive(ScalarType scalarType);
309  epicsShareExtern ScalarType getScalarType(std::string const &value);
315  epicsShareExtern const char* name(ScalarType scalarType);
316 
318  epicsShareExtern size_t elementSize(ScalarType id);
319 };
320 
321 epicsShareExtern std::ostream& operator<<(std::ostream& o, const ScalarType& scalarType);
322 
323 
328 class epicsShareClass Field :
329  virtual public Serializable,
330  public std::tr1::enable_shared_from_this<Field> {
331 public:
332  static size_t num_instances;
333 
334  POINTER_DEFINITIONS(Field);
335  virtual ~Field();
340  Type getType() const{return m_fieldType;}
345  virtual std::string getID() const = 0;
346 
352  virtual std::ostream& dump(std::ostream& o) const = 0;
353 
356  std::tr1::shared_ptr<PVField> build() const;
357 
358  enum {isField=1};
359 
360 protected:
365  Field(Type type);
366  void cacheCleanup();
367 private:
368  const Type m_fieldType;
369  unsigned int m_hash;
370  struct Helper;
371  friend struct Helper;
372 
373  friend class StructureArray;
374  friend class Structure;
375  friend class PVFieldPvt;
376  friend class StandardField;
377  friend class BasePVStructureArray;
378  friend class FieldCreate;
379  EPICS_NOT_COPYABLE(Field)
380 };
381 
382 epicsShareExtern std::ostream& operator<<(std::ostream& o, const Field& field);
383 
384 
389 class epicsShareClass Scalar : public Field{
390 public:
391  POINTER_DEFINITIONS(Scalar);
392  virtual ~Scalar();
393  typedef Scalar& reference;
394  typedef const Scalar& const_reference;
399  ScalarType getScalarType() const {return scalarType;}
400 
401  virtual std::string getID() const OVERRIDE;
402 
403  virtual std::ostream& dump(std::ostream& o) const OVERRIDE FINAL;
404 
405  virtual void serialize(ByteBuffer *buffer, SerializableControl *control) const OVERRIDE;
406  virtual void deserialize(ByteBuffer *buffer, DeserializableControl *control) OVERRIDE FINAL;
407 
410  std::tr1::shared_ptr<PVScalar> build() const;
411 
412 protected:
413  Scalar(ScalarType scalarType);
414 private:
415  static int8 getTypeCodeLUT(ScalarType scalarType);
416  ScalarType scalarType;
417  friend class FieldCreate;
418  friend class ScalarArray;
419  friend class BoundedScalarArray;
420  friend class FixedScalarArray;
421  friend class BoundedString;
422  EPICS_NOT_COPYABLE(Scalar)
423 };
424 
429 class epicsShareClass BoundedString : public Scalar{
430 public:
431  POINTER_DEFINITIONS(BoundedString);
432  virtual ~BoundedString();
433  typedef BoundedString& reference;
434  typedef const BoundedString& const_reference;
435 
436  virtual std::string getID() const OVERRIDE FINAL;
437 
438  virtual void serialize(ByteBuffer *buffer, SerializableControl *control) const OVERRIDE FINAL;
439 
440  std::size_t getMaximumLength() const;
441 
442 protected:
443  BoundedString(std::size_t maxStringLength);
444 private:
445  std::size_t maxLength;
446  friend class FieldCreate;
447  EPICS_NOT_COPYABLE(BoundedString)
448 };
449 
454 class epicsShareClass Array : public Field{
455 public:
456  POINTER_DEFINITIONS(Array);
457  virtual ~Array();
458  typedef Array& reference;
459  typedef const Array& const_reference;
460 
461  enum ArraySizeType { variable, fixed, bounded };
462 
467  virtual ArraySizeType getArraySizeType() const = 0;
468 
473  virtual std::size_t getMaximumCapacity() const = 0;
474 
475 protected:
480  Array(Type type);
481 
482  EPICS_NOT_COPYABLE(Array)
483 };
484 
489 class epicsShareClass ScalarArray : public Array{
490 public:
491  POINTER_DEFINITIONS(ScalarArray);
492  typedef ScalarArray& reference;
493  typedef const ScalarArray& const_reference;
494 
499  ScalarArray(ScalarType scalarType);
504  ScalarType getElementType() const {return elementType;}
505 
506  virtual ArraySizeType getArraySizeType() const OVERRIDE {return Array::variable;}
507 
508  virtual std::size_t getMaximumCapacity() const OVERRIDE {return 0;}
509 
510  virtual std::string getID() const OVERRIDE;
511 
512  virtual std::ostream& dump(std::ostream& o) const OVERRIDE FINAL;
513 
514  virtual void serialize(ByteBuffer *buffer, SerializableControl *control) const OVERRIDE;
515  virtual void deserialize(ByteBuffer *buffer, DeserializableControl *control) OVERRIDE FINAL;
516 
519  std::tr1::shared_ptr<PVScalarArray> build() const;
520 
521  virtual ~ScalarArray();
522 private:
523  const std::string getIDScalarArrayLUT() const;
524  ScalarType elementType;
525  friend class FieldCreate;
526  EPICS_NOT_COPYABLE(ScalarArray)
527 };
528 
529 
530 
535 class epicsShareClass BoundedScalarArray : public ScalarArray{
536 public:
537  POINTER_DEFINITIONS(BoundedScalarArray);
538  typedef BoundedScalarArray& reference;
539  typedef const BoundedScalarArray& const_reference;
540 
546  BoundedScalarArray(ScalarType scalarType, std::size_t size);
547 
548  virtual ArraySizeType getArraySizeType() const OVERRIDE FINAL {return Array::bounded;}
549 
550  virtual std::size_t getMaximumCapacity() const OVERRIDE FINAL {return size;}
551 
552  virtual std::string getID() const OVERRIDE FINAL;
553 
554  virtual void serialize(ByteBuffer *buffer, SerializableControl *control) const OVERRIDE FINAL;
555 
556  virtual ~BoundedScalarArray();
557 private:
558  std::size_t size;
559  friend class FieldCreate;
560  EPICS_NOT_COPYABLE(BoundedScalarArray)
561 };
562 
567 class epicsShareClass FixedScalarArray : public ScalarArray{
568 public:
569  POINTER_DEFINITIONS(FixedScalarArray);
570  typedef FixedScalarArray& reference;
571  typedef const FixedScalarArray& const_reference;
572 
578  FixedScalarArray(ScalarType scalarType, std::size_t size);
579 
580  virtual ArraySizeType getArraySizeType() const OVERRIDE FINAL {return Array::fixed;}
581 
582  virtual std::size_t getMaximumCapacity() const OVERRIDE FINAL {return size;}
583 
584  virtual std::string getID() const OVERRIDE FINAL;
585 
586  virtual void serialize(ByteBuffer *buffer, SerializableControl *control) const OVERRIDE FINAL;
587 
588  virtual ~FixedScalarArray();
589 private:
590  std::size_t size;
591  friend class FieldCreate;
592  EPICS_NOT_COPYABLE(FixedScalarArray)
593 };
594 
599 class epicsShareClass StructureArray : public Array{
600 public:
601  POINTER_DEFINITIONS(StructureArray);
602  typedef StructureArray& reference;
603  typedef const StructureArray& const_reference;
604 
609  const StructureConstPtr& getStructure() const {return pstructure;}
610 
611  virtual ArraySizeType getArraySizeType() const OVERRIDE FINAL {return Array::variable;}
612 
613  virtual std::size_t getMaximumCapacity() const OVERRIDE FINAL {return 0;}
614 
615  virtual std::string getID() const OVERRIDE FINAL;
616 
617  virtual std::ostream& dump(std::ostream& o) const OVERRIDE FINAL;
618 
619  virtual void serialize(ByteBuffer *buffer, SerializableControl *control) const OVERRIDE FINAL;
620  virtual void deserialize(ByteBuffer *buffer, DeserializableControl *control) OVERRIDE FINAL;
621 
624  std::tr1::shared_ptr<PVValueArray<std::tr1::shared_ptr<PVStructure> > > build() const;
625 
626 protected:
632 public:
633  virtual ~StructureArray();
634 private:
635  StructureConstPtr pstructure;
636  friend class FieldCreate;
637  EPICS_NOT_COPYABLE(StructureArray)
638 };
639 
644 class epicsShareClass UnionArray : public Array{
645 public:
646  POINTER_DEFINITIONS(UnionArray);
647  typedef UnionArray& reference;
648  typedef const UnionArray& const_reference;
649 
654  UnionConstPtr getUnion() const {return punion;}
655 
656  virtual ArraySizeType getArraySizeType() const OVERRIDE FINAL {return Array::variable;}
657 
658  virtual std::size_t getMaximumCapacity() const OVERRIDE FINAL {return 0;}
659 
660  virtual std::string getID() const OVERRIDE FINAL;
661 
662  virtual std::ostream& dump(std::ostream& o) const OVERRIDE FINAL;
663 
664  virtual void serialize(ByteBuffer *buffer, SerializableControl *control) const OVERRIDE FINAL;
665  virtual void deserialize(ByteBuffer *buffer, DeserializableControl *control) OVERRIDE FINAL;
666 
669  std::tr1::shared_ptr<PVValueArray<std::tr1::shared_ptr<PVUnion> > > build() const;
670 
671 protected:
676  UnionArray(UnionConstPtr const & _punion);
677 public:
678  virtual ~UnionArray();
679 private:
680  UnionConstPtr punion;
681  friend class FieldCreate;
682  EPICS_NOT_COPYABLE(UnionArray)
683 };
684 
689 class epicsShareClass Structure : public Field {
690 public:
691  POINTER_DEFINITIONS(Structure);
692 
696  static const std::string DEFAULT_ID;
697 
702  static const std::string & defaultId();
703 
704  virtual ~Structure();
705  typedef Structure& reference;
706  typedef const Structure& const_reference;
707 
712  std::size_t getNumberFields() const {return fieldNames.size();}
713 
719  FieldConstPtr getField(std::string const &fieldName) const;
720 
725  template<typename FT>
726  std::tr1::shared_ptr<const FT> getField(std::string const &fieldName) const
727  {
728  STATIC_ASSERT(FT::isField); // only allow cast from Field sub-class
729  return std::tr1::dynamic_pointer_cast<const FT>(getField(fieldName));
730  }
731 
738  FieldConstPtr getFieldT(std::string const &fieldName) const {return getFieldImpl(fieldName, true);};
739 
745  template<typename FT>
746  std::tr1::shared_ptr<const FT> getFieldT(std::string const &fieldName) const
747  {
748  STATIC_ASSERT(FT::isField); // only allow cast from Field sub-class
749  std::tr1::shared_ptr<const FT> result(
750  std::tr1::dynamic_pointer_cast<const FT>(getFieldT(fieldName))
751  );
752 
753  if (!result)
754  throw std::runtime_error("Wrong Field type");
755 
756  return result;
757  }
758 
764  const FieldConstPtr& getField(std::size_t index) const {return fields.at(index);}
765 
771  template<typename FT>
772  std::tr1::shared_ptr<const FT> getField(std::size_t index) const
773  {
774  STATIC_ASSERT(FT::isField); // only allow cast from Field sub-class
775  return std::tr1::dynamic_pointer_cast<const FT>(getField(index));
776  }
777 
783  FieldConstPtr getFieldT(std::size_t index) const {return fields.at(index);}
784 
791  template<typename FT>
792  std::tr1::shared_ptr<const FT> getFieldT(std::size_t index) const
793  {
794  STATIC_ASSERT(FT::isField); // only allow cast from Field sub-class
795  std::tr1::shared_ptr<const FT> result(
796  std::tr1::dynamic_pointer_cast<const FT>(getFieldT(index))
797  );
798 
799  if (!result)
800  throw std::runtime_error("Wrong Field type");
801 
802  return result;
803  }
804 
810  std::size_t getFieldIndex(std::string const &fieldName) const;
815  FieldConstPtrArray const & getFields() const {return fields;}
820  StringArray const & getFieldNames() const {return fieldNames;}
826  const std::string& getFieldName(std::size_t fieldIndex) const {return fieldNames.at(fieldIndex);}
827 
828  virtual std::string getID() const OVERRIDE FINAL;
829 
830  virtual std::ostream& dump(std::ostream& o) const OVERRIDE FINAL;
831 
832  virtual void serialize(ByteBuffer *buffer, SerializableControl *control) const OVERRIDE FINAL;
833  virtual void deserialize(ByteBuffer *buffer, DeserializableControl *control) OVERRIDE FINAL;
834 
837  std::tr1::shared_ptr<PVStructure> build() const;
838 
839 protected:
840  Structure(StringArray const & fieldNames, FieldConstPtrArray const & fields, std::string const & id = defaultId());
841 private:
842  StringArray fieldNames;
843  FieldConstPtrArray fields;
844  std::string id;
845 
846  FieldConstPtr getFieldImpl(const std::string& fieldName, bool throws) const;
847  void dumpFields(std::ostream& o) const;
848 
849  friend class FieldCreate;
850  friend class Union;
851  EPICS_NOT_COPYABLE(Structure)
852 };
853 
858 class epicsShareClass Union : public Field {
859 public:
860  POINTER_DEFINITIONS(Union);
861 
865  static const std::string DEFAULT_ID;
866 
871  static const std::string & defaultId();
872 
876  static const std::string ANY_ID;
877 
882  static const std::string & anyId();
883 
884  virtual ~Union();
885  typedef Union& reference;
886  typedef const Union& const_reference;
887 
892  std::size_t getNumberFields() const {return fieldNames.size();}
893 
899  FieldConstPtr getField(std::string const &fieldName) const;
900 
905  template<typename FT>
906  std::tr1::shared_ptr<const FT> getField(std::string const &fieldName) const
907  {
908  STATIC_ASSERT(FT::isField); // only allow cast from Field sub-class
909  return std::tr1::dynamic_pointer_cast<const FT>(getField(fieldName));
910  }
911 
918  FieldConstPtr getFieldT(std::string const &fieldName) const {return getFieldImpl(fieldName, true);};
919 
925  template<typename FT>
926  std::tr1::shared_ptr<const FT> getFieldT(std::string const &fieldName) const
927  {
928  STATIC_ASSERT(FT::isField); // only allow cast from Field sub-class
929  std::tr1::shared_ptr<const FT> result(
930  std::tr1::dynamic_pointer_cast<const FT>(getFieldT(fieldName))
931  );
932 
933  if (!result)
934  throw std::runtime_error("Wrong Field type");
935 
936  return result;
937  }
938 
944  FieldConstPtr getField(std::size_t index) const {return fields.at(index);}
945 
951  template<typename FT>
952  std::tr1::shared_ptr<const FT> getField(std::size_t index) const
953  {
954  STATIC_ASSERT(FT::isField); // only allow cast from Field sub-class
955  return std::tr1::dynamic_pointer_cast<const FT>(getField(index));
956  }
957 
963  FieldConstPtr getFieldT(std::size_t index) const {return fields.at(index);}
964 
971  template<typename FT>
972  std::tr1::shared_ptr<const FT> getFieldT(std::size_t index) const
973  {
974  STATIC_ASSERT(FT::isField); // only allow cast from Field sub-class
975  std::tr1::shared_ptr<const FT> result(
976  std::tr1::dynamic_pointer_cast<const FT>(getFieldT(index))
977  );
978 
979  if (!result)
980  throw std::runtime_error("Wrong Field type");
981 
982  return result;
983  }
984 
990  std::size_t getFieldIndex(std::string const &fieldName) const;
995  FieldConstPtrArray const & getFields() const {return fields;}
1000  StringArray const & getFieldNames() const {return fieldNames;}
1006  std::string getFieldName(std::size_t fieldIndex) const {return fieldNames.at(fieldIndex);}
1011  bool isVariant() const {return (fieldNames.size() == 0);}
1012 
1022  int32 guess(Type t, ScalarType s) const;
1023 
1024  virtual std::string getID() const OVERRIDE FINAL;
1025 
1026  virtual std::ostream& dump(std::ostream& o) const OVERRIDE FINAL;
1027 
1028  virtual void serialize(ByteBuffer *buffer, SerializableControl *control) const OVERRIDE FINAL;
1029  virtual void deserialize(ByteBuffer *buffer, DeserializableControl *control) OVERRIDE FINAL;
1030 
1033  std::tr1::shared_ptr<PVUnion> build() const;
1034 
1035 protected:
1036  Union();
1037  Union(StringArray const & fieldNames, FieldConstPtrArray const & fields, std::string const & id = defaultId());
1038 private:
1039  StringArray fieldNames;
1040  FieldConstPtrArray fields;
1041  std::string id;
1042 
1043  FieldConstPtr getFieldImpl(const std::string& fieldName, bool throws) const;
1044  void dumpFields(std::ostream& o) const;
1045 
1046  friend class FieldCreate;
1047  friend class Structure;
1048  EPICS_NOT_COPYABLE(Union)
1049 };
1050 
1051 class FieldCreate;
1052 typedef std::tr1::shared_ptr<FieldCreate> FieldCreatePtr;
1053 
1054 class FieldBuilder;
1055 typedef std::tr1::shared_ptr<FieldBuilder> FieldBuilderPtr;
1056 
1064 class epicsShareClass FieldBuilder :
1065  public std::tr1::enable_shared_from_this<FieldBuilder>
1066 {
1067 public:
1070  static FieldBuilderPtr begin();
1072  static FieldBuilderPtr begin(StructureConstPtr S);
1073 
1079  FieldBuilderPtr setId(std::string const & id);
1080 
1087  FieldBuilderPtr add(std::string const & name, ScalarType scalarType);
1088 
1095  FieldBuilderPtr addBoundedString(std::string const & name, std::size_t maxLength) PVD_DEPRECATED_52;
1096 
1103  FieldBuilderPtr add(std::string const & name, FieldConstPtr const & field);
1104 
1111  FieldBuilderPtr addArray(std::string const & name, ScalarType scalarType);
1112 
1120  FieldBuilderPtr addFixedArray(std::string const & name, ScalarType scalarType, std::size_t size) PVD_DEPRECATED_52;
1121 
1129  FieldBuilderPtr addBoundedArray(std::string const & name, ScalarType scalarType, std::size_t bound) PVD_DEPRECATED_52;
1130 
1137  FieldBuilderPtr addArray(std::string const & name, FieldConstPtr const & element);
1138 
1144  StructureConstPtr createStructure();
1145 
1151  UnionConstPtr createUnion();
1152 
1161  FieldBuilderPtr addNestedStructure(std::string const & name);
1162 
1171  FieldBuilderPtr addNestedUnion(std::string const & name);
1172 
1181  FieldBuilderPtr addNestedStructureArray(std::string const & name);
1182 
1191  FieldBuilderPtr addNestedUnionArray(std::string const & name);
1192 
1199  FieldBuilderPtr endNested();
1200 
1201 private:
1202  FieldBuilder();
1203  FieldBuilder(const Structure*);
1204  FieldBuilder(const FieldBuilderPtr & _parentBuilder, const std::string& name, const Structure*);
1205  FieldBuilder(const FieldBuilderPtr & _parentBuilder, const std::string& name, const StructureArray*);
1206  FieldBuilder(const FieldBuilderPtr & _parentBuilder, const std::string& name, const Union*);
1207  FieldBuilder(const FieldBuilderPtr & _parentBuilder, const std::string& name, const UnionArray*);
1208  FieldBuilder(FieldBuilderPtr const & parentBuilder,
1209  std::string const & nestedName,
1210  Type nestedClassToBuild, bool nestedArray);
1211 
1212  const Field *findField(const std::string& name, Type ftype);
1213 
1214  void reset();
1215  FieldConstPtr createFieldInternal(Type type);
1216 
1217  friend class FieldCreate;
1218 
1219  const FieldCreatePtr fieldCreate;
1220 
1221  std::string id;
1222  bool idSet;
1223 
1224  StringArray fieldNames;
1225  FieldConstPtrArray fields;
1226 
1227  const FieldBuilderPtr parentBuilder;
1228  const Type nestedClassToBuild;
1229  const std::string nestedName;
1230  const bool nestedArray;
1231  const bool createNested; // true - endNested() creates in parent, false - endNested() appends to parent
1232 };
1233 
1234 namespace detail {
1235 struct field_factory;
1236 }
1237 
1242 class epicsShareClass FieldCreate {
1243  friend struct detail::field_factory;
1244 public:
1245  static const FieldCreatePtr &getFieldCreate();
1250  FieldBuilderPtr createFieldBuilder() const;
1255  FieldBuilderPtr createFieldBuilder(StructureConstPtr S) const;
1262  ScalarConstPtr createScalar(ScalarType scalarType) const;
1269  BoundedStringConstPtr createBoundedString(std::size_t maxLength) const PVD_DEPRECATED_52;
1275  ScalarArrayConstPtr createScalarArray(ScalarType elementType) const;
1276  /*
1277  * Create an @c Array field, fixed size array.
1278  * @param elementType The @c ScalarType for array elements
1279  * @param size Fixed array size.
1280  * @return An @c Array Interface for the newly created object.
1281  */
1282  ScalarArrayConstPtr createFixedScalarArray(ScalarType elementType, std::size_t size) const PVD_DEPRECATED_52;
1289  ScalarArrayConstPtr createBoundedScalarArray(ScalarType elementType, std::size_t bound) const PVD_DEPRECATED_52;
1295  StructureArrayConstPtr createStructureArray(StructureConstPtr const & structure) const;
1300  StructureConstPtr createStructure () const;
1307  StructureConstPtr createStructure (
1308  StringArray const & fieldNames,
1309  FieldConstPtrArray const & fields) const;
1317  StructureConstPtr createStructure (
1318  std::string const & id,
1319  StringArray const & fieldNames,
1320  FieldConstPtrArray const & fields) const;
1326  UnionArrayConstPtr createUnionArray(UnionConstPtr const & punion) const;
1331  UnionArrayConstPtr createVariantUnionArray() const;
1336  UnionConstPtr createVariantUnion() const;
1343  UnionConstPtr createUnion (
1344  StringArray const & fieldNames,
1345  FieldConstPtrArray const & fields) const;
1353  UnionConstPtr createUnion (
1354  std::string const & id,
1355  StringArray const & fieldNames,
1356  FieldConstPtrArray const & fields) const;
1364  StructureConstPtr appendField(
1365  StructureConstPtr const & structure,
1366  std::string const & fieldName, FieldConstPtr const & field) const;
1374  StructureConstPtr appendFields(
1375  StructureConstPtr const & structure,
1376  StringArray const & fieldNames,
1377  FieldConstPtrArray const & fields) const;
1384  FieldConstPtr deserialize(ByteBuffer* buffer, DeserializableControl* control) const;
1385 
1386 private:
1387  FieldCreate();
1388 
1389  // const after ctor
1391  std::vector<ScalarArrayConstPtr> scalarArrays;
1392  UnionConstPtr variantUnion;
1393  UnionArrayConstPtr variantUnionArray;
1394 
1395  mutable Mutex mutex;
1397  mutable cache_t cache;
1398 
1399  struct Helper;
1400  friend class Field;
1401  EPICS_NOT_COPYABLE(FieldCreate)
1402 };
1403 
1408 FORCE_INLINE const FieldCreatePtr& getFieldCreate() {
1409  return FieldCreate::getFieldCreate();
1410 }
1411 
1422 template<typename T>
1423 struct ScalarTypeID {};
1424 
1431 template<ScalarType ID>
1433 
1434 #define OP(ENUM, TYPE) \
1435 template<> struct ScalarTypeTraits<ENUM> {typedef TYPE type;}; \
1436 template<> struct ScalarTypeID<TYPE> { enum {value=ENUM}; }; \
1437 template<> struct ScalarTypeID<const TYPE> { enum {value=ENUM}; };
1438 
1439 OP(pvBoolean, boolean)
1448 OP(pvFloat, float)
1449 OP(pvDouble, double)
1450 OP(pvString, std::string)
1451 #undef OP
1452 
1453 bool epicsShareExtern compare(const Field&, const Field&);
1454 bool epicsShareExtern compare(const Scalar&, const Scalar&);
1455 bool epicsShareExtern compare(const ScalarArray&, const ScalarArray&);
1456 bool epicsShareExtern compare(const Structure&, const Structure&);
1457 bool epicsShareExtern compare(const StructureArray&, const StructureArray&);
1458 bool epicsShareExtern compare(const Union&, const Union&);
1459 bool epicsShareExtern compare(const UnionArray&, const UnionArray&);
1460 bool epicsShareExtern compare(const BoundedString&, const BoundedString&);
1461 
1468 #define MAKE_COMPARE(CLASS) \
1469 static FORCE_INLINE bool operator==(const CLASS& a, const CLASS& b) {return (void*)&a==(void*)&b;} \
1470 static FORCE_INLINE bool operator!=(const CLASS& a, const CLASS& b) {return !(a==b);}
1471 
1472 MAKE_COMPARE(Field)
1473 MAKE_COMPARE(Scalar)
1474 MAKE_COMPARE(ScalarArray)
1475 MAKE_COMPARE(Structure)
1476 MAKE_COMPARE(StructureArray)
1477 MAKE_COMPARE(Union)
1478 MAKE_COMPARE(UnionArray)
1479 MAKE_COMPARE(BoundedString)
1480 
1481 #undef MAKE_COMPARE
1482 }}
1483 
1487 namespace std{
1488  epicsShareExtern std::ostream& operator<<(std::ostream& o, const epics::pvData::Field *ptr);
1489 }
1490 
1491 #endif /* PVINTROSPECT_H */
const FieldConstPtr & getField(std::size_t index) const
Definition: pvIntrospect.h:764
basic_ostream< _CharT, _Traits > & operator<<(basic_ostream< _CharT, _Traits > &__os, const basic_string< _CharT, _Traits, _Alloc > &__str)
std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const std::bernoulli_distribution &__x)
UnionConstPtr getUnion() const
Definition: pvIntrospect.h:654
std::tr1::shared_ptr< const FT > getField(std::size_t index) const
Definition: pvIntrospect.h:952
Type getType() const
Definition: pvIntrospect.h:340
std::string getFieldName(std::size_t fieldIndex) const
bool isUInteger(ScalarType scalarType)
virtual ArraySizeType getArraySizeType() const
Definition: pvIntrospect.h:656
const char * name(ScalarType scalarType)
std::tr1::shared_ptr< const StructureArray > StructureArrayConstPtr
Definition: pvIntrospect.h:158
valarray< size_t > size() const
FieldConstPtr getFieldT(std::size_t index) const
Definition: pvIntrospect.h:963
std::tr1::shared_ptr< const FT > getField(std::string const &fieldName) const
Definition: pvIntrospect.h:726
virtual ArraySizeType getArraySizeType() const
Definition: pvIntrospect.h:580
uint32_t uint32
Definition: pvType.h:99
ScalarType getScalarType(std::string const &value)
Data interface for a structure,.
Definition: pvData.h:712
static const std::string DEFAULT_ID
Definition: pvIntrospect.h:865
std::tr1::shared_ptr< const Structure > StructureConstPtr
Definition: pvIntrospect.h:154
bool isPrimitive(ScalarType scalarType)
std::size_t getNumberFields() const
Definition: pvIntrospect.h:892
constexpr reference at(size_type __n)
uint8_t uint8
Definition: pvType.h:91
directory_iterator begin(directory_iterator __iter) noexcept
int16_t int16
Definition: pvType.h:79
std::tr1::shared_ptr< const FT > getField(std::size_t index) const
Definition: pvIntrospect.h:772
const std::string & getFieldName(std::size_t fieldIndex) const
Definition: pvIntrospect.h:826
This class implements introspection object for Array.
Definition: pvIntrospect.h:454
This class implements introspection object for a structureArray.
Definition: pvIntrospect.h:599
StringArray const & getFieldNames() const
Callback class for serialization.
Definition: serialize.h:42
This class implements introspection object for field.
Definition: pvIntrospect.h:328
std::tr1::shared_ptr< const UnionArray > UnionArrayConstPtr
Definition: pvIntrospect.h:166
This class implements introspection object for bounded scalar array.
Definition: pvIntrospect.h:567
std::tr1::shared_ptr< const Field > FieldConstPtr
Definition: pvIntrospect.h:129
This class implements introspection object for a union.
Definition: pvIntrospect.h:858
virtual ArraySizeType getArraySizeType() const
Definition: pvIntrospect.h:548
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
const StructureConstPtr & getStructure() const
Definition: pvIntrospect.h:609
basic_ios< char > ios
This is a singleton class for creating introspection interfaces.
virtual std::size_t getMaximumCapacity() const
Definition: pvIntrospect.h:508
ScalarType getScalarType() const
Definition: pvIntrospect.h:399
StringArray const & getFieldNames() const
Definition: pvIntrospect.h:820
reference at(size_type __n)
This class implements introspection object for Scalar.
Definition: pvIntrospect.h:389
std::size_t getNumberFields() const
Definition: pvIntrospect.h:712
PVScalar is the base class for each scalar field.
Definition: pvData.h:272
FieldConstPtr getField(std::size_t index) const
Definition: pvIntrospect.h:944
virtual std::size_t getMaximumCapacity() const
Definition: pvIntrospect.h:658
ios_base & fixed(ios_base &__base)
std::tr1::shared_ptr< const Union > UnionConstPtr
Definition: pvIntrospect.h:162
This class implements introspection object for a unionArray.
Definition: pvIntrospect.h:644
virtual ArraySizeType getArraySizeType() const
Definition: pvIntrospect.h:611
virtual std::size_t getMaximumCapacity() const
Definition: pvIntrospect.h:582
int64_t int64
Definition: pvType.h:87
std::tr1::shared_ptr< const FT > getField(std::string const &fieldName) const
Definition: pvIntrospect.h:906
This class implements introspection object for scalar array.
Definition: pvIntrospect.h:489
template class for all extensions of PVArray.
Definition: pvData.h:55
int32_t int32
Definition: pvType.h:83
FieldConstPtr getFieldT(std::string const &fieldName) const
Definition: pvIntrospect.h:918
const char * name(Type type)
bool isVariant() const
virtual std::size_t getMaximumCapacity() const
Definition: pvIntrospect.h:613
Callback class for deserialization.
Definition: serialize.h:93
This class implements introspection object for BoundedString.
Definition: pvIntrospect.h:429
std::tr1::shared_ptr< const FT > getFieldT(std::string const &fieldName) const
Definition: pvIntrospect.h:746
PVField is the base class for each PVData field.
Definition: pvData.h:152
ScalarType getElementType() const
Definition: pvIntrospect.h:504
std::tr1::shared_ptr< const FT > getFieldT(std::string const &fieldName) const
Definition: pvIntrospect.h:926
std::vector< FieldConstPtr > FieldConstPtrArray
Definition: pvIntrospect.h:138
shared_ptr< _Tp > dynamic_pointer_cast(const shared_ptr< _Up > &__r) noexcept
basic_ostream< char > ostream
uint16_t uint16
Definition: pvType.h:95
virtual ArraySizeType getArraySizeType() const
Definition: pvIntrospect.h:506
std::tr1::shared_ptr< const ScalarArray > ScalarArrayConstPtr
Definition: pvIntrospect.h:150
const FieldCreatePtr & getFieldCreate()
virtual std::size_t getMaximumCapacity() const
Definition: pvIntrospect.h:550
int8_t int8
Definition: pvType.h:75
static const std::string ANY_ID
Definition: pvIntrospect.h:876
bool isNumeric(ScalarType scalarType)
FieldConstPtrArray const & getFields() const
Definition: pvIntrospect.h:995
size_t elementSize(ScalarType id)
gives sizeof(T) where T depends on the scalar type id.
std::tr1::shared_ptr< const Scalar > ScalarConstPtr
Definition: pvIntrospect.h:142
Interface for in-line creating of introspection interfaces.
std::tr1::shared_ptr< const FT > getFieldT(std::size_t index) const
Definition: pvIntrospect.h:792
PVUnion has a single subfield.
Definition: pvData.h:940
Base class for serialization.
Definition: serialize.h:138
FieldConstPtr getFieldT(std::size_t index) const
Definition: pvIntrospect.h:783
std::tr1::shared_ptr< const FT > getFieldT(std::size_t index) const
Definition: pvIntrospect.h:972
This class implements introspection object for bounded scalar array.
Definition: pvIntrospect.h:535
This class implements introspection object for a structure.
Definition: pvIntrospect.h:689
static const std::string DEFAULT_ID
Definition: pvIntrospect.h:696
uint64_t uint64
Definition: pvType.h:103
bool isInteger(ScalarType scalarType)
std::tr1::shared_ptr< const Array > ArrayConstPtr
Definition: pvIntrospect.h:146
FieldConstPtr getFieldT(std::string const &fieldName) const
Definition: pvIntrospect.h:738
std::tr1::shared_ptr< const BoundedString > BoundedStringConstPtr
Definition: pvIntrospect.h:170
FieldConstPtrArray const & getFields() const
Definition: pvIntrospect.h:815