diff --git a/src/factory/FieldCreateFactory.cpp b/src/factory/FieldCreateFactory.cpp index b5e3d46..62ca0cf 100644 --- a/src/factory/FieldCreateFactory.cpp +++ b/src/factory/FieldCreateFactory.cpp @@ -25,6 +25,7 @@ #include #include #include +#include using std::tr1::static_pointer_cast; using std::size_t; @@ -102,6 +103,11 @@ Field::~Field() { } } +std::tr1::shared_ptr Field::build() const +{ + FieldConstPtr self(shared_from_this()); + return getPVDataCreate()->createPVField(self); +} std::ostream& operator<<(std::ostream& o, const Field& f) { @@ -172,6 +178,11 @@ void Scalar::deserialize(ByteBuffer* /*buffer*/, DeserializableControl* /*contro } +std::tr1::shared_ptr Scalar::build() const +{ + return getPVDataCreate()->createPVScalar(std::tr1::static_pointer_cast(shared_from_this())); +} + std::string BoundedString::getID() const @@ -338,6 +349,11 @@ void ScalarArray::deserialize(ByteBuffer* /*buffer*/, DeserializableControl* /*c throw std::runtime_error("not valid operation, use FieldCreate::deserialize instead"); } +std::tr1::shared_ptr ScalarArray::build() const +{ + return getPVDataCreate()->createPVScalarArray(std::tr1::static_pointer_cast(shared_from_this())); +} + BoundedScalarArray::~BoundedScalarArray() {} @@ -418,6 +434,11 @@ void StructureArray::deserialize(ByteBuffer* /*buffer*/, DeserializableControl* throw std::runtime_error("not valid operation, use FieldCreate::deserialize instead"); } +std::tr1::shared_ptr > > StructureArray::build() const +{ + return getPVDataCreate()->createPVStructureArray(std::tr1::static_pointer_cast(shared_from_this())); +} + UnionArray::UnionArray(UnionConstPtr const & _punion) : Array(unionArray),punion(_punion) { @@ -460,6 +481,11 @@ void UnionArray::deserialize(ByteBuffer* /*buffer*/, DeserializableControl* /*co throw std::runtime_error("not valid operation, use FieldCreate::deserialize instead"); } +std::tr1::shared_ptr > > UnionArray::build() const +{ + return getPVDataCreate()->createPVUnionArray(std::tr1::static_pointer_cast(shared_from_this())); +} + const string Structure::DEFAULT_ID = Structure::defaultId(); const string & Structure::defaultId() @@ -597,6 +623,11 @@ void Structure::deserialize(ByteBuffer* /*buffer*/, DeserializableControl* /*con throw std::runtime_error("not valid operation, use FieldCreate::deserialize instead"); } +std::tr1::shared_ptr Structure::build() const +{ + return getPVDataCreate()->createPVStructure(std::tr1::static_pointer_cast(shared_from_this())); +} + const string Union::DEFAULT_ID = Union::defaultId(); const string & Union::defaultId() @@ -795,6 +826,11 @@ void Union::deserialize(ByteBuffer* /*buffer*/, DeserializableControl* /*control throw std::runtime_error("not valid operation, use FieldCreate::deserialize instead"); } +std::tr1::shared_ptr Union::build() const +{ + return getPVDataCreate()->createPVUnion(std::tr1::static_pointer_cast(shared_from_this())); +} + FieldBuilder::FieldBuilder() :fieldCreate(getFieldCreate()) ,idSet(false) @@ -896,6 +932,19 @@ void FieldBuilder::reset() fields.clear(); } +FieldBuilderPtr FieldBuilder::begin() +{ + FieldBuilderPtr ret(new FieldBuilder); + return ret; +} + +FieldBuilderPtr FieldBuilder::begin(StructureConstPtr S) +{ + FieldBuilderPtr ret(new FieldBuilder(S.get())); + return ret; +} + + FieldBuilderPtr FieldBuilder::setId(string const & id) { this->id = id; diff --git a/src/pv/pvIntrospect.h b/src/pv/pvIntrospect.h index 9458571..8e177b4 100644 --- a/src/pv/pvIntrospect.h +++ b/src/pv/pvIntrospect.h @@ -118,6 +118,13 @@ class UnionArray; class BoundedString; +class PVField; +class PVScalar; +class PVScalarArray; +class PVStructure; +class PVUnion; +template class PVValueArray; + /** * typedef for a shared pointer to an immutable Field. */ @@ -341,6 +348,9 @@ public: */ virtual std::ostream& dump(std::ostream& o) const = 0; + //! Allocate a new instance + std::tr1::shared_ptr build() const; + protected: /** * Constructor @@ -387,6 +397,9 @@ public: virtual void serialize(ByteBuffer *buffer, SerializableControl *control) const OVERRIDE; virtual void deserialize(ByteBuffer *buffer, DeserializableControl *control) OVERRIDE FINAL; + + //! Allocate a new instance + std::tr1::shared_ptr build() const; protected: Scalar(ScalarType scalarType); @@ -492,6 +505,9 @@ public: virtual void serialize(ByteBuffer *buffer, SerializableControl *control) const OVERRIDE; virtual void deserialize(ByteBuffer *buffer, DeserializableControl *control) OVERRIDE FINAL; + + //! Allocate a new instance + std::tr1::shared_ptr build() const; virtual ~ScalarArray(); private: @@ -594,6 +610,9 @@ public: virtual void serialize(ByteBuffer *buffer, SerializableControl *control) const OVERRIDE FINAL; virtual void deserialize(ByteBuffer *buffer, DeserializableControl *control) OVERRIDE FINAL; + //! Allocate a new instance + std::tr1::shared_ptr > > build() const; + protected: /** * Constructor. @@ -635,6 +654,9 @@ public: virtual void serialize(ByteBuffer *buffer, SerializableControl *control) const OVERRIDE FINAL; virtual void deserialize(ByteBuffer *buffer, DeserializableControl *control) OVERRIDE FINAL; + //! Allocate a new instance + std::tr1::shared_ptr > > build() const; + protected: /** * Constructor. @@ -742,7 +764,10 @@ public: virtual void serialize(ByteBuffer *buffer, SerializableControl *control) const OVERRIDE FINAL; virtual void deserialize(ByteBuffer *buffer, DeserializableControl *control) OVERRIDE FINAL; - + + //! Allocate a new instance + std::tr1::shared_ptr build() const; + protected: Structure(StringArray const & fieldNames, FieldConstPtrArray const & fields, std::string const & id = defaultId()); private: @@ -877,6 +902,9 @@ public: virtual void serialize(ByteBuffer *buffer, SerializableControl *control) const OVERRIDE FINAL; virtual void deserialize(ByteBuffer *buffer, DeserializableControl *control) OVERRIDE FINAL; + + //! Allocate a new instance + std::tr1::shared_ptr build() const; protected: Union(); @@ -910,6 +938,11 @@ class epicsShareClass FieldBuilder : public std::tr1::enable_shared_from_this { public: + //! Create a new instance of in-line @c Field builder. + static FieldBuilderPtr begin(); + //! Create a new instance of in-line @c Field builder pre-initialized with and existing Structure + static FieldBuilderPtr begin(StructureConstPtr S); + /** * Set ID of an object to be created. * @param id id to be set.