15 #define epicsExportSharedSymbols 25 namespace epics {
namespace pvData {
29 structurePtr(structurePtr),
30 extendsStructureName(
"")
34 StringArray const & fieldNames = structurePtr->getFieldNames();
35 pvFields.reserve(numberFields);
37 for(
size_t i=0;
i<numberFields;
i++) {
38 pvFields.push_back(pvDataCreate->createPVField(fields[
i]));
40 for(
size_t i=0;
i<numberFields;
i++) {
41 pvFields[
i]->setParentAndName(
this,fieldNames[
i]);
49 structurePtr(structurePtr),
50 extendsStructureName(
"")
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]);
58 for(
size_t i=0;
i<numberFields;
i++) {
59 pvFields[
i]->setParentAndName(
this,fieldNames[
i]);
67 size_t numFields = pvFields.size();
68 for(
size_t i=0;
i<numFields;
i++) {
70 pvField->setImmutable();
75 PVFieldPtr PVStructure::getSubFieldImpl(
size_t fieldOffset,
bool throws)
const 84 ss <<
"Failed to get field with offset " 85 << fieldOffset <<
" (Invalid offset)" ;
86 throw std::runtime_error(ss.str());
92 for(
size_t i=0, numFields = current->pvFields.size();
i<numFields;
i++) {
95 if(pvField->getFieldOffset()==fieldOffset) {
98 }
else if(pvField->getNextFieldOffset()<=fieldOffset) {
101 }
else if(pvField->getField()->getType()==
structure) {
102 current =
static_cast<PVStructure *
>(pvField.get());
107 throw std::logic_error(
"PVStructure.getSubField: Logic error");
110 PVFieldPtr PVStructure::getSubFieldImpl(
const char *name,
bool throws)
const 116 throw std::invalid_argument(
"Failed to get field: (Field name is NULL string)");
120 const char *fullName = name;
122 const char *sep=name;
123 while(*sep!=
'\0' && *sep!=
'.' && *sep!=
' ') sep++;
128 std::stringstream ss;
129 ss <<
"Failed to get field: " << fullName
130 <<
" (No spaces allowed in field name)";
131 throw std::runtime_error(ss.str());
141 std::stringstream ss;
142 ss <<
"Failed to get field: " << fullName
143 <<
" (Zero-length field name encountered)";
144 throw std::runtime_error(ss.str());
154 for(
size_t i=0, n=pvFields.size();
i!=n;
i++) {
156 const std::string& fname = fld->getFieldName();
158 if(fname.size()==N && memcmp(name, fname.c_str(), N)==0) {
168 std::stringstream ss;
169 ss <<
"Failed to get field: " << fullName <<
" (" 170 << std::string(fullName, sep) <<
" not found)";
171 throw std::runtime_error(ss.str());
184 std::stringstream ss;
185 ss <<
"Failed to get field: " << fullName
186 <<
" (" << std::string(fullName, sep)
187 <<
" is not a structure)";
188 throw std::runtime_error(ss.str());
198 return child->shared_from_this();
203 void PVStructure::throwBadFieldType(
const char *name)
205 std::ostringstream ss;
206 ss <<
"Failed to get field: " << name <<
" (Field has wrong type)";
207 throw std::runtime_error(ss.str());
210 void PVStructure::throwBadFieldType(std::size_t fieldOffset)
212 std::stringstream ss;
213 ss <<
"Failed to get field with offset " 214 << fieldOffset <<
" (Field has wrong type)";
215 throw std::runtime_error(ss.str());
220 size_t fieldsSize = pvFields.size();
221 for(
size_t i = 0;
i<fieldsSize;
i++)
227 size_t fieldsSize = pvFields.size();
228 for(
size_t i = 0;
i<fieldsSize;
i++)
240 if(next<0||next>=static_cast<int32>(offset+numberFields))
return;
243 if(static_cast<int32>(offset)==next) {
248 size_t fieldsSize = pvFields.size();
249 for(
size_t i = 0;
i<fieldsSize;
i++) {
250 PVField* pvField = pvFields[
i].get();
253 next = pbitSet->
nextSetBit(static_cast<uint32>(offset));
258 if(next>=static_cast<int32>(offset+inumberFields))
continue;
261 if(inumberFields==1) {
276 if(next<0||next>=static_cast<int32>(offset+numberFields))
return;
279 if(static_cast<int32>(offset)==next) {
284 size_t fieldsSize = pvFields.size();
285 for(
size_t i = 0;
i<fieldsSize;
i++) {
287 offset = pvField->getFieldOffset();
288 int32 inumberFields =
static_cast<int32>(pvField->getNumberFields());
289 next = pbitSet->
nextSetBit(static_cast<uint32>(offset));
293 if(next>=static_cast<int32>(offset+inumberFields))
continue;
296 if(inumberFields==1) {
297 pvField->deserialize(pbuffer, pcontrol);
300 pvStructure->
deserialize(pbuffer, pcontrol, pbitSet);
313 if (fieldsData.size() != 0) {
315 for(
size_t i=0;
i<length;
i++) {
317 Type type = fieldField->getField()->getType();
319 o <<
format::indent() << fieldField->getField()->getID() <<
' ' << fieldField->getFieldName() <<
' ' << *(fieldField.get()) << std::endl;
321 o << *(fieldField.get());
332 throw std::invalid_argument(
"destination is immutable");
335 throw std::invalid_argument(
"structure definitions do not match");
348 size_t fieldsSize = fromPVFields.size();
349 for(
size_t i = 0;
i<fieldsSize;
i++) {
350 toPVFields[
i]->copyUnchecked(*fromPVFields[
i]);
361 int32 next = inverse ?
363 maskBitSet.
nextSetBit(static_cast<uint32>(offset));
366 if(next<0||next>=static_cast<int32>(offset+numberFields))
return;
369 if(static_cast<int32>(offset)==next) {
377 size_t fieldsSize = fromPVFields.size();
378 for(
size_t i = 0;
i<fieldsSize;
i++) {
380 offset = pvField->getFieldOffset();
381 int32 inumberFields =
static_cast<int32>(pvField->getNumberFields());
384 maskBitSet.
nextSetBit(static_cast<uint32>(offset));
389 if(next>=static_cast<int32>(offset+inumberFields))
continue;
392 if(inumberFields==1) {
393 toPVFields[
i]->copyUnchecked(*pvField);
397 toPVStructure->
copyUnchecked(*fromPVStructure, maskBitSet, inverse);
virtual void setImmutable() OVERRIDE FINAL
const std::string & getFieldName() const
const PVFieldPtrArray & getPVFields() const
PVStructure(StructureConstPtr const &structure)
virtual void serialize(ByteBuffer *buffer, SerializableControl *flusher) const =0
virtual void setImmutable()
virtual void serialize(ByteBuffer *pbuffer, SerializableControl *pflusher) const OVERRIDE FINAL
shared_ptr< T > static_pointer_cast(shared_ptr< U > const &r) BOOST_NOEXCEPT
pvd::StructureConstPtr type
TODO only here because of the Lockable.
std::tr1::shared_ptr< const Structure > StructureConstPtr
virtual std::ostream & dumpValue(std::ostream &o) const OVERRIDE FINAL
Callback class for deserialization.
PVField is the base class for each PVData field.
std::size_t getFieldOffset() const
void copyUnchecked(const PVStructure &from)
void copy(const PVStructure &from)
std::tr1::shared_ptr< PVDataCreate > PVDataCreatePtr
int32 nextClearBit(uint32 fromIndex) const
This class implements a Bytebuffer that is like the java.nio.ByteBuffer.
int32 nextSetBit(uint32 fromIndex) const
std::vector< FieldConstPtr > FieldConstPtrArray
std::vector< PVFieldPtr > PVFieldPtrArray
Data interface for a structure,.
virtual void deserialize(ByteBuffer *pbuffer, DeserializableControl *pflusher) OVERRIDE FINAL
std::tr1::shared_ptr< PVStructure > PVStructurePtr
std::vector< std::string > StringArray
std::tr1::shared_ptr< PVField > PVFieldPtr
Callback class for serialization.
const StructureConstPtr & getStructure() const
FORCE_INLINE const PVDataCreatePtr & getPVDataCreate()
std::size_t getNextFieldOffset() const
std::size_t getNumberFields() const