From 0ceb87eee1e5d194333c99c70b18d678a2d56ee4 Mon Sep 17 00:00:00 2001 From: Matej Sekoranja Date: Tue, 13 May 2014 00:18:30 +0200 Subject: [PATCH] Array IF added --- pvDataApp/factory/FieldCreateFactory.cpp | 13 +++++-- pvDataApp/pv/pvData.h | 20 +++++++++++ pvDataApp/pv/pvIntrospect.h | 46 ++++++++++++++++++++---- 3 files changed, 70 insertions(+), 9 deletions(-) diff --git a/pvDataApp/factory/FieldCreateFactory.cpp b/pvDataApp/factory/FieldCreateFactory.cpp index 5e010a9..1685966 100644 --- a/pvDataApp/factory/FieldCreateFactory.cpp +++ b/pvDataApp/factory/FieldCreateFactory.cpp @@ -216,8 +216,15 @@ static UnionConstPtr deserializeUnionField(const FieldCreate* fieldCreate, ByteB return fieldCreate->createUnion(id, fieldNames, fields); } +Array::Array(Type type) + : Field(type) +{ +} + +Array::~Array() {} + ScalarArray::ScalarArray(ScalarType elementType) -: Field(scalarArray),elementType(elementType) +: Array(scalarArray),elementType(elementType) { if(elementType<0 || elementType>MAX_SCALAR_TYPE) throw std::invalid_argument("Can't construct ScalarArray from invalid ScalarType"); @@ -282,7 +289,7 @@ void ScalarArray::deserialize(ByteBuffer* /*buffer*/, DeserializableControl* /*c } StructureArray::StructureArray(StructureConstPtr const & structure) -: Field(structureArray),pstructure(structure) +: Array(structureArray),pstructure(structure) { } @@ -312,7 +319,7 @@ void StructureArray::deserialize(ByteBuffer* /*buffer*/, DeserializableControl* } UnionArray::UnionArray(UnionConstPtr const & _punion) -: Field(unionArray),punion(_punion) +: Array(unionArray),punion(_punion) { } diff --git a/pvDataApp/pv/pvData.h b/pvDataApp/pv/pvData.h index c864eb6..762b718 100644 --- a/pvDataApp/pv/pvData.h +++ b/pvDataApp/pv/pvData.h @@ -542,6 +542,11 @@ public: * Destructor */ virtual ~PVArray(){}; + /** + * Get the introspection interface + * @return The interface. + */ + virtual ArrayConstPtr getArray() const = 0; /** * Set the field to be immutable, i. e. it can no longer be modified. * This is permanent, i.e. once done the field can onot be made mutable. @@ -1155,6 +1160,11 @@ public: */ virtual ~PVValueArray() {} + virtual ArrayConstPtr getArray() const + { + return std::tr1::static_pointer_cast(this->getField()); + } + std::ostream& dumpValue(std::ostream& o) const { const_svector v(this->view()); @@ -1216,6 +1226,11 @@ public: */ virtual ~PVValueArray() {} + virtual ArrayConstPtr getArray() const + { + return std::tr1::static_pointer_cast(structureArray); + } + virtual size_t getLength() const {return value.size();} virtual size_t getCapacity() const {return value.capacity();} @@ -1306,6 +1321,11 @@ public: */ virtual ~PVValueArray() {} + virtual ArrayConstPtr getArray() const + { + return std::tr1::static_pointer_cast(unionArray); + } + virtual size_t getLength() const {return value.size();} virtual size_t getCapacity() const {return value.capacity();} diff --git a/pvDataApp/pv/pvIntrospect.h b/pvDataApp/pv/pvIntrospect.h index a25b072..3bb839f 100644 --- a/pvDataApp/pv/pvIntrospect.h +++ b/pvDataApp/pv/pvIntrospect.h @@ -24,6 +24,7 @@ namespace epics { namespace pvData { class Field; class Scalar; +class Array; class ScalarArray; class Structure; class StructureArray; @@ -42,6 +43,10 @@ typedef std::vector FieldConstPtrArray; * typedef for a shared pointer to an immutable Scalar. */ typedef std::tr1::shared_ptr ScalarConstPtr; +/** + * typedef for a shared pointer to an immutable Array. + */ +typedef std::tr1::shared_ptr ArrayConstPtr; /** * typedef for a shared pointer to an immutable ScalarArray. */ @@ -314,10 +319,39 @@ private: friend class FieldCreate; }; +/** + * This class implements introspection object for Array. + */ +class epicsShareClass Array : public Field{ +public: + POINTER_DEFINITIONS(Array); + /** + * Destructor. + */ + virtual ~Array(); + typedef Array& reference; + typedef const Array& const_reference; + +/* fixed-size array support + // 0 not valid value, means undefined + std::size_t getMaximumCapacity() const; + + // 0 not valid value, means undefined + std::size_t getFixedLength() const; +*/ +protected: + /** + * Constructor + * @param fieldName The field type. + */ + Array(Type type); + +}; + /** * This class implements introspection object for field. */ -class epicsShareClass ScalarArray : public Field{ +class epicsShareClass ScalarArray : public Array{ public: POINTER_DEFINITIONS(ScalarArray); typedef ScalarArray& reference; @@ -332,7 +366,7 @@ public: * Get the scalarType for the elements. * @return the scalarType */ - ScalarType getElementType() const {return elementType;} + ScalarType getElementType() const {return elementType;} /** * Convert the scalarType to a string and add it to builder. * @param builder The string builder. @@ -365,7 +399,7 @@ private: /** * This class implements introspection object for a structureArray */ -class epicsShareClass StructureArray : public Field{ +class epicsShareClass StructureArray : public Array{ public: POINTER_DEFINITIONS(StructureArray); typedef StructureArray& reference; @@ -375,7 +409,7 @@ public: * Get the introspection interface for the array elements. * @return The introspection interface. */ - StructureConstPtr getStructure() const {return pstructure;} + StructureConstPtr getStructure() const {return pstructure;} /** * Convert the scalarType to a string and add it to builder. @@ -407,7 +441,7 @@ private: /** * This class implements introspection object for a unionArray */ -class epicsShareClass UnionArray : public Field{ +class epicsShareClass UnionArray : public Array{ public: POINTER_DEFINITIONS(UnionArray); typedef UnionArray& reference; @@ -417,7 +451,7 @@ public: * Get the introspection interface for the array elements. * @return The introspection interface. */ - UnionConstPtr getUnion() const {return punion;} + UnionConstPtr getUnion() const {return punion;} /** * Convert the scalarType to a string and add it to builder.