This is Unofficial EPICS BASE Doxygen Site
epics::pvData::ValueBuilder Class Reference

#include "valueBuilder.h"

Classes

struct  child
 
struct  child_scalar
 
struct  child_scalar_array
 
struct  child_scalar_base
 
struct  child_struct
 

Public Member Functions

 ValueBuilder (const std::string &id=std::string())
 empty structure More...
 
 ValueBuilder (const PVStructure &)
 Clone existing definition and value. More...
 
 ~ValueBuilder ()
 
template<ScalarType ENUM>
FORCE_INLINE ValueBuilderadd (const std::string &name, typename meta::arg_type< typename ScalarTypeTraits< ENUM >::type >::type V)
 Add a scalar field with a given name and initial value. More...
 
template<class T >
FORCE_INLINE ValueBuilderadd (const std::string &name, const shared_vector< const T > &V)
 Add a scalar array field. More...
 
FORCE_INLINE ValueBuilderadd (const std::string &name, const PVStructure &V)
 
ValueBuilderaddNested (const std::string &name, Type type=structure, const std::string &id=std::string())
 Start a sub-structure. More...
 
ValueBuilderendNested ()
 End a sub-structure. More...
 
std::tr1::shared_ptr< PVStructurebuildPVStructure () const
 

Friends

struct child
 
struct child_struct
 
struct child_scalar_base
 
template<typename T >
struct child_scalar
 
struct child_scalar_array
 

Detailed Description

Incrementally define and initialize a PVStructure

Equivalent to FieldBuilder with the added ability to assign initial values.

.add<pvInt>("intfld", 42)
.addNested("sub")
.add<pvString>("strfld", "testing")

Definition at line 31 of file valueBuilder.h.

Constructor & Destructor Documentation

epics::pvData::ValueBuilder::ValueBuilder ( const std::string &  id = std::string())
explicit

empty structure

Definition at line 104 of file valueBuilder.cpp.

104 :parent(0),id(id) {}
epics::pvData::ValueBuilder::ValueBuilder ( const PVStructure clone)
explicit

Clone existing definition and value.

Definition at line 147 of file valueBuilder.cpp.

147  :parent(0)
148 {
149  StructureConstPtr ctype(clone.getStructure());
150  id = ctype->getID();
151  child_struct::fillStruct(*this, clone);
152 }
std::tr1::shared_ptr< const Structure > StructureConstPtr
Definition: pvIntrospect.h:162
static void fillStruct(ValueBuilder &self, const PVStructure &val)
epics::pvData::ValueBuilder::~ValueBuilder ( )

Definition at line 160 of file valueBuilder.cpp.

161 {
162  for(children_t::const_iterator it=children.begin(), end=children.end(); it!=end; ++it)
163  delete it->second;
164  children.clear();
165 }

Member Function Documentation

template<ScalarType ENUM>
FORCE_INLINE ValueBuilder& epics::pvData::ValueBuilder::add ( const std::string &  name,
typename meta::arg_type< typename ScalarTypeTraits< ENUM >::type >::type  V 
)
inline

Add a scalar field with a given name and initial value.

Definition at line 42 of file valueBuilder.h.

43  {
44  _add(name, ENUM, &V);
45  return *this;
46  }
template<class T >
FORCE_INLINE ValueBuilder& epics::pvData::ValueBuilder::add ( const std::string &  name,
const shared_vector< const T > &  V 
)
inline

Add a scalar array field.

Definition at line 50 of file valueBuilder.h.

51  {
52  _add(name, V);
53  return *this;
54  }
FORCE_INLINE ValueBuilder& epics::pvData::ValueBuilder::add ( const std::string &  name,
const PVStructure V 
)
inline

Definition at line 56 of file valueBuilder.h.

56  {
57  _add(name, V);
58  return *this;
59  }
ValueBuilder & epics::pvData::ValueBuilder::addNested ( const std::string &  name,
Type  type = structure,
const std::string &  id = std::string() 
)

Start a sub-structure.

Definition at line 225 of file valueBuilder.cpp.

226 {
227  if(type!=structure)
228  THROW_EXCEPTION2(std::invalid_argument, "addNested() only supports structure");
229  child_struct *sub;
230  children_t::const_iterator it(children.find(name));
231  if(it==children.end()) {
232  epics::auto_ptr<child_struct> store(new child_struct(this, id));
233  sub = store.get();
234  children[name] = store.get();
235  store.release();
236  } else if(it->second->type==structure) {
237  sub = static_cast<child_struct*>(it->second);
238  } else {
239  std::ostringstream msg;
240  msg<<"Can't replace non-struct field '"<<name<<"' with struct";
241  THROW_EXCEPTION2(std::invalid_argument, msg.str());
242  }
243  sub->builder.id = id;
244  return sub->builder;
245 }
#define THROW_EXCEPTION2(TYPE, MSG)
pvd::StructureConstPtr type
PVStructure::shared_pointer epics::pvData::ValueBuilder::buildPVStructure ( ) const

Complete building structure

Note
ValueBuilder may be re-used after calling buildPVStructure()

Definition at line 274 of file valueBuilder.cpp.

275 {
276  if(parent)
277  THROW_EXCEPTION2(std::logic_error, "Only top level structure may be built. Missing endNested() ?");
278 
280  {
281  FieldBuilderPtr tbuild(getFieldCreate()->createFieldBuilder());
282 
283  child_struct::buildStruct(*this, tbuild);
284 
285  type = tbuild->createStructure();
286  }
287 
288  PVStructure::shared_pointer root(type->build());
289 
290  child_struct::storeStruct(*this, root);
291 
292  return root;
293 }
#define THROW_EXCEPTION2(TYPE, MSG)
pvd::StructureConstPtr type
std::tr1::shared_ptr< const Structure > StructureConstPtr
Definition: pvIntrospect.h:162
std::tr1::shared_ptr< FieldBuilder > FieldBuilderPtr
static void buildStruct(const ValueBuilder &self, FieldBuilderPtr &builder)
FORCE_INLINE const FieldCreatePtr & getFieldCreate()
static void storeStruct(const ValueBuilder &self, const PVStructurePtr &val)
ValueBuilder & epics::pvData::ValueBuilder::endNested ( )

End a sub-structure.

Definition at line 247 of file valueBuilder.cpp.

248 {
249  if(!parent) {
250  THROW_EXCEPTION2(std::logic_error, "Can't end top of structure");
251  }
252  return *parent;
253 }
#define THROW_EXCEPTION2(TYPE, MSG)

Friends And Related Function Documentation

friend struct child
friend

Definition at line 80 of file valueBuilder.h.

template<typename T >
friend struct child_scalar
friend

Definition at line 86 of file valueBuilder.h.

friend struct child_scalar_array
friend

Definition at line 88 of file valueBuilder.h.

friend struct child_scalar_base
friend

Definition at line 84 of file valueBuilder.h.

friend struct child_struct
friend

Definition at line 82 of file valueBuilder.h.


The documentation for this class was generated from the following files: