Class Union

Inheritance Relationships

Base Type

Class Documentation

class Union : public epics::pvData::Field

This class implements introspection object for a union.

Public Types

typedef Union &reference
typedef const Union &const_reference

Public Functions

POINTER_DEFINITIONS(Union)
virtual ~Union()
inline std::size_t getNumberFields() const

Get the number of immediate subfields in the union.

Returns

The number of fields.

FieldConstPtr getField(std::string const &fieldName) const

Lookup Field by name

Parameters

fieldName – Member field name. May not contain ‘.’

Returns

NULL if no member by this name.

template<typename FT>
inline std::tr1::shared_ptr<const FT> getField(std::string const &fieldName) const

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

Parameters

fieldName – Member field name. May not contain ‘.’

Returns

NULL If no member by this name, or member exists, but has type other than FT.

inline FieldConstPtr getFieldT(std::string const &fieldName) const

Lookup Field by name

Parameters

fieldName – Member field name. May not contain ‘.’

Throws

std::runtime_error – If no member by this name

Returns

Field pointer (never NULL)

template<typename FT>
inline std::tr1::shared_ptr<const FT> getFieldT(std::string const &fieldName) const

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

Parameters

fieldName – Member field name. May not contain ‘.’

Throws

std::runtime_error – If no member by this name, or member exists, but has type other than FT.

Returns

Field pointer (never NULL)

inline FieldConstPtr getField(std::size_t index) const

Lookup Field by index, within this Union.

Parameters

index – Index of member in this union.

index>=0 && index<getNumberFields() 

Throws

std::out_of_range – If index >= getNumberFields()

Returns

Field pointer (never NULL)

template<typename FT>
inline std::tr1::shared_ptr<const FT> getField(std::size_t index) const

Lookup Field by index, within this Union.

Parameters

index – Index of member in this union.

index>=0 && index<getNumberFields() 

Throws

std::out_of_range – If index >= getNumberFields()

Returns

NULL if member is not a sub-class of FT

inline FieldConstPtr getFieldT(std::size_t index) const

Lookup Field by index, within this Union.

Parameters

index – Index of member in this union.

index>=0 && index<getNumberFields() 

Throws

std::out_of_range – If index >= getNumberFields()

Returns

Field pointer (never NULL)

template<typename FT>
inline std::tr1::shared_ptr<const FT> getFieldT(std::size_t index) const

Lookup Field by index, within this Structure.

Parameters

index – Index of member in this structure.

index>=0 && index<getNumberFields() 

Throws
  • std::out_of_range – If index >= getNumberFields()

  • std::runtime_error – If member is not a sub-class of FT

Returns

Field pointer (never NULL)

std::size_t 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 union.

inline FieldConstPtrArray const &getFields() const

Get the fields in the union.

Returns

The array of fields.

inline StringArray const &getFieldNames() const

Get the names of the fields in the union.

Returns

The array of fieldNames.

inline std::string getFieldName(std::size_t fieldIndex) const

Get the name of the field with the specified index;

Parameters

fieldIndex – The index of the desired field.

Returns

The fieldName.

inline bool isVariant() const

Check if this union is variant union (aka any type).

Returns

true if this union is variant union, otherwise false.

int32 guess(Type t, ScalarType s) const

Attempt to find an suitable member to stored the specified type.

Returned index is guerenteed to by of specified Type (either scalar or scalarArray). Provided ScalarType is taken as a hint.

Parameters
  • t – Must be either scalar or scalarArray

  • s – The preferred ScalarType

Returns

A valid index or -1

virtual std::string getID() const

Get the identification string.

Returns

The identification string, can be empty.

virtual std::ostream &dump(std::ostream &o) const

Puts the string representation to the stream.

Parameters

o – output stream.

Returns

The output stream.

virtual void serialize(ByteBuffer *buffer, SerializableControl *control) const

Serialize field into given buffer.

Parameters
  • buffer – serialization buffer.

  • flusher – flush interface.

virtual void deserialize(ByteBuffer *buffer, DeserializableControl *control)

Deserialize buffer.

Parameters
  • buffer – serialization buffer.

  • flusher – deserialization control.

std::tr1::shared_ptr<PVUnion> build() const

Allocate a new instance

Version

Added after 7.0.0

Public Static Functions

static const std::string &defaultId()

Get the default union ID.

Returns

The default union ID.

static const std::string &anyId()

Get the default variant union ID.

Returns

The default variant union ID.

Public Static Attributes

static const std::string DEFAULT_ID = Union::defaultId()

Default union ID.

static const std::string ANY_ID = Union::anyId()

Default variant union ID.

Protected Functions

Union()
Union(StringArray const &fieldNames, FieldConstPtrArray const &fields, std::string const &id = defaultId())