PVData C++  8.0.5
valueBuilder.h
1 /*
2  * Copyright information and license terms for this software can be
3  * found in the file LICENSE that is included with the distribution
4  */
5 #ifndef VALUEBUILDER_H
6 #define VALUEBUILDER_H
7 
8 #include <map>
9 
10 #include <pv/templateMeta.h>
11 #include <pv/pvIntrospect.h>
12 #include <pv/sharedVector.h>
13 
14 namespace epics{namespace pvData{
15 
16 class PVStructure;
17 
18 /** Incrementally define and initialize a PVStructure
19  *
20  * Equivalent to FieldBuilder with the added ability to assign initial values.
21  *
22  @code
23  epics::pvData::PVStructurePtr val(epics::pvData::ValueBuilder()
24  .add<pvInt>("intfld", 42)
25  .addNested("sub")
26  .add<pvString>("strfld", "testing")
27  .endNested()
28  .buildPVStructure());
29  @endcode
30  */
31 class epicsShareClass ValueBuilder
32 {
33 public:
34  //! empty structure
35  explicit ValueBuilder(const std::string& id=std::string());
36  //! Clone existing definition and value
37  explicit ValueBuilder(const PVStructure&);
38  ~ValueBuilder();
39 
40  //! Add a scalar field with a given name and initial value
41  template<ScalarType ENUM>
43  {
44  _add(name, ENUM, &V);
45  return *this;
46  }
47 
48  //! Add a scalar array field
49  template<class T>
51  {
52  _add(name, V);
53  return *this;
54  }
55 
57  _add(name, V);
58  return *this;
59  }
60 
61  //! Start a sub-structure
63  //! End a sub-structure
65 
66  /** Complete building structure
67  *
68  * @note ValueBuilder may be re-used after calling buildPVStructure()
69  */
71 
72 private:
73  void _add(const std::string& name, ScalarType stype, const void *V);
74  void _add(const std::string& name, const shared_vector<const void> &V);
75  void _add(const std::string& name, const PVStructure& V);
76 
78 
79  ValueBuilder * const parent;
80  struct child;
81  friend struct child;
82  struct child_struct;
83  friend struct child_struct;
84  struct child_scalar_base;
85  friend struct child_scalar_base;
86  template <typename T> struct child_scalar;
87  template <typename T> friend struct child_scalar;
88  struct child_scalar_array;
89  friend struct child_scalar_array;
90 
91  typedef std::map<std::string, child*> children_t;
93  std::string id;
94 
95  ValueBuilder(const ValueBuilder&);
97 };
98 
99 }}// namespace epics::pvData
100 
101 #endif // VALUEBUILDER_H
#define FORCE_INLINE
Definition: templateMeta.h:20
epicsShareFunc bool yajl_parse_helper(std::istream &src, yajl_handle handle)