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

This is a singleton class for creating introspection interfaces. More...

#include "pvIntrospect.h"

Classes

struct  Helper
 

Public Member Functions

FieldBuilderPtr createFieldBuilder () const
 
FieldBuilderPtr createFieldBuilder (StructureConstPtr S) const
 
ScalarConstPtr createScalar (ScalarType scalarType) const
 
BoundedStringConstPtr createBoundedString (std::size_t maxLength) const PVD_DEPRECATED_52
 
ScalarArrayConstPtr createScalarArray (ScalarType elementType) const
 
ScalarArrayConstPtr createFixedScalarArray (ScalarType elementType, std::size_t size) const PVD_DEPRECATED_52
 
ScalarArrayConstPtr createBoundedScalarArray (ScalarType elementType, std::size_t bound) const PVD_DEPRECATED_52
 
StructureArrayConstPtr createStructureArray (StructureConstPtr const &structure) const
 
StructureConstPtr createStructure () const
 
StructureConstPtr createStructure (StringArray const &fieldNames, FieldConstPtrArray const &fields) const
 
StructureConstPtr createStructure (std::string const &id, StringArray const &fieldNames, FieldConstPtrArray const &fields) const
 
UnionArrayConstPtr createUnionArray (UnionConstPtr const &punion) const
 
UnionArrayConstPtr createVariantUnionArray () const
 
UnionConstPtr createVariantUnion () const
 
UnionConstPtr createUnion (StringArray const &fieldNames, FieldConstPtrArray const &fields) const
 
UnionConstPtr createUnion (std::string const &id, StringArray const &fieldNames, FieldConstPtrArray const &fields) const
 
StructureConstPtr appendField (StructureConstPtr const &structure, std::string const &fieldName, FieldConstPtr const &field) const
 
StructureConstPtr appendFields (StructureConstPtr const &structure, StringArray const &fieldNames, FieldConstPtrArray const &fields) const
 
FieldConstPtr deserialize (ByteBuffer *buffer, DeserializableControl *control) const
 

Static Public Member Functions

static const FieldCreatePtrgetFieldCreate ()
 

Friends

struct detail::field_factory
 
class Field
 

Detailed Description

This is a singleton class for creating introspection interfaces.

Definition at line 1250 of file pvIntrospect.h.

Member Function Documentation

StructureConstPtr epics::pvData::FieldCreate::appendField ( StructureConstPtr const &  structure,
std::string const &  fieldName,
FieldConstPtr const &  field 
) const

Append a field to a structure.

Parameters
structureThe structure to which the field is appended.
fieldNameThe name of the field.
fieldThe field.
Returns
a Structure interface for the newly created object.

Definition at line 1395 of file FieldCreateFactory.cpp.

1399 {
1400  StringArray const & oldNames = structure->getFieldNames();
1401  FieldConstPtrArray const & oldFields = structure->getFields();
1402  size_t oldLen = oldNames.size();
1403  StringArray newNames(oldLen+1);
1404  FieldConstPtrArray newFields(oldLen+1);
1405  for(size_t i = 0; i<oldLen; i++) {
1406  newNames[i] = oldNames[i];
1407  newFields[i] = oldFields[i];
1408  }
1409  newNames[oldLen] = fieldName;
1410  newFields[oldLen] = field;
1411  return createStructure(structure->getID(),newNames,newFields);
1412 }
StructureConstPtr createStructure() const
int i
Definition: scan.c:967
std::vector< FieldConstPtr > FieldConstPtrArray
Definition: pvIntrospect.h:146
std::vector< std::string > StringArray
Definition: pvType.h:110
StructureConstPtr epics::pvData::FieldCreate::appendFields ( StructureConstPtr const &  structure,
StringArray const &  fieldNames,
FieldConstPtrArray const &  fields 
) const

Append fields to a structure.

Parameters
structureThe structure to which the fields appended.
fieldNamesThe names of the fields.
fieldsThe fields.
Returns
a Structure interface for the newly created object.

Definition at line 1414 of file FieldCreateFactory.cpp.

1418 {
1419  validateFieldNames(fieldNames);
1420  StringArray const & oldNames = structure->getFieldNames();
1421  FieldConstPtrArray const & oldFields = structure->getFields();
1422  size_t oldLen = oldNames.size();
1423  size_t extra = fieldNames.size();
1424  StringArray newNames(oldLen+extra);
1425  FieldConstPtrArray newFields(oldLen+extra);
1426  for(size_t i = 0; i<oldLen; i++) {
1427  newNames[i] = oldNames[i];
1428  newFields[i] = oldFields[i];
1429  }
1430  for(size_t i = 0; i<extra; i++) {
1431  newNames[oldLen +i] = fieldNames[i];
1432  newFields[oldLen +i] = fields[i];
1433  }
1434  return createStructure(structure->getID(),newNames,newFields);
1435 }
StructureConstPtr createStructure() const
int i
Definition: scan.c:967
std::vector< FieldConstPtr > FieldConstPtrArray
Definition: pvIntrospect.h:146
std::vector< std::string > StringArray
Definition: pvType.h:110
ScalarArrayConstPtr epics::pvData::FieldCreate::createBoundedScalarArray ( ScalarType  elementType,
std::size_t  bound 
) const

Create an Array field, bounded size array.

Parameters
elementTypeThe ScalarType for array elements
boundArray maximum capacity.
Returns
An Array Interface for the newly created object.

Definition at line 1266 of file FieldCreateFactory.cpp.

1267 {
1268  if(elementType<0 || elementType>MAX_SCALAR_TYPE) {
1269  std::ostringstream strm("Can't construct bounded ScalarArray from invalid ScalarType ");
1270  strm << elementType;
1271  THROW_EXCEPTION2(std::invalid_argument, strm.str());
1272  }
1273 
1274  std::tr1::shared_ptr<ScalarArray> s(new BoundedScalarArray(elementType, size));
1275  Helper::cache(this, s);
1276  return s;
1277 }
#define THROW_EXCEPTION2(TYPE, MSG)
#define MAX_SCALAR_TYPE
Definition: pvIntrospect.h:280
static void cache(const FieldCreate *create, std::tr1::shared_ptr< FLD > &ent)
BoundedStringConstPtr epics::pvData::FieldCreate::createBoundedString ( std::size_t  maxLength) const

Create a BoundedString.

Parameters
maxLengtha string maximum length.
Returns
a BoundedString interface for the newly created object.
Exceptions
IllegalArgumentExceptionif maxLength == 0.

Definition at line 1235 of file FieldCreateFactory.cpp.

1236 {
1237  std::tr1::shared_ptr<BoundedString> s(new BoundedString(maxLength));
1238  Helper::cache(this, s);
1239  return s;
1240 }
static void cache(const FieldCreate *create, std::tr1::shared_ptr< FLD > &ent)
FieldBuilderPtr epics::pvData::FieldCreate::createFieldBuilder ( ) const

Create a new instance of in-line Field builder.

Returns
a new instance of a FieldBuilder.

Definition at line 1213 of file FieldCreateFactory.cpp.

1214 {
1215  return FieldBuilderPtr(new FieldBuilder());
1216 }
std::tr1::shared_ptr< FieldBuilder > FieldBuilderPtr
FieldBuilderPtr epics::pvData::FieldCreate::createFieldBuilder ( StructureConstPtr  S) const

Create a new instance of in-line Field builder pre-initialized with and existing Structure

Returns
a new instance of a FieldBuilder.

Definition at line 1218 of file FieldCreateFactory.cpp.

1219 {
1220  FieldBuilderPtr ret(new FieldBuilder(S.get()));
1221  return ret;
1222 }
std::tr1::shared_ptr< FieldBuilder > FieldBuilderPtr
ScalarArrayConstPtr epics::pvData::FieldCreate::createFixedScalarArray ( ScalarType  elementType,
std::size_t  size 
) const

Definition at line 1253 of file FieldCreateFactory.cpp.

1254 {
1255  if(elementType<0 || elementType>MAX_SCALAR_TYPE) {
1256  std::ostringstream strm("Can't construct fixed ScalarArray from invalid ScalarType ");
1257  strm << elementType;
1258  THROW_EXCEPTION2(std::invalid_argument, strm.str());
1259  }
1260 
1261  std::tr1::shared_ptr<ScalarArray> s(new FixedScalarArray(elementType, size));
1262  Helper::cache(this, s);
1263  return s;
1264 }
#define THROW_EXCEPTION2(TYPE, MSG)
#define MAX_SCALAR_TYPE
Definition: pvIntrospect.h:280
static void cache(const FieldCreate *create, std::tr1::shared_ptr< FLD > &ent)
ScalarConstPtr epics::pvData::FieldCreate::createScalar ( ScalarType  scalarType) const

Create a ScalarField.

Parameters
scalarTypeThe scalar type.
Returns
a Scalar interface for the newly created object.
Exceptions
IllegalArgumentExceptionif an illegal type is specified.

Definition at line 1224 of file FieldCreateFactory.cpp.

1225 {
1226  if(scalarType<0 || scalarType>MAX_SCALAR_TYPE) {
1227  std::ostringstream strm("Can't construct Scalar from invalid ScalarType ");
1228  strm << scalarType;
1229  THROW_EXCEPTION2(std::invalid_argument, strm.str());
1230  }
1231 
1232  return scalars[scalarType];
1233 }
#define THROW_EXCEPTION2(TYPE, MSG)
#define MAX_SCALAR_TYPE
Definition: pvIntrospect.h:280
ScalarArrayConstPtr epics::pvData::FieldCreate::createScalarArray ( ScalarType  elementType) const

Create an Array field, variable size array.

Parameters
elementTypeThe ScalarType for array elements
Returns
An Array Interface for the newly created object.

Definition at line 1242 of file FieldCreateFactory.cpp.

1243 {
1244  if(elementType<0 || elementType>MAX_SCALAR_TYPE) {
1245  std::ostringstream strm("Can't construct ScalarArray from invalid ScalarType ");
1246  strm << elementType;
1247  THROW_EXCEPTION2(std::invalid_argument, strm.str());
1248  }
1249 
1250  return scalarArrays[elementType];
1251 }
#define THROW_EXCEPTION2(TYPE, MSG)
#define MAX_SCALAR_TYPE
Definition: pvIntrospect.h:280
StructureConstPtr epics::pvData::FieldCreate::createStructure ( ) const

Create a Structure field.

Returns
a Structure interface for the newly created object.

Definition at line 1279 of file FieldCreateFactory.cpp.

1280 {
1281  StringArray fieldNames;
1282  FieldConstPtrArray fields;
1283  return createStructure(fieldNames,fields);
1284 }
StructureConstPtr createStructure() const
std::vector< FieldConstPtr > FieldConstPtrArray
Definition: pvIntrospect.h:146
std::vector< std::string > StringArray
Definition: pvType.h:110
StructureConstPtr epics::pvData::FieldCreate::createStructure ( StringArray const &  fieldNames,
FieldConstPtrArray const &  fields 
) const

Create a Structure field.

Parameters
fieldNamesthe names of the fields for the structure.
fieldsThe array of Field objects for the structure.
Returns
a Structure interface for the newly created object.

Definition at line 1329 of file FieldCreateFactory.cpp.

1331 {
1332  validateFieldNames(fieldNames);
1333  std::tr1::shared_ptr<Structure> sp(new Structure(fieldNames,fields));
1334  Helper::cache(this, sp);
1335  return sp;
1336 }
static void cache(const FieldCreate *create, std::tr1::shared_ptr< FLD > &ent)
StructureConstPtr epics::pvData::FieldCreate::createStructure ( std::string const &  id,
StringArray const &  fieldNames,
FieldConstPtrArray const &  fields 
) const

Create a Structure field with identification string.

Parameters
idThe identification string for the structure.
fieldNamesthe names of the fields for the structure.
fieldsThe array of Field objects for the structure.
Returns
a Structure interface for the newly created object.
StructureArrayConstPtr epics::pvData::FieldCreate::createStructureArray ( StructureConstPtr const &  structure) const

Create an Array field that is has element type Structure

Parameters
structureThe Structure for each array element.
Returns
An Array Interface for the newly created object.

Definition at line 1349 of file FieldCreateFactory.cpp.

1351 {
1352  std::tr1::shared_ptr<StructureArray> sp(new StructureArray(structure));
1353  Helper::cache(this, sp);
1354  return sp;
1355 }
static void cache(const FieldCreate *create, std::tr1::shared_ptr< FLD > &ent)
UnionConstPtr epics::pvData::FieldCreate::createUnion ( StringArray const &  fieldNames,
FieldConstPtrArray const &  fields 
) const

Create a Union field.

Parameters
fieldNamesthe names of the fields for the union.
fieldsThe Field for each fields for the union.
Returns
a Union interface for the newly created object.

Definition at line 1357 of file FieldCreateFactory.cpp.

1359 {
1360  validateFieldNames(fieldNames);
1361  std::tr1::shared_ptr<Union> sp(new Union(fieldNames,fields));
1362  Helper::cache(this, sp);
1363  return sp;
1364 }
static void cache(const FieldCreate *create, std::tr1::shared_ptr< FLD > &ent)
UnionConstPtr epics::pvData::FieldCreate::createUnion ( std::string const &  id,
StringArray const &  fieldNames,
FieldConstPtrArray const &  fields 
) const

Create a Union field with identification string.

Parameters
idThe identification string for the union.
fieldNamesthe names of the fields for the union.
fieldsThe array of Field objects for the union.
Returns
a Union interface for the newly created object.
UnionArrayConstPtr epics::pvData::FieldCreate::createUnionArray ( UnionConstPtr const &  punion) const

Create an Array field that is has element type Union

Parameters
punionThe Union for each array element.
Returns
An Array Interface for the newly created object.

Definition at line 1382 of file FieldCreateFactory.cpp.

1384 {
1385  std::tr1::shared_ptr<UnionArray> sp(new UnionArray(punion));
1386  Helper::cache(this, sp);
1387  return sp;
1388 }
static void cache(const FieldCreate *create, std::tr1::shared_ptr< FLD > &ent)
UnionConstPtr epics::pvData::FieldCreate::createVariantUnion ( ) const

Create a variant Union (aka any type) field.

Returns
a Union interface for the newly created object.

Definition at line 1377 of file FieldCreateFactory.cpp.

1378 {
1379  return variantUnion;
1380 }
UnionArrayConstPtr epics::pvData::FieldCreate::createVariantUnionArray ( ) const

Create a variant UnionArray (aka any type) field.

Returns
a UnionArray interface for the newly created object.

Definition at line 1390 of file FieldCreateFactory.cpp.

1391 {
1392  return variantUnionArray;
1393 }
FieldConstPtr epics::pvData::FieldCreate::deserialize ( ByteBuffer buffer,
DeserializableControl control 
) const

Deserialize Field instance from given byte buffer.

Parameters
bufferBuffer containing serialized Field instance.
controlDeserialization control instance.
Returns
a deserialized Field instance.

Definition at line 1474 of file FieldCreateFactory.cpp.

1475 {
1476  control->ensureData(1);
1477  int8 code = buffer->getByte();
1478  if (code == -1)
1479  return FieldConstPtr();
1480 
1481  int typeCode = code & 0xE7;
1482  int scalarOrArray = code & 0x18;
1483  bool notArray = (scalarOrArray == 0);
1484  if (notArray)
1485  {
1486  if (typeCode < 0x80)
1487  {
1488  // Type type = Type.scalar;
1489  int scalarType = decodeScalar(code);
1490  if (scalarType == -1)
1491  throw std::invalid_argument("invalid scalar type encoding");
1492  return scalars[scalarType];
1493  }
1494  else if (typeCode == 0x80)
1495  {
1496  // Type type = Type.structure;
1497  return deserializeStructureField(this, buffer, control);
1498  }
1499  else if (typeCode == 0x81)
1500  {
1501  // Type type = Type.union;
1502  return deserializeUnionField(this, buffer, control);
1503  }
1504  else if (typeCode == 0x82)
1505  {
1506  // Type type = Type.union; variant union (aka any type)
1507  return variantUnion;
1508  }
1509  else if (typeCode == 0x83)
1510  {
1511  // TODO cache?
1512  // bounded string
1513 
1514  size_t size = SerializeHelper::readSize(buffer, control);
1515 
1516  std::tr1::shared_ptr<Field> sp(
1517  new BoundedString(size));
1518  Helper::cache(this, sp);
1519  return sp;
1520  }
1521  else
1522  throw std::invalid_argument("invalid type encoding");
1523  }
1524  else // array
1525  {
1526  bool isVariable = (scalarOrArray == 0x08);
1527  // bounded == 0x10;
1528  bool isFixed = (scalarOrArray == 0x18);
1529 
1530  size_t size = (isVariable ? 0 : SerializeHelper::readSize(buffer, control));
1531 
1532  if (typeCode < 0x80)
1533  {
1534  // Type type = Type.scalarArray;
1535  int scalarType = decodeScalar(code);
1536  if (scalarType == -1)
1537  throw std::invalid_argument("invalid scalarArray type encoding");
1538  if (isVariable)
1539  return scalarArrays[scalarType];
1540  else if (isFixed)
1541  {
1542  // TODO use std::make_shared
1543  std::tr1::shared_ptr<Field> sp(
1544  new FixedScalarArray(static_cast<epics::pvData::ScalarType>(scalarType), size));
1545  Helper::cache(this, sp);
1546  return sp;
1547  }
1548  else
1549  {
1550  // TODO use std::make_shared
1551  std::tr1::shared_ptr<Field> sp(
1552  new BoundedScalarArray(static_cast<epics::pvData::ScalarType>(scalarType), size));
1553  Helper::cache(this, sp);
1554  return sp;
1555  }
1556  }
1557  else if (typeCode == 0x80)
1558  {
1559  // TODO fixed and bounded array support
1560  if (!isVariable)
1561  throw std::invalid_argument("fixed and bounded structure array not supported");
1562 
1563  // Type type = Type.structureArray;
1564  StructureConstPtr elementStructure = std::tr1::static_pointer_cast<const Structure>(control->cachedDeserialize(buffer));
1565  // TODO use std::make_shared
1566  std::tr1::shared_ptr<Field> sp(new StructureArray(elementStructure));
1567  Helper::cache(this, sp);
1568  return sp;
1569  }
1570  else if (typeCode == 0x81)
1571  {
1572  // TODO fixed and bounded array support
1573  if (!isVariable)
1574  throw std::invalid_argument("fixed and bounded structure array not supported");
1575 
1576  // Type type = Type.unionArray;
1577  UnionConstPtr elementUnion = std::tr1::static_pointer_cast<const Union>(control->cachedDeserialize(buffer));
1578  // TODO use std::make_shared
1579  std::tr1::shared_ptr<Field> sp(new UnionArray(elementUnion));
1580  Helper::cache(this, sp);
1581  return sp;
1582  }
1583  else if (typeCode == 0x82)
1584  {
1585  // TODO fixed and bounded array support
1586  if (!isVariable)
1587  throw std::invalid_argument("fixed and bounded structure array not supported");
1588 
1589  // Type type = Type.unionArray; variant union (aka any type)
1590  return variantUnionArray;
1591  }
1592  else
1593  throw std::invalid_argument("invalid type encoding");
1594  }
1595 }
int8_t int8
Definition: pvType.h:75
shared_ptr< T > static_pointer_cast(shared_ptr< U > const &r) BOOST_NOEXCEPT
Definition: shared_ptr.hpp:788
std::tr1::shared_ptr< const Structure > StructureConstPtr
Definition: pvIntrospect.h:162
static std::size_t readSize(ByteBuffer *buffer, DeserializableControl *control)
std::tr1::shared_ptr< const Union > UnionConstPtr
Definition: pvIntrospect.h:170
static void cache(const FieldCreate *create, std::tr1::shared_ptr< FLD > &ent)
std::tr1::shared_ptr< const Field > FieldConstPtr
Definition: pvIntrospect.h:137
const FieldCreatePtr & epics::pvData::FieldCreate::getFieldCreate ( )
static

Definition at line 1619 of file FieldCreateFactory.cpp.

1620 {
1621  epicsThreadOnce(&field_factory_once, &field_factory_init, 0);
1622  if(!field_factory_s->fieldCreate)
1623  throw std::logic_error("getFieldCreate() not initialized");
1624  return field_factory_s->fieldCreate;
1625 }
LIBCOM_API void epicsStdCall epicsThreadOnce(epicsThreadOnceId *id, EPICSTHREADFUNC, void *arg)

Friends And Related Function Documentation

friend struct detail::field_factory
friend

Definition at line 1251 of file pvIntrospect.h.

friend class Field
friend

Definition at line 1407 of file pvIntrospect.h.


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