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

This class implements introspection object for a structure. More...

#include "pvIntrospect.h"

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

Public Types

typedef Structurereference
 
typedef const Structureconst_reference
 
- Public Types inherited from epics::pvData::Field
enum  { isField =1 }
 

Public Member Functions

 POINTER_DEFINITIONS (Structure)
 
virtual ~Structure ()
 
std::size_t getNumberFields () const
 
FieldConstPtr getField (std::string const &fieldName) const
 
template<typename FT >
std::tr1::shared_ptr< const FT > getField (std::string const &fieldName) const
 
FieldConstPtr getFieldT (std::string const &fieldName) const
 
template<typename FT >
std::tr1::shared_ptr< const FT > getFieldT (std::string const &fieldName) const
 
const FieldConstPtrgetField (std::size_t index) const
 
template<typename FT >
std::tr1::shared_ptr< const FT > getField (std::size_t index) const
 
FieldConstPtr getFieldT (std::size_t index) const
 
template<typename FT >
std::tr1::shared_ptr< const FT > getFieldT (std::size_t index) const
 
std::size_t getFieldIndex (std::string const &fieldName) const
 
FieldConstPtrArray const & getFields () const
 
StringArray const & getFieldNames () const
 
const std::string & getFieldName (std::size_t fieldIndex) const
 
virtual std::string getID () const OVERRIDE FINAL
 
virtual std::ostream & dump (std::ostream &o) const OVERRIDE FINAL
 
virtual void serialize (ByteBuffer *buffer, SerializableControl *control) const OVERRIDE FINAL
 
virtual void deserialize (ByteBuffer *buffer, DeserializableControl *control) OVERRIDE FINAL
 
std::tr1::shared_ptr< PVStructurebuild () const
 
- Public Member Functions inherited from epics::pvData::Field
 POINTER_DEFINITIONS (Field)
 
virtual ~Field ()
 
Type getType () const
 
std::tr1::shared_ptr< PVFieldbuild () const
 
- Public Member Functions inherited from epics::pvData::Serializable
virtual ~Serializable ()
 

Static Public Member Functions

static const std::string & defaultId ()
 

Static Public Attributes

static const std::string DEFAULT_ID = Structure::defaultId()
 
- Static Public Attributes inherited from epics::pvData::Field
static size_t num_instances
 

Protected Member Functions

 Structure (StringArray const &fieldNames, FieldConstPtrArray const &fields, std::string const &id=defaultId())
 
- Protected Member Functions inherited from epics::pvData::Field
 Field (Type type)
 
void cacheCleanup ()
 

Friends

class FieldCreate
 
class Union
 

Detailed Description

This class implements introspection object for a structure.

Definition at line 697 of file pvIntrospect.h.

Member Typedef Documentation

Definition at line 714 of file pvIntrospect.h.

Definition at line 713 of file pvIntrospect.h.

Constructor & Destructor Documentation

epics::pvData::Structure::~Structure ( )
virtual

Definition at line 550 of file FieldCreateFactory.cpp.

551 {
552  cacheCleanup();
553 }
epics::pvData::Structure::Structure ( StringArray const &  fieldNames,
FieldConstPtrArray const &  fields,
std::string const &  id = defaultId() 
)
protected

Definition at line 514 of file FieldCreateFactory.cpp.

518 : Field(structure),
519  fieldNames(fieldNames),
520  fields(infields),
521  id(inid)
522 {
523  if(inid.empty()) {
524  THROW_EXCEPTION2(std::invalid_argument, "Can't construct Structure, id is empty string");
525  }
526  if(fieldNames.size()!=fields.size()) {
527  THROW_EXCEPTION2(std::invalid_argument, "Can't construct Structure, fieldNames.size()!=fields.size()");
528  }
529  size_t number = fields.size();
530  for(size_t i=0; i<number; i++) {
531  const string& name = fieldNames[i];
532  if(name.empty()) {
533  THROW_EXCEPTION2(std::invalid_argument, "Can't construct Structure, empty string in fieldNames");
534  }
535  if(fields[i].get()==NULL)
536  THROW_EXCEPTION2(std::invalid_argument, "Can't construct Structure, NULL in fields");
537  // look for duplicates
538  for(size_t j=i+1; j<number; j++) {
539  string otherName = fieldNames[j];
540  int result = name.compare(otherName);
541  if(result==0) {
542  string message("Can't construct Structure, duplicate fieldName ");
543  message += name;
544  THROW_EXCEPTION2(std::invalid_argument, message);
545  }
546  }
547  }
548 }
pvac::PutEvent result
Definition: clientSync.cpp:117
#define THROW_EXCEPTION2(TYPE, MSG)
int i
Definition: scan.c:967
#define NULL
Definition: catime.c:38

Member Function Documentation

std::tr1::shared_ptr< PVStructure > epics::pvData::Structure::build ( ) const

Allocate a new instance

Version
Added after 7.0.0

Definition at line 661 of file FieldCreateFactory.cpp.

662 {
663  return getPVDataCreate()->createPVStructure(std::tr1::static_pointer_cast<const Structure>(shared_from_this()));
664 }
FORCE_INLINE const PVDataCreatePtr & getPVDataCreate()
Definition: pvData.h:1648
const string & epics::pvData::Structure::defaultId ( )
static

Get the default structure ID.

Returns
The default structure ID.

Definition at line 508 of file FieldCreateFactory.cpp.

509 {
510  static const string id = "structure";
511  return id;
512 }
void epics::pvData::Structure::deserialize ( ByteBuffer buffer,
DeserializableControl flusher 
)
virtual

Deserialize buffer.

Parameters
bufferserialization buffer.
flusherdeserialization control.

Implements epics::pvData::Serializable.

Definition at line 657 of file FieldCreateFactory.cpp.

657  {
658  throw std::runtime_error("not valid operation, use FieldCreate::deserialize instead");
659 }
std::ostream & epics::pvData::Structure::dump ( std::ostream &  o) const
virtual

Puts the string representation to the stream.

Parameters
ooutput stream.
Returns
The output stream.

Implements epics::pvData::Field.

Definition at line 595 of file FieldCreateFactory.cpp.

596 {
597  o << format::indent() << getID() << std::endl;
598  {
599  format::indent_scope s(o);
600  dumpFields(o);
601  }
602  return o;
603 }
virtual std::string getID() const OVERRIDE FINAL
FieldConstPtr epics::pvData::Structure::getField ( std::string const &  fieldName) const

Lookup Field by name

Parameters
fieldNameMember field name. May not contain '.'
Returns
NULL if no member by this name.
template<typename FT >
std::tr1::shared_ptr<const FT> epics::pvData::Structure::getField ( std::string const &  fieldName) const
inline

Lookup Field by name and cast to Field sub-class.

Parameters
fieldNameMember field name. May not contain '.'
Returns
NULL If no member by this name, or member exists, but has type other than FT.

Definition at line 734 of file pvIntrospect.h.

735  {
736  STATIC_ASSERT(FT::isField); // only allow cast from Field sub-class
737  return std::tr1::dynamic_pointer_cast<const FT>(getField(fieldName));
738  }
FieldConstPtr getField(std::string const &fieldName) const
#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
const FieldConstPtr& epics::pvData::Structure::getField ( std::size_t  index) const
inline

Lookup Field by index, within this Structure.

Parameters
indexIndex of member in this structure.
index>=0 && index<getNumberFields()
Returns
Field pointer (never NULL)
Exceptions
std::out_of_rangeIf index >= getNumberFields()

Definition at line 772 of file pvIntrospect.h.

772 {return fields.at(index);}
template<typename FT >
std::tr1::shared_ptr<const FT> epics::pvData::Structure::getField ( std::size_t  index) const
inline

Lookup Field by index, within this Structure.

Parameters
indexIndex of member in this structure.
index>=0 && index<getNumberFields()
Returns
NULL if member is not a sub-class of FT
Exceptions
std::out_of_rangeIf index >= getNumberFields()

Definition at line 780 of file pvIntrospect.h.

781  {
782  STATIC_ASSERT(FT::isField); // only allow cast from Field sub-class
783  return std::tr1::dynamic_pointer_cast<const FT>(getField(index));
784  }
FieldConstPtr getField(std::string const &fieldName) const
#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
size_t epics::pvData::Structure::getFieldIndex ( std::string const &  fieldName) const

Get the field index for the specified fieldName.

Returns
The introspection interface. This will be -1 if the field is not in the structure.

Definition at line 570 of file FieldCreateFactory.cpp.

570  {
571  size_t numberFields = fields.size();
572  for(size_t i=0; i<numberFields; i++) {
573  FieldConstPtr pfield = fields[i];
574  int result = fieldName.compare(fieldNames[i]);
575  if(result==0) return i;
576  }
577  return -1;
578 }
pvac::PutEvent result
Definition: clientSync.cpp:117
int i
Definition: scan.c:967
std::tr1::shared_ptr< const Field > FieldConstPtr
Definition: pvIntrospect.h:137
const std::string& epics::pvData::Structure::getFieldName ( std::size_t  fieldIndex) const
inline

Get the name of the field with the specified index;

Parameters
fieldIndexThe index of the desired field.
Returns
The fieldName.

Definition at line 834 of file pvIntrospect.h.

834 {return fieldNames.at(fieldIndex);}
StringArray const& epics::pvData::Structure::getFieldNames ( ) const
inline

Get the names of the fields in the structure.

Returns
The array of fieldNames.

Definition at line 828 of file pvIntrospect.h.

828 {return fieldNames;}
FieldConstPtrArray const& epics::pvData::Structure::getFields ( ) const
inline

Get the fields in the structure.

Returns
The array of fields.

Definition at line 823 of file pvIntrospect.h.

823 {return fields;}
FieldConstPtr epics::pvData::Structure::getFieldT ( std::string const &  fieldName) const
inline

Lookup Field by name

Parameters
fieldNameMember field name. May not contain '.'
Returns
Field pointer (never NULL)
Exceptions
std::runtime_errorIf no member by this name

Definition at line 746 of file pvIntrospect.h.

746 {return getFieldImpl(fieldName, true);};
template<typename FT >
std::tr1::shared_ptr<const FT> epics::pvData::Structure::getFieldT ( std::string const &  fieldName) const
inline

Lookup Field by name and cast to Field sub-class.

Parameters
fieldNameMember field name. May not contain '.'
Returns
Field pointer (never NULL)
Exceptions
std::runtime_errorIf no member by this name, or member exists, but has type other than FT.

Definition at line 754 of file pvIntrospect.h.

755  {
756  STATIC_ASSERT(FT::isField); // only allow cast from Field sub-class
757  std::tr1::shared_ptr<const FT> result(
758  std::tr1::dynamic_pointer_cast<const FT>(getFieldT(fieldName))
759  );
760 
761  if (!result)
762  throw std::runtime_error("Wrong Field type");
763 
764  return result;
765  }
pvac::PutEvent result
Definition: clientSync.cpp:117
FieldConstPtr getFieldT(std::string const &fieldName) const
Definition: pvIntrospect.h:746
#define STATIC_ASSERT(expr)
Declare a condition that should be true at compile-time.
Definition: epicsAssert.h:86
FieldConstPtr epics::pvData::Structure::getFieldT ( std::size_t  index) const
inline

Lookup Field by index, within this Structure.

Parameters
indexIndex of member in this structure.
index>=0 && index<getNumberFields()
Returns
Field pointer (never NULL)
Exceptions
std::out_of_rangeIf index >= getNumberFields()

Definition at line 791 of file pvIntrospect.h.

791 {return fields.at(index);}
template<typename FT >
std::tr1::shared_ptr<const FT> epics::pvData::Structure::getFieldT ( std::size_t  index) const
inline

Lookup Field by index, within this Structure.

Parameters
indexIndex of member in this structure.
index>=0 && index<getNumberFields()
Returns
Field pointer (never NULL)
Exceptions
std::out_of_rangeIf index >= getNumberFields()
std::runtime_errorIf member is not a sub-class of FT

Definition at line 800 of file pvIntrospect.h.

801  {
802  STATIC_ASSERT(FT::isField); // only allow cast from Field sub-class
803  std::tr1::shared_ptr<const FT> result(
804  std::tr1::dynamic_pointer_cast<const FT>(getFieldT(index))
805  );
806 
807  if (!result)
808  throw std::runtime_error("Wrong Field type");
809 
810  return result;
811  }
pvac::PutEvent result
Definition: clientSync.cpp:117
FieldConstPtr getFieldT(std::string const &fieldName) const
Definition: pvIntrospect.h:746
#define STATIC_ASSERT(expr)
Declare a condition that should be true at compile-time.
Definition: epicsAssert.h:86
string epics::pvData::Structure::getID ( ) const
virtual

Get the identification string.

Returns
The identification string, can be empty.

Implements epics::pvData::Field.

Definition at line 556 of file FieldCreateFactory.cpp.

557 {
558  return id;
559 }
std::size_t epics::pvData::Structure::getNumberFields ( ) const
inline

Get the number of immediate subfields in the structure.

Returns
The number of fields.

Definition at line 720 of file pvIntrospect.h.

720 {return fieldNames.size();}
epics::pvData::Structure::POINTER_DEFINITIONS ( Structure  )
void epics::pvData::Structure::serialize ( ByteBuffer buffer,
SerializableControl flusher 
) const
virtual

Serialize field into given buffer.

Parameters
bufferserialization buffer.
flusherflush interface.

Implements epics::pvData::Serializable.

Definition at line 651 of file FieldCreateFactory.cpp.

651  {
652  control->ensureBuffer(1);
653  buffer->putByte((int8)0x80);
654  serializeStructureField(this, buffer, control);
655 }
int8_t int8
Definition: pvType.h:75

Friends And Related Function Documentation

friend class FieldCreate
friend

Definition at line 857 of file pvIntrospect.h.

friend class Union
friend

Definition at line 858 of file pvIntrospect.h.

Member Data Documentation

const string epics::pvData::Structure::DEFAULT_ID = Structure::defaultId()
static

Default structure ID.

Definition at line 704 of file pvIntrospect.h.


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