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

Data interface for a structure,. More...

#include "pvData.h"

+ Inheritance diagram for epics::pvData::PVStructure:
+ Collaboration diagram for epics::pvData::PVStructure:

Classes

struct  Formatter
 

Public Types

typedef PVStructurereference
 
typedef const PVStructureconst_reference
 
- Public Types inherited from epics::pvData::PVField
enum  { isPVField =1 }
 

Public Member Functions

 POINTER_DEFINITIONS (PVStructure)
 
virtual ~PVStructure ()
 
virtual void setImmutable () OVERRIDE FINAL
 
const StructureConstPtrgetStructure () const
 
const PVFieldPtrArraygetPVFields () const
 
template<typename A >
FORCE_INLINE std::tr1::shared_ptr< PVFieldgetSubField (A a)
 
template<typename A >
FORCE_INLINE std::tr1::shared_ptr< const PVFieldgetSubField (A a) const
 
template<typename PVD , typename A >
std::tr1::shared_ptr< PVD > getSubField (A a)
 
template<typename PVD , typename A >
std::tr1::shared_ptr< const PVD > getSubField (A a) const
 
template<typename A >
FORCE_INLINE std::tr1::shared_ptr< PVFieldgetSubFieldT (A a)
 
template<typename A >
FORCE_INLINE std::tr1::shared_ptr< const PVFieldgetSubFieldT (A a) const
 
template<typename PVD , typename A >
std::tr1::shared_ptr< PVD > getSubFieldT (A a)
 
template<typename PVD , typename A >
std::tr1::shared_ptr< const PVD > getSubFieldT (A a) const
 
virtual void serialize (ByteBuffer *pbuffer, SerializableControl *pflusher) const OVERRIDE FINAL
 
virtual void deserialize (ByteBuffer *pbuffer, DeserializableControl *pflusher) OVERRIDE FINAL
 
virtual void serialize (ByteBuffer *pbuffer, SerializableControl *pflusher, BitSet *pbitSet) const OVERRIDE FINAL
 
virtual void deserialize (ByteBuffer *pbuffer, DeserializableControl *pflusher, BitSet *pbitSet) OVERRIDE FINAL
 
 PVStructure (StructureConstPtr const &structure)
 
 PVStructure (StructureConstPtr const &structure, PVFieldPtrArray const &pvFields)
 
virtual std::ostream & dumpValue (std::ostream &o) const OVERRIDE FINAL
 
void copy (const PVStructure &from)
 
void copyUnchecked (const PVStructure &from)
 
void copyUnchecked (const PVStructure &from, const BitSet &maskBitSet, bool inverse=false)
 
FORCE_INLINE Formatter stream () const
 
- Public Member Functions inherited from epics::pvData::PVField
 POINTER_DEFINITIONS (PVField)
 
virtual ~PVField ()
 
const std::string & getFieldName () const
 
std::string getFullName () const
 
std::size_t getFieldOffset () const
 
std::size_t getNextFieldOffset () const
 
std::size_t getNumberFields () const
 
bool isImmutable () const
 
const FieldConstPtrgetField () const
 
PVStructuregetParent ()
 
const PVStructuregetParent () const
 
void postPut ()
 
void setPostHandler (PostHandlerPtr const &postHandler)
 
virtual bool equals (PVField &pv)
 
void copy (const PVField &from)
 
void copyUnchecked (const PVField &from)
 
- Public Member Functions inherited from epics::pvData::Serializable
virtual ~Serializable ()
 
- Public Member Functions inherited from epics::pvData::BitSetSerializable
virtual ~BitSetSerializable ()
 

Friends

class PVDataCreate
 

Additional Inherited Members

- Static Public Attributes inherited from epics::pvData::PVField
static size_t num_instances
 
- Protected Member Functions inherited from epics::pvData::PVField
PVField::shared_pointer getPtrSelf ()
 
 PVField (FieldConstPtr field)
 
void setParentAndName (PVStructure *parent, std::string const &fieldName)
 

Detailed Description

Data interface for a structure,.

Definition at line 712 of file pvData.h.

Member Typedef Documentation

Definition at line 721 of file pvData.h.

Definition at line 720 of file pvData.h.

Constructor & Destructor Documentation

epics::pvData::PVStructure::~PVStructure ( )
virtual

Destructor

Definition at line 63 of file PVStructure.cpp.

63 {}
epics::pvData::PVStructure::PVStructure ( StructureConstPtr const &  structure)
explicit

Constructor

Parameters
structureThe introspection interface.

Definition at line 27 of file PVStructure.cpp.

28 : PVField(structurePtr),
29  structurePtr(structurePtr),
30  extendsStructureName("")
31 {
32  size_t numberFields = structurePtr->getNumberFields();
33  FieldConstPtrArray const & fields = structurePtr->getFields();
34  StringArray const & fieldNames = structurePtr->getFieldNames();
35  pvFields.reserve(numberFields);
36  PVDataCreatePtr pvDataCreate = getPVDataCreate();
37  for(size_t i=0; i<numberFields; i++) {
38  pvFields.push_back(pvDataCreate->createPVField(fields[i]));
39  }
40  for(size_t i=0; i<numberFields; i++) {
41  pvFields[i]->setParentAndName(this,fieldNames[i]);
42  }
43 }
int i
Definition: scan.c:967
PVField(FieldConstPtr field)
Definition: PVField.cpp:30
std::tr1::shared_ptr< PVDataCreate > PVDataCreatePtr
Definition: pvData.h:124
std::vector< FieldConstPtr > FieldConstPtrArray
Definition: pvIntrospect.h:146
std::vector< std::string > StringArray
Definition: pvType.h:110
FORCE_INLINE const PVDataCreatePtr & getPVDataCreate()
Definition: pvData.h:1648
epics::pvData::PVStructure::PVStructure ( StructureConstPtr const &  structure,
PVFieldPtrArray const &  pvFields 
)

Constructor

Parameters
structureThe introspection interface.
pvFieldsThe array of fields for the structure.

Definition at line 45 of file PVStructure.cpp.

48 : PVField(structurePtr),
49  structurePtr(structurePtr),
50  extendsStructureName("")
51 {
52  size_t numberFields = structurePtr->getNumberFields();
53  StringArray const & fieldNames = structurePtr->getFieldNames();
54  pvFields.reserve(numberFields);
55  for(size_t i=0; i<numberFields; i++) {
56  pvFields.push_back(pvs[i]);
57  }
58  for(size_t i=0; i<numberFields; i++) {
59  pvFields[i]->setParentAndName(this,fieldNames[i]);
60  }
61 }
int i
Definition: scan.c:967
PVField(FieldConstPtr field)
Definition: PVField.cpp:30
std::vector< std::string > StringArray
Definition: pvType.h:110

Member Function Documentation

void epics::pvData::PVStructure::copy ( const PVStructure from)

Definition at line 329 of file PVStructure.cpp.

330 {
331  if(isImmutable())
332  throw std::invalid_argument("destination is immutable");
333 
334  if(*getStructure() != *from.getStructure())
335  throw std::invalid_argument("structure definitions do not match");
336 
337  copyUnchecked(from);
338 }
void copyUnchecked(const PVStructure &from)
bool isImmutable() const
Definition: pvData.h:198
const StructureConstPtr & getStructure() const
Definition: pvData.h:731
void epics::pvData::PVStructure::copyUnchecked ( const PVStructure from)

Definition at line 340 of file PVStructure.cpp.

341 {
342  if (this == &from)
343  return;
344 
345  PVFieldPtrArray const & fromPVFields = from.getPVFields();
346  PVFieldPtrArray const & toPVFields = getPVFields();
347 
348  size_t fieldsSize = fromPVFields.size();
349  for(size_t i = 0; i<fieldsSize; i++) {
350  toPVFields[i]->copyUnchecked(*fromPVFields[i]);
351  }
352 }
const PVFieldPtrArray & getPVFields() const
Definition: pvData.h:736
int i
Definition: scan.c:967
std::vector< PVFieldPtr > PVFieldPtrArray
Definition: pvData.h:70
void epics::pvData::PVStructure::copyUnchecked ( const PVStructure from,
const BitSet maskBitSet,
bool  inverse = false 
)

Definition at line 354 of file PVStructure.cpp.

355 {
356  if (this == &from)
357  return;
358 
359  size_t numberFields = from.getNumberFields();
360  size_t offset = from.getFieldOffset();
361  int32 next = inverse ?
362  maskBitSet.nextClearBit(static_cast<uint32>(offset)) :
363  maskBitSet.nextSetBit(static_cast<uint32>(offset));
364 
365  // no more changes or no changes in this structure
366  if(next<0||next>=static_cast<int32>(offset+numberFields)) return;
367 
368  // entire structure
369  if(static_cast<int32>(offset)==next) {
370  copyUnchecked(from);
371  return;
372  }
373 
374  PVFieldPtrArray const & fromPVFields = from.getPVFields();
375  PVFieldPtrArray const & toPVFields = getPVFields();
376 
377  size_t fieldsSize = fromPVFields.size();
378  for(size_t i = 0; i<fieldsSize; i++) {
379  PVFieldPtr pvField = fromPVFields[i];
380  offset = pvField->getFieldOffset();
381  int32 inumberFields = static_cast<int32>(pvField->getNumberFields());
382  next = inverse ?
383  maskBitSet.nextClearBit(static_cast<uint32>(offset)) :
384  maskBitSet.nextSetBit(static_cast<uint32>(offset));
385 
386  // no more changes
387  if(next<0) return;
388  // no change in this pvField
389  if(next>=static_cast<int32>(offset+inumberFields)) continue;
390 
391  // serialize field or fields
392  if(inumberFields==1) {
393  toPVFields[i]->copyUnchecked(*pvField);
394  } else {
395  PVStructure::shared_pointer fromPVStructure = std::tr1::static_pointer_cast<PVStructure>(pvField);
396  PVStructure::shared_pointer toPVStructure = std::tr1::static_pointer_cast<PVStructure>(toPVFields[i]);
397  toPVStructure->copyUnchecked(*fromPVStructure, maskBitSet, inverse);
398  }
399  }
400 }
const PVFieldPtrArray & getPVFields() const
Definition: pvData.h:736
PVStructure(StructureConstPtr const &structure)
Definition: PVStructure.cpp:27
int i
Definition: scan.c:967
shared_ptr< T > static_pointer_cast(shared_ptr< U > const &r) BOOST_NOEXCEPT
Definition: shared_ptr.hpp:788
void copyUnchecked(const PVStructure &from)
std::vector< PVFieldPtr > PVFieldPtrArray
Definition: pvData.h:70
std::tr1::shared_ptr< PVField > PVFieldPtr
Definition: pvData.h:66
int32_t int32
Definition: pvType.h:83
void epics::pvData::PVStructure::deserialize ( ByteBuffer pbuffer,
DeserializableControl pflusher 
)
virtual

Deserialize

Parameters
pbufferThe byte buffer.
pflusherInterface to call when buffer is empty.

Implements epics::pvData::Serializable.

Definition at line 225 of file PVStructure.cpp.

226  {
227  size_t fieldsSize = pvFields.size();
228  for(size_t i = 0; i<fieldsSize; i++)
229  pvFields[i]->deserialize(pbuffer, pcontrol);
230 
231 }
int i
Definition: scan.c:967
virtual void deserialize(ByteBuffer *pbuffer, DeserializableControl *pflusher) OVERRIDE FINAL
char * pbuffer
Definition: errlog.c:85
void epics::pvData::PVStructure::deserialize ( ByteBuffer pbuffer,
DeserializableControl pflusher,
BitSet pbitSet 
)
virtual

Deserialize

Parameters
pbufferThe byte buffer.
pflusherInterface to call when buffer is empty.
pbitSetA bitset the specifies which fields to deserialize.

Implements epics::pvData::BitSetSerializable.

Definition at line 269 of file PVStructure.cpp.

270  {
271  size_t offset = getFieldOffset();
272  size_t numberFields = getNumberFields();
273  int32 next = pbitSet->nextSetBit(static_cast<uint32>(offset));
274 
275  // no more changes or no changes in this structure
276  if(next<0||next>=static_cast<int32>(offset+numberFields)) return;
277 
278  // entire structure
279  if(static_cast<int32>(offset)==next) {
280  deserialize(pbuffer, pcontrol);
281  return;
282  }
283 
284  size_t fieldsSize = pvFields.size();
285  for(size_t i = 0; i<fieldsSize; i++) {
286  PVFieldPtr pvField = pvFields[i];
287  offset = pvField->getFieldOffset();
288  int32 inumberFields = static_cast<int32>(pvField->getNumberFields());
289  next = pbitSet->nextSetBit(static_cast<uint32>(offset));
290  // no more changes
291  if(next<0) return;
292  // no change in this pvField
293  if(next>=static_cast<int32>(offset+inumberFields)) continue;
294 
295  // deserialize field or fields
296  if(inumberFields==1) {
297  pvField->deserialize(pbuffer, pcontrol);
298  } else {
300  pvStructure->deserialize(pbuffer, pcontrol, pbitSet);
301  }
302  }
303 }
PVStructure(StructureConstPtr const &structure)
Definition: PVStructure.cpp:27
int i
Definition: scan.c:967
shared_ptr< T > static_pointer_cast(shared_ptr< U > const &r) BOOST_NOEXCEPT
Definition: shared_ptr.hpp:788
std::size_t getFieldOffset() const
Definition: PVField.cpp:44
virtual void deserialize(ByteBuffer *pbuffer, DeserializableControl *pflusher) OVERRIDE FINAL
std::tr1::shared_ptr< PVStructure > PVStructurePtr
Definition: pvData.h:87
char * pbuffer
Definition: errlog.c:85
std::tr1::shared_ptr< PVField > PVFieldPtr
Definition: pvData.h:66
int32_t int32
Definition: pvType.h:83
std::size_t getNumberFields() const
Definition: PVField.cpp:56
std::ostream & epics::pvData::PVStructure::dumpValue ( std::ostream &  o) const
virtual

Puts the PVField raw value to the stream.

Parameters
ooutput stream.
Returns
The output stream.

Implements epics::pvData::PVField.

Definition at line 305 of file PVStructure.cpp.

306 {
307  o << format::indent() << getStructure()->getID() << ' ' << getFieldName();
308  o << std::endl;
309  {
310  format::indent_scope s(o);
311 
312  PVFieldPtrArray const & fieldsData = getPVFields();
313  if (fieldsData.size() != 0) {
314  size_t length = getStructure()->getNumberFields();
315  for(size_t i=0; i<length; i++) {
316  PVFieldPtr fieldField = fieldsData[i];
317  Type type = fieldField->getField()->getType();
318  if (type == scalar || type == scalarArray)
319  o << format::indent() << fieldField->getField()->getID() << ' ' << fieldField->getFieldName() << ' ' << *(fieldField.get()) << std::endl;
320  else
321  o << *(fieldField.get());
322  }
323  }
324  }
325  return o;
326 }
const std::string & getFieldName() const
Definition: pvData.h:166
const PVFieldPtrArray & getPVFields() const
Definition: pvData.h:736
int i
Definition: scan.c:967
pvd::StructureConstPtr type
std::vector< PVFieldPtr > PVFieldPtrArray
Definition: pvData.h:70
std::tr1::shared_ptr< PVField > PVFieldPtr
Definition: pvData.h:66
const StructureConstPtr & getStructure() const
Definition: pvData.h:731
const PVFieldPtrArray& epics::pvData::PVStructure::getPVFields ( ) const
inline

Get the array of pointers to the subfields in the structure.

Returns
The array.

Definition at line 736 of file pvData.h.

736 { return pvFields; }
const StructureConstPtr& epics::pvData::PVStructure::getStructure ( ) const
inline

Get the introspection interface

Returns
The interface.

Definition at line 731 of file pvData.h.

731 { return structurePtr; }
template<typename A >
FORCE_INLINE std::tr1::shared_ptr<PVField> epics::pvData::PVStructure::getSubField ( a)
inline

Get the subfield with the specified offset.

Parameters
aA sub-field name or index
Returns
Pointer to the field or NULL if field does not exist.

Definition at line 744 of file pvData.h.

745  {
746  return getSubFieldImpl(a, false);
747  }
template<typename A >
FORCE_INLINE std::tr1::shared_ptr<const PVField> epics::pvData::PVStructure::getSubField ( a) const
inline

Definition at line 750 of file pvData.h.

751  {
752  return getSubFieldImpl(a, false);
753  }
template<typename PVD , typename A >
std::tr1::shared_ptr<PVD> epics::pvData::PVStructure::getSubField ( a)
inline

Get a subfield with the specified name.

Parameters
aA sub-field name or index
Returns
A pointer to the sub-field or null if field does not exist or has a different type
PVIntPtr ptr = pvStruct->getSubField<PVInt>("substruct.leaffield");

A field name is a '.' delimited list of child field names (no whitespace allowed)

Definition at line 766 of file pvData.h.

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  }
#define STATIC_ASSERT(expr)
Declare a condition that should be true at compile-time.
Definition: epicsAssert.h:86
shared_ptr< T > dynamic_pointer_cast(shared_ptr< U > const &r) BOOST_NOEXCEPT
Definition: shared_ptr.hpp:808
template<typename PVD , typename A >
std::tr1::shared_ptr<const PVD> epics::pvData::PVStructure::getSubField ( a) const
inline

Definition at line 773 of file pvData.h.

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  }
#define STATIC_ASSERT(expr)
Declare a condition that should be true at compile-time.
Definition: epicsAssert.h:86
shared_ptr< T > dynamic_pointer_cast(shared_ptr< U > const &r) BOOST_NOEXCEPT
Definition: shared_ptr.hpp:808
template<typename A >
FORCE_INLINE std::tr1::shared_ptr<PVField> epics::pvData::PVStructure::getSubFieldT ( a)
inline

Get the subfield with the specified offset.

Parameters
aA sub-field name or index
Exceptions
std::runtime_errorif the requested sub-field doesn't exist, or has a different type
Returns
Pointer to the field

Definition at line 786 of file pvData.h.

787  {
788  return getSubFieldImpl(a, true);
789  }
template<typename A >
FORCE_INLINE std::tr1::shared_ptr<const PVField> epics::pvData::PVStructure::getSubFieldT ( a) const
inline

Definition at line 792 of file pvData.h.

793  {
794  return getSubFieldImpl(a, true);
795  }
template<typename PVD , typename A >
std::tr1::shared_ptr<PVD> epics::pvData::PVStructure::getSubFieldT ( a)
inline

Definition at line 806 of file pvData.h.

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  }
#define STATIC_ASSERT(expr)
Declare a condition that should be true at compile-time.
Definition: epicsAssert.h:86
template<typename PVD , typename A >
std::tr1::shared_ptr<const PVD> epics::pvData::PVStructure::getSubFieldT ( a) const
inline

Definition at line 816 of file pvData.h.

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  }
#define STATIC_ASSERT(expr)
Declare a condition that should be true at compile-time.
Definition: epicsAssert.h:86
epics::pvData::PVStructure::POINTER_DEFINITIONS ( PVStructure  )
void epics::pvData::PVStructure::serialize ( ByteBuffer pbuffer,
SerializableControl pflusher 
) const
virtual

Serialize.

Parameters
pbufferThe byte buffer.
pflusherInterface to call when buffer is full.

Implements epics::pvData::Serializable.

Definition at line 218 of file PVStructure.cpp.

219  {
220  size_t fieldsSize = pvFields.size();
221  for(size_t i = 0; i<fieldsSize; i++)
222  pvFields[i]->serialize(pbuffer, pflusher);
223 }
int i
Definition: scan.c:967
virtual void serialize(ByteBuffer *pbuffer, SerializableControl *pflusher) const OVERRIDE FINAL
char * pbuffer
Definition: errlog.c:85
void epics::pvData::PVStructure::serialize ( ByteBuffer pbuffer,
SerializableControl pflusher,
BitSet pbitSet 
) const
virtual

Serialize.

Parameters
pbufferThe byte buffer.
pflusherInterface to call when buffer is full.
pbitSetA bitset the specifies which fields to serialize.

Implements epics::pvData::BitSetSerializable.

Definition at line 233 of file PVStructure.cpp.

234  {
235  size_t numberFields = this->getNumberFields();
236  size_t offset = this->getFieldOffset();
237  int32 next = pbitSet->nextSetBit(static_cast<uint32>(offset));
238 
239  // no more changes or no changes in this structure
240  if(next<0||next>=static_cast<int32>(offset+numberFields)) return;
241 
242  // entire structure
243  if(static_cast<int32>(offset)==next) {
244  serialize(pbuffer, pflusher);
245  return;
246  }
247 
248  size_t fieldsSize = pvFields.size();
249  for(size_t i = 0; i<fieldsSize; i++) {
250  PVField* pvField = pvFields[i].get();
251  offset = pvField->getFieldOffset();
252  int32 inumberFields = static_cast<int32>(pvField->getNumberFields());
253  next = pbitSet->nextSetBit(static_cast<uint32>(offset));
254 
255  // no more changes
256  if(next<0) return;
257  // no change in this pvField
258  if(next>=static_cast<int32>(offset+inumberFields)) continue;
259 
260  // serialize field or fields
261  if(inumberFields==1) {
262  pvField->serialize(pbuffer, pflusher);
263  } else {
264  static_cast<PVStructure*>(pvField)->serialize(pbuffer, pflusher, pbitSet);
265  }
266  }
267 }
PVStructure(StructureConstPtr const &structure)
Definition: PVStructure.cpp:27
int i
Definition: scan.c:967
virtual void serialize(ByteBuffer *pbuffer, SerializableControl *pflusher) const OVERRIDE FINAL
PVField(FieldConstPtr field)
Definition: PVField.cpp:30
std::size_t getFieldOffset() const
Definition: PVField.cpp:44
char * pbuffer
Definition: errlog.c:85
int32_t int32
Definition: pvType.h:83
std::size_t getNumberFields() const
Definition: PVField.cpp:56
void epics::pvData::PVStructure::setImmutable ( )
virtual

Set the field to be immutable, i.e. it can no longer be modified. This is permanent, i.e. once done the field cannot be made mutable.

Reimplemented from epics::pvData::PVField.

Definition at line 65 of file PVStructure.cpp.

66 {
67  size_t numFields = pvFields.size();
68  for(size_t i=0; i<numFields; i++) {
69  PVFieldPtr pvField = pvFields[i];
70  pvField->setImmutable();
71  }
73 }
int i
Definition: scan.c:967
virtual void setImmutable()
Definition: PVField.cpp:63
std::tr1::shared_ptr< PVField > PVFieldPtr
Definition: pvData.h:66
FORCE_INLINE Formatter epics::pvData::PVStructure::stream ( ) const
inline

Definition at line 913 of file pvData.h.

913 { return Formatter(*this); }

Friends And Related Function Documentation

friend class PVDataCreate
friend

Definition at line 926 of file pvData.h.


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