This is Unofficial EPICS BASE Doxygen Site
epics::pvData::ScalarTypeFunc Namespace Reference

Convenience functions for ScalarType. More...

Functions

bool isInteger (ScalarType type)
 
bool isUInteger (ScalarType type)
 
bool isNumeric (ScalarType type)
 
bool isPrimitive (ScalarType type)
 
ScalarType getScalarType (const string &pvalue)
 
const char * name (ScalarType t)
 
size_t elementSize (ScalarType id)
 gives sizeof(T) where T depends on the scalar type id. More...
 
shared_vector< void > allocArray (ScalarType id, size_t len)
 Allocate an untyped array based on ScalarType. More...
 
template<ScalarType ID>
shared_vector< typename ScalarTypeTraits< ID >::typeallocArray (size_t len)
 Allocate an untyped array based on ScalarType. More...
 
epicsShareExtern ScalarType getScalarType (std::string const &value)
 

Detailed Description

Convenience functions for ScalarType.

Function Documentation

epicsShareFunc shared_vector< void > epics::pvData::ScalarTypeFunc::allocArray ( ScalarType  id,
size_t  len 
)

Allocate an untyped array based on ScalarType.

Definition at line 104 of file TypeFunc.cpp.

105  {
106  switch(id) {
107 #define OP(ENUM, TYPE) case ENUM: return static_shared_vector_cast<void>(shared_vector<TYPE>(len))
108  OP(pvBoolean, boolean);
109  OP(pvUByte, uint8);
110  OP(pvByte, int8);
111  OP(pvUShort, uint16);
112  OP(pvShort, int16);
113  OP(pvUInt, uint32);
114  OP(pvInt, int32);
115  OP(pvULong, uint64);
116  OP(pvLong, int64);
117  OP(pvFloat, float);
118  OP(pvDouble, double);
119  OP(pvString, string);
120 #undef OP
121  default:
122  throw std::bad_alloc();
123  }
124  }
int8_t int8
Definition: pvType.h:75
uint16_t uint16
Definition: pvType.h:95
uint64_t uint64
Definition: pvType.h:103
#define OP(ENUM, TYPE)
int64_t int64
Definition: pvType.h:87
int16_t int16
Definition: pvType.h:79
int32_t int32
Definition: pvType.h:83
uint8_t uint8
Definition: pvType.h:91
uint32_t uint32
Definition: pvType.h:99
template<ScalarType ID>
shared_vector<typename ScalarTypeTraits<ID>::type> epics::pvData::ScalarTypeFunc::allocArray ( size_t  len)
inline

Allocate an untyped array based on ScalarType.

Definition at line 955 of file sharedVector.h.

956  {
957  shared_vector<void> raw(allocArray(ID, len));
958  return static_shared_vector_cast<typename ScalarTypeTraits<ID>::type>(raw);
959  }
pvd::StructureConstPtr type
shared_vector< typename ScalarTypeTraits< ID >::type > allocArray(size_t len)
Allocate an untyped array based on ScalarType.
Definition: sharedVector.h:955
epicsShareExtern size_t epics::pvData::ScalarTypeFunc::elementSize ( ScalarType  id)

gives sizeof(T) where T depends on the scalar type id.

Definition at line 82 of file TypeFunc.cpp.

83  {
84  switch(id) {
85 #define OP(ENUM, TYPE) case ENUM: return sizeof(TYPE)
86  OP(pvBoolean, boolean);
87  OP(pvUByte, uint8);
88  OP(pvByte, int8);
89  OP(pvUShort, uint16);
90  OP(pvShort, int16);
91  OP(pvUInt, uint32);
92  OP(pvInt, int32);
93  OP(pvULong, uint64);
94  OP(pvLong, int64);
95  OP(pvFloat, float);
96  OP(pvDouble, double);
97  OP(pvString, string);
98 #undef OP
99  default:
100  THROW_EXCEPTION2(std::invalid_argument, "error unknown ScalarType");
101  }
102  }
int8_t int8
Definition: pvType.h:75
#define THROW_EXCEPTION2(TYPE, MSG)
uint16_t uint16
Definition: pvType.h:95
uint64_t uint64
Definition: pvType.h:103
#define OP(ENUM, TYPE)
int64_t int64
Definition: pvType.h:87
int16_t int16
Definition: pvType.h:79
int32_t int32
Definition: pvType.h:83
uint8_t uint8
Definition: pvType.h:91
uint32_t uint32
Definition: pvType.h:99
ScalarType epics::pvData::ScalarTypeFunc::getScalarType ( const string &  pvalue)

Definition at line 69 of file TypeFunc.cpp.

69  {
70  for(size_t i=0; i<NELEMENTS(names); i++)
71  if(pvalue==names[i])
72  return ScalarType(i);
73  THROW_EXCEPTION2(std::invalid_argument, "error unknown ScalarType");
74  }
#define THROW_EXCEPTION2(TYPE, MSG)
int i
Definition: scan.c:967
#define NELEMENTS(A)
Definition: aToIPAddr.c:21
epicsShareExtern ScalarType epics::pvData::ScalarTypeFunc::getScalarType ( std::string const &  value)

Get the scalarType for value.

Parameters
valueThe name of the scalar type.
Returns
The scalarType. An exception is thrown if the name is not the name of a scalar type.
epicsShareExtern bool epics::pvData::ScalarTypeFunc::isInteger ( ScalarType  scalarType)

Is the type an integer, i.e. is it one of byte,...ulong

Parameters
scalarTypeThe type.
Returns
(false,true) if the scalarType is an integer.

Definition at line 43 of file TypeFunc.cpp.

43  {
44  if(type>=pvByte && type<=pvULong) return true;
45  return false;
46  }
pvd::StructureConstPtr type
epicsShareExtern bool epics::pvData::ScalarTypeFunc::isNumeric ( ScalarType  scalarType)

Is the type numeric, i.e. is it one of byte,...,double

Parameters
scalarTypeThe type.
Returns
(false,true) if the scalarType is a numeric

Definition at line 53 of file TypeFunc.cpp.

53  {
54  if(type>=pvByte && type<=pvDouble) return true;
55  return false;
56  }
pvd::StructureConstPtr type
epicsShareExtern bool epics::pvData::ScalarTypeFunc::isPrimitive ( ScalarType  scalarType)

Is the type primitive, i.e. not string

Parameters
scalarTypeThe type.
Returns
(false,true) if the scalarType is primitive.

Definition at line 58 of file TypeFunc.cpp.

58  {
59  if(type>=pvBoolean && type<=pvDouble) return true;
60  return false;
61  }
pvd::StructureConstPtr type
epicsShareExtern bool epics::pvData::ScalarTypeFunc::isUInteger ( ScalarType  scalarType)

Is the type an unsigned integer, i.e. is it one of ubyte,...ulong

Parameters
scalarTypeThe type.
Returns
(false,true) if the scalarType is an integer.

Definition at line 48 of file TypeFunc.cpp.

48  {
49  if(type>=pvUByte && type<=pvULong) return true;
50  return false;
51  }
pvd::StructureConstPtr type
epicsShareExtern const char * epics::pvData::ScalarTypeFunc::name ( ScalarType  scalarType)

Get a name for the scalarType.

Parameters
scalarTypeThe type.
Returns
The name for the scalarType.

Definition at line 76 of file TypeFunc.cpp.

76  {
77  if (t<pvBoolean || t>pvString)
78  THROW_EXCEPTION2(std::invalid_argument, "error unknown ScalarType");
79  return names[t];
80  }
#define THROW_EXCEPTION2(TYPE, MSG)