This is Unofficial EPICS BASE Doxygen Site
epics::pvCopy::PVCopy Class Reference

Support for subset of fields in a pvStructure. More...

#include "pvStructureCopy.h"

+ Inheritance diagram for epics::pvCopy::PVCopy:
+ Collaboration diagram for epics::pvCopy::PVCopy:

Public Member Functions

 POINTER_DEFINITIONS (PVCopy)
 
virtual ~PVCopy ()
 
virtual void destroy ()
 
epics::pvData::PVStructurePtr getPVMaster ()
 
void traverseMaster (PVCopyTraverseMasterCallbackPtr const &callback)
 
epics::pvData::StructureConstPtr getStructure ()
 
epics::pvData::PVStructurePtr createPVStructure ()
 
std::size_t getCopyOffset (epics::pvData::PVFieldPtr const &masterPVField)
 
std::size_t getCopyOffset (epics::pvData::PVStructurePtr const &masterPVStructure, epics::pvData::PVFieldPtr const &masterPVField)
 
epics::pvData::PVFieldPtr getMasterPVField (std::size_t structureOffset)
 
void initCopy (epics::pvData::PVStructurePtr const &copyPVStructure, epics::pvData::BitSetPtr const &bitSet)
 
bool updateCopySetBitSet (epics::pvData::PVStructurePtr const &copyPVStructure, epics::pvData::BitSetPtr const &bitSet)
 
bool updateCopyFromBitSet (epics::pvData::PVStructurePtr const &copyPVStructure, epics::pvData::BitSetPtr const &bitSet)
 
void updateMaster (epics::pvData::PVStructurePtr const &copyPVStructure, epics::pvData::BitSetPtr const &bitSet)
 
epics::pvData::PVStructurePtr getOptions (std::size_t fieldOffset)
 
std::string dump ()
 

Static Public Member Functions

static PVCopyPtr create (epics::pvData::PVStructurePtr const &pvMaster, epics::pvData::PVStructurePtr const &pvRequest, std::string const &structureName)
 

Detailed Description

Support for subset of fields in a pvStructure.

Class that manages one or more PVStructures that holds an arbitrary subset of the fields in another PVStructure called master.

Definition at line 65 of file pvStructureCopy.h.

Constructor & Destructor Documentation

virtual epics::pvCopy::PVCopy::~PVCopy ( )
inlinevirtual

Definition at line 81 of file pvStructureCopy.h.

81 {}

Member Function Documentation

PVCopyPtr epics::pvCopy::PVCopy::create ( epics::pvData::PVStructurePtr const &  pvMaster,
epics::pvData::PVStructurePtr const &  pvRequest,
std::string const &  structureName 
)
static

Create a new pvCopy

Parameters
pvMasterThe top-level structure for which a copy of an arbitrary subset of the fields in master will be created and managed.
pvRequestSelects the set of subfields desired and options for each field.
structureNameThe name for the top level of any PVStructure created.

Definition at line 73 of file pvCopy.cpp.

77 {
78  PVStructurePtr pvStructure(pvRequest);
79  if(structureName.size()>0) {
80  if(pvStructure->getStructure()->getNumberFields()>0) {
81  pvStructure = pvRequest->getSubField<PVStructure>(structureName);
82  if(!pvStructure) return NULLPVCopy;
83  }
84  } else if(pvRequest->getSubField<PVStructure>("field")) {
85  pvStructure = pvRequest->getSubField<PVStructure>("field");
86  }
87  PVCopyPtr pvCopy = PVCopyPtr(new PVCopy(pvMaster));
88  bool result = pvCopy->init(pvStructure);
89  if(!result) return PVCopyPtr();
90  pvCopy->traverseMasterInitPlugin();
91 //cout << pvCopy->dump() << endl;
92  return pvCopy;
93 }
pvac::PutEvent result
Definition: clientSync.cpp:117
std::tr1::shared_ptr< PVCopy > PVCopyPtr
Definition: pvPlugin.h:25
Data interface for a structure,.
Definition: pvData.h:712
std::tr1::shared_ptr< PVStructure > PVStructurePtr
Definition: pvData.h:87
PVStructurePtr epics::pvCopy::PVCopy::createPVStructure ( )

Create a copy instance. Monitors keep a queue of monitor elements. Since each element needs a PVStructure, multiple top-level structures will be created.

Definition at line 110 of file pvCopy.cpp.

111 {
112  if(cacheInitStructure) {
113  PVStructurePtr save = cacheInitStructure;
114  cacheInitStructure.reset();
115  return save;
116  }
117  PVStructurePtr pvStructure =
118  getPVDataCreate()->createPVStructure(structure);
119  return pvStructure;
120 }
std::tr1::shared_ptr< PVStructure > PVStructurePtr
Definition: pvData.h:87
FORCE_INLINE const PVDataCreatePtr & getPVDataCreate()
Definition: pvData.h:1648
void epics::pvCopy::PVCopy::destroy ( )
virtual

Definition at line 431 of file pvCopy.cpp.

432 {
433  headNode.reset();
434 }
string epics::pvCopy::PVCopy::dump ( )

For debugging.

Definition at line 327 of file pvCopy.cpp.

328 {
329  string builder;
330  dump(&builder,headNode,0);
331  return builder;
332 }
std::string dump()
Definition: pvCopy.cpp:327
size_t epics::pvCopy::PVCopy::getCopyOffset ( epics::pvData::PVFieldPtr const &  masterPVField)

Given a field in pvMaster. return the offset in copy for the same field. A value of std::string::npos means that the copy does not have this field.

Parameters
masterPVFieldThe field in master.

Definition at line 123 of file pvCopy.cpp.

124 {
125  if(!headNode->isStructure) {
126  CopyNodePtr node = static_pointer_cast<CopyNode>(headNode);
127  if((node->masterPVField.get())==masterPVField.get()) {
128  return headNode->structureOffset;
129  }
130  PVStructure * parent = masterPVField->getParent();
131  size_t offsetParent = parent->getFieldOffset();
132  size_t off = masterPVField->getFieldOffset();
133  size_t offdiff = off -offsetParent;
134  if(offdiff<node->nfields) return headNode->structureOffset + offdiff;
135  return string::npos;
136  }
137  CopyStructureNodePtr structNode = static_pointer_cast<CopyStructureNode>(headNode);
138  CopyNodePtr node = getCopyOffset(structNode,masterPVField);
139  if(node) return node->structureOffset;
140  return string::npos;
141 }
std::tr1::shared_ptr< CopyStructureNode > CopyStructureNodePtr
std::tr1::shared_ptr< CopyNode > CopyNodePtr
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
Data interface for a structure,.
Definition: pvData.h:712
std::size_t getCopyOffset(epics::pvData::PVFieldPtr const &masterPVField)
Definition: pvCopy.cpp:123
PVStructure * getParent()
Definition: pvData.h:213
size_t epics::pvCopy::PVCopy::getCopyOffset ( epics::pvData::PVStructurePtr const &  masterPVStructure,
epics::pvData::PVFieldPtr const &  masterPVField 
)

Given a field in pvMaster. return the offset in copy for the same field. A value of std::string::npos means that the copy does not have this field.

Parameters
masterPVStructureA structure in master that has masterPVField.
masterPVFieldThe field in master.

Definition at line 143 of file pvCopy.cpp.

146 {
147  CopyNodePtr node;
148  if(!headNode->isStructure) {
149  node = static_pointer_cast<CopyNode>(headNode);
150  if(node->masterPVField.get()!=masterPVStructure.get()) return string::npos;
151  } else {
152  CopyStructureNodePtr snode = static_pointer_cast<CopyStructureNode>(headNode);
153  node = getCopyOffset(snode,masterPVField);
154  }
155  if(!node) return string::npos;
156  size_t diff = masterPVField->getFieldOffset()
157  - masterPVStructure->getFieldOffset();
158  return node->structureOffset + diff;
159 }
std::tr1::shared_ptr< CopyStructureNode > CopyStructureNodePtr
std::tr1::shared_ptr< CopyNode > CopyNodePtr
shared_ptr< T > static_pointer_cast(shared_ptr< U > const &r) BOOST_NOEXCEPT
Definition: shared_ptr.hpp:788
std::size_t getCopyOffset(epics::pvData::PVFieldPtr const &masterPVField)
Definition: pvCopy.cpp:123
PVFieldPtr epics::pvCopy::PVCopy::getMasterPVField ( std::size_t  structureOffset)

Given an offset in the copy get the corresponding field in pvMaster.

Parameters
structureOffsetThe offset in the copy.

Definition at line 161 of file pvCopy.cpp.

162 {
163  CopyNodePtr node;
164  if(!headNode->isStructure) {
165  node = headNode;
166  } else {
167  CopyStructureNodePtr snode = static_pointer_cast<CopyStructureNode>(headNode);
168  node = getMasterNode(snode,structureOffset);
169  }
170  if(!node) {
171  throw std::logic_error(
172  "PVCopy::getMasterPVField: structureOffset not valid");
173  }
174  size_t diff = structureOffset - node->structureOffset;
175  PVFieldPtr pvMasterField = node->masterPVField;
176  if(diff==0) return pvMasterField;
177  PVStructurePtr pvStructure
178  = static_pointer_cast<PVStructure>(pvMasterField);
179  return pvStructure->getSubField(
180  pvMasterField->getFieldOffset() + diff);
181 }
FORCE_INLINE std::tr1::shared_ptr< PVField > getSubField(A a)
Definition: pvData.h:744
std::tr1::shared_ptr< CopyStructureNode > CopyStructureNodePtr
std::tr1::shared_ptr< CopyNode > CopyNodePtr
shared_ptr< T > static_pointer_cast(shared_ptr< U > const &r) BOOST_NOEXCEPT
Definition: shared_ptr.hpp:788
Data interface for a structure,.
Definition: pvData.h:712
std::tr1::shared_ptr< PVStructure > PVStructurePtr
Definition: pvData.h:87
std::tr1::shared_ptr< PVField > PVFieldPtr
Definition: pvData.h:66
PVStructurePtr epics::pvCopy::PVCopy::getOptions ( std::size_t  fieldOffset)

Get the options for the field at the specified offset.

Parameters
fieldOffsetthe offset in copy.
Returns
A NULL is returned if no options were specified for the field. If options were specified,PVStructurePtr is a structures with a set of PVString subfields that specify name,value pairs.s name is the subField name and value is the subField value.

Definition at line 300 of file pvCopy.cpp.

301 {
302  if(fieldOffset==0) return headNode->options;
303  CopyNodePtr node = headNode;
304  while(true) {
305  if(node->structureOffset==fieldOffset) return node->options;
306  if(!node->isStructure) return NULLPVStructure;
307  CopyStructureNodePtr structNode = static_pointer_cast<CopyStructureNode>(node);
308  CopyNodePtrArrayPtr nodes = structNode->nodes;
309  bool okToContinue = false;
310  for(size_t i=0; i< nodes->size(); i++) {
311  node = (*nodes)[i];
312  size_t soff = node->structureOffset;
313  if(fieldOffset>=soff && fieldOffset<soff+node->nfields) {
314  if(fieldOffset==soff) return node->options;
315  if(!node->isStructure) {
316  return NULLPVStructure;
317  }
318  okToContinue = true;
319  break;
320  }
321  }
322  if(okToContinue) continue;
323  throw std::logic_error("PVCopy::getOptions logic error: fieldOffset not valid");
324  }
325 }
std::tr1::shared_ptr< CopyStructureNode > CopyStructureNodePtr
std::tr1::shared_ptr< CopyNode > CopyNodePtr
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::tr1::shared_ptr< CopyNodePtrArray > CopyNodePtrArrayPtr
Definition: pvCopy.cpp:67
PVStructurePtr epics::pvCopy::PVCopy::getPVMaster ( )

Get the top-level structure of master

Returns
The master top-level structure. This should not be modified.

Definition at line 95 of file pvCopy.cpp.

96 {
97  return pvMaster;
98 }
StructureConstPtr epics::pvCopy::PVCopy::getStructure ( )

Get the introspection interface for a PVStructure for e copy.

Definition at line 105 of file pvCopy.cpp.

106 {
107  return structure;
108 }
void epics::pvCopy::PVCopy::initCopy ( epics::pvData::PVStructurePtr const &  copyPVStructure,
epics::pvData::BitSetPtr const &  bitSet 
)

Initialize the fields in copyPVStructure by giving each field the value from the corresponding field in pvMaster. bitSet will be set to show that all fields are changed.

Parameters
copyPVStructureA copy top-level structure.
bitSetA bitSet for copyPVStructure.

Definition at line 183 of file pvCopy.cpp.

186 {
187  for(size_t i=0; i< copyPVStructure->getNumberFields(); ++i) {
188  bitSet->set(i,true);
189  }
190  updateCopyFromBitSet(copyPVStructure,headNode,bitSet);
191 }
int i
Definition: scan.c:967
bool updateCopyFromBitSet(epics::pvData::PVStructurePtr const &copyPVStructure, epics::pvData::BitSetPtr const &bitSet)
Definition: pvCopy.cpp:202
epics::pvCopy::PVCopy::POINTER_DEFINITIONS ( PVCopy  )
void epics::pvCopy::PVCopy::traverseMaster ( PVCopyTraverseMasterCallbackPtr const &  callback)

Traverse all the fields in master.

Parameters
callbackThis is called for each field on master.

Definition at line 100 of file pvCopy.cpp.

101 {
102  traverseMaster(headNode,callback);
103 }
void traverseMaster(PVCopyTraverseMasterCallbackPtr const &callback)
Definition: pvCopy.cpp:100
Definition: caget.c:48
bool epics::pvCopy::PVCopy::updateCopyFromBitSet ( epics::pvData::PVStructurePtr const &  copyPVStructure,
epics::pvData::BitSetPtr const &  bitSet 
)

For each set bit in bitSet set the field in copyPVStructure to the value of the corresponding field in pvMaster.

Parameters
copyPVStructureA copy top-level structure.
bitSetA bitSet for copyPVStructure.
Returns
(false,true) if client (should not,should) receive changes.

Definition at line 202 of file pvCopy.cpp.

205 {
206  if(bitSet->get(0)) {
207  for(size_t i=0; i< copyPVStructure->getNumberFields(); ++i) {
208  bitSet->set(i,true);
209  }
210  }
211  updateCopyFromBitSet(copyPVStructure,headNode,bitSet);
212  return checkIgnore(copyPVStructure,bitSet);
213 }
int i
Definition: scan.c:967
bool updateCopyFromBitSet(epics::pvData::PVStructurePtr const &copyPVStructure, epics::pvData::BitSetPtr const &bitSet)
Definition: pvCopy.cpp:202
bool epics::pvCopy::PVCopy::updateCopySetBitSet ( epics::pvData::PVStructurePtr const &  copyPVStructure,
epics::pvData::BitSetPtr const &  bitSet 
)

Set all fields in copyPVStructure to the value of the corresponding field in pvMaster. Each field that is changed has it's corresponding bit set in bitSet.

Parameters
copyPVStructureA copy top-level structure.
bitSetA bitSet for copyPVStructure.
Returns
(false,true) if client (should not,should) receive changes.

Definition at line 194 of file pvCopy.cpp.

197 {
198  updateCopySetBitSet(copyPVStructure,headNode,bitSet);
199  return checkIgnore(copyPVStructure,bitSet);
200 }
bool updateCopySetBitSet(epics::pvData::PVStructurePtr const &copyPVStructure, epics::pvData::BitSetPtr const &bitSet)
Definition: pvCopy.cpp:194
void epics::pvCopy::PVCopy::updateMaster ( epics::pvData::PVStructurePtr const &  copyPVStructure,
epics::pvData::BitSetPtr const &  bitSet 
)

For each set bit in bitSet set the field in pvMaster to the value of the corresponding field in copyPVStructure

Parameters
copyPVStructureA copy top-level structure.
bitSetA bitSet for copyPVStructure.

Definition at line 280 of file pvCopy.cpp.

283 {
284  updateMasterCheckBitSet(copyPVStructure,bitSet,0);
285  size_t nextSet =0;
286  while(true) {
287  nextSet = bitSet->nextSetBit(nextSet);
288  if(nextSet==string::npos) return;
289  PVFieldPtr pvCopy = copyPVStructure->getSubField(nextSet);
290  PVFieldPtr pvMaster = headNode->masterPVField;
291  if(pvMaster->getField()->getType()==epics::pvData::structure) {
293  pvMaster = pv->getSubField(pvCopy->getFullName());
294  }
295  updateMasterField(getCopyNode(nextSet),pvCopy,pvMaster,bitSet);
296  bitSet->clear(nextSet);
297  }
298 }
FORCE_INLINE std::tr1::shared_ptr< PVField > getSubField(A a)
Definition: pvData.h:744
Definition: tool_lib.h:67
shared_ptr< T > static_pointer_cast(shared_ptr< U > const &r) BOOST_NOEXCEPT
Definition: shared_ptr.hpp:788
Data interface for a structure,.
Definition: pvData.h:712
std::tr1::shared_ptr< PVStructure > PVStructurePtr
Definition: pvData.h:87
std::tr1::shared_ptr< PVField > PVFieldPtr
Definition: pvData.h:66

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