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

Conversion and Copy facility for pvData. More...

#include "convert.h"

Public Member Functions

void copy (PVFieldPtr const &from, PVFieldPtr const &to)
 
void getString (std::string *buf, PVFieldPtr const &pvField)
 
void getString (std::string *buf, PVField const *pvField, int indentLevel)
 
std::size_t fromString (PVStructurePtr const &pv, StringArray const &from, std::size_t fromStartIndex=0)
 
void fromString (PVScalarPtr const &pv, std::string const &from)
 
std::size_t fromString (PVScalarArrayPtr const &pv, std::string from)
 
std::size_t fromStringArray (PVScalarArrayPtr const &pv, std::size_t offset, std::size_t length, StringArray const &from, std::size_t fromOffset)
 
std::size_t toStringArray (PVScalarArrayPtr const &pv, std::size_t offset, std::size_t length, StringArray &to, std::size_t toOffset)
 
int8 toByte (PVScalarPtr const &pv)
 
int16 toShort (PVScalarPtr const &pv)
 
int32 toInt (PVScalarPtr const &pv)
 
int64 toLong (PVScalarPtr const &pv)
 
uint8 toUByte (PVScalarPtr const &pv)
 
uint16 toUShort (PVScalarPtr const &pv)
 
uint32 toUInt (PVScalarPtr const &pv)
 
uint64 toULong (PVScalarPtr const &pv)
 
float toFloat (PVScalarPtr const &pv)
 
double toDouble (PVScalarPtr const &pv)
 
std::string toString (PVScalarPtr const &pv)
 
void fromByte (PVScalarPtr const &pv, int8 from)
 
void fromShort (PVScalarPtr const &pv, int16 from)
 
void fromInt (PVScalarPtr const &pv, int32 from)
 
void fromLong (PVScalarPtr const &pv, int64 from)
 
void fromUByte (PVScalarPtr const &pv, uint8 from)
 
void fromUShort (PVScalarPtr const &pv, uint16 from)
 
void fromUInt (PVScalarPtr const &pv, uint32 from)
 
void fromULong (PVScalarPtr const &pv, uint64 from)
 
void fromFloat (PVScalarPtr const &pv, float from)
 
void fromDouble (PVScalarPtr const &pv, double from)
 

Static Public Member Functions

static ConvertPtr getConvert ()
 

Detailed Description

Conversion and Copy facility for pvData.

Convert between numeric types, convert any field to a string, or convert from a string to a scalar field.

Numeric conversions are between scalar numeric types or between arrays of numeric types. It is not possible to convert between a scalar and an array. Numeric conversions are between types: pvByte, pvShort, pvInt, pvLong, pvUByte, pvUShort, pvUInt, pvULong, pvFloat, or pvDouble.

getString converts any supported type to a std::string.

fromString converts a std::string to a scalar. fromStringArray converts an array of std::strings to a pvArray, which must have a scaler element type. A scalar field is a numeric field or pvBoolean or pvString.

All from methods put data into a PVField, e.g. from means where the PVField gets it's data.

Definition at line 47 of file convert.h.

Member Function Documentation

void epics::pvData::Convert::copy ( PVFieldPtr const &  from,
PVFieldPtr const &  to 
)
inline

Copy from a PVField to another PVField. This calls one on copyScalar, copyArray, copyStructure. The two arguments must be compatible.

Parameters
fromThe source.
toThe destination
Exceptions
std::invalid_argumentif the arguments are not compatible.
Deprecated:
use "to->copy[Unchecked](*from)" instead

Definition at line 60 of file convert.h.

60  {
61  to->copy(*from);
62  }
void epics::pvData::Convert::fromByte ( PVScalarPtr const &  pv,
int8  from 
)
inline

Convert a PV from a byte

Parameters
pva PV
fromvalue to put into PV
Exceptions
std::invalid_argumentif the Type is not a numeric scalar

Definition at line 224 of file convert.h.

224 { pv->putFrom<int8>(from); }
int8_t int8
Definition: pvType.h:75
Definition: tool_lib.h:67
void epics::pvData::Convert::fromDouble ( PVScalarPtr const &  pv,
double  from 
)
inline

Convert a PV from a double

Parameters
pva PV
fromvalue to put into PV
Exceptions
std::invalid_argumentif the Type is not a numeric scalar

Definition at line 287 of file convert.h.

287 { pv->putFrom<double>(from); }
Definition: tool_lib.h:67
void epics::pvData::Convert::fromFloat ( PVScalarPtr const &  pv,
float  from 
)
inline

Convert a PV from a float

Parameters
pva PV
fromvalue to put into PV
Exceptions
std::invalid_argumentif the Type is not a numeric scalar

Definition at line 280 of file convert.h.

280 { pv->putFrom<float>(from); }
Definition: tool_lib.h:67
void epics::pvData::Convert::fromInt ( PVScalarPtr const &  pv,
int32  from 
)
inline

Convert a PV from an int

Parameters
pva PV
fromvalue to put into PV
Exceptions
std::invalid_argumentif the Type is not a numeric scalar

Definition at line 238 of file convert.h.

238 { pv->putFrom<int32>(from); }
Definition: tool_lib.h:67
int32_t int32
Definition: pvType.h:83
void epics::pvData::Convert::fromLong ( PVScalarPtr const &  pv,
int64  from 
)
inline

Convert a PV from a long

Parameters
pva PV
fromvalue to put into PV
Exceptions
std::invalid_argumentif the Type is not a numeric scalar

Definition at line 245 of file convert.h.

245 { pv->putFrom<int64>(from); }
Definition: tool_lib.h:67
int64_t int64
Definition: pvType.h:87
void epics::pvData::Convert::fromShort ( PVScalarPtr const &  pv,
int16  from 
)
inline

Convert a PV from a short

Parameters
pva PV
fromvalue to put into PV
Exceptions
std::invalid_argumentif the Type is not a numeric scalar

Definition at line 231 of file convert.h.

231 { pv->putFrom<int16>(from); }
Definition: tool_lib.h:67
int16_t int16
Definition: pvType.h:79
std::size_t epics::pvData::Convert::fromString ( PVStructurePtr const &  pv,
StringArray const &  from,
std::size_t  fromStartIndex = 0 
)

Convert from an array of std::string to a PVStructure

Parameters
pvThe PV.
fromThe array of std::string value to convert and put into a PV.
fromStartIndexThe first element if the array of strings.
Returns
The total number of fields that have been changed.
Exceptions
std::logic_errorif the array of std::string does not have a valid values.
void epics::pvData::Convert::fromString ( PVScalarPtr const &  pv,
std::string const &  from 
)
inline

Convert from a std::string to a PVScalar

Parameters
pvThe PV.
fromThe std::string value to convert and put into a PV.
Exceptions
std::logic_errorif the std::string does not have a valid value.

Definition at line 98 of file convert.h.

99  {
100  pv->putFrom<std::string>(from);
101  }
Definition: tool_lib.h:67
std::size_t epics::pvData::Convert::fromString ( PVScalarArrayPtr const &  pv,
std::string  from 
)

Convert from a std::string to a PVScalarArray. The std::string must be a comma separated set of values optionally enclosed in []

Parameters
pvThe PV.
fromThe std::string value to convert and put into a PV.
Returns
The number of elements converted.
Exceptions
std::invalid_argumentif the element Type is not a scalar.
std::logic_errorif the std::string does not have a valid array values.
size_t epics::pvData::Convert::fromStringArray ( PVScalarArrayPtr const &  pv,
std::size_t  offset,
std::size_t  length,
StringArray const &  from,
std::size_t  fromOffset 
)

Convert a PVScalarArray from a std::string array. The array element type must be a scalar.

Parameters
pvThe PV.
offsetStarting element in a PV.
lengthThe number of elements to transfer.
fromThe array of values to put into the PV.
fromOffsetStarting element in the source array.
Returns
The number of elements converted.
Exceptions
std::invalid_argumentif the element Type is not a scalar.
std::logic_errorif the std::string does not have a valid value.

Definition at line 114 of file Convert.cpp.

118 {
119  size_t alen = pv->getLength();
120 
121  if(offset==0 && length>=alen) {
122  // replace all existing elements
123  assert(from.size()>=fromOffset+length);
124 
125  PVStringArray::svector data(length);
126  std::copy(from.begin()+fromOffset,
127  from.begin()+fromOffset+length,
128  data.begin());
129 
130  PVStringArray::const_svector temp(freeze(data));
131  pv->putFrom<string>(temp);
132  return length;
133 
134  } else {
135  // partial update.
136  throw std::runtime_error("fromStringArray: partial update not implemented");
137  }
138 }
#define assert(exp)
Declare that a condition should be true.
Definition: epicsAssert.h:70
::epics::pvData::shared_vector< T > svector
Definition: pvData.h:1184
Definition: tool_lib.h:67
void copy(PVValueArray< T > &pvFrom, size_t fromOffset, size_t fromStride, PVValueArray< T > &pvTo, size_t toOffset, size_t toStride, size_t count)
Copy a subarray from one scalar array to another.
::epics::pvData::shared_vector< const T > const_svector
Definition: pvData.h:1185
void epics::pvData::Convert::fromUByte ( PVScalarPtr const &  pv,
uint8  from 
)
inline

Convert a PV from a ubyte

Parameters
pva PV
fromvalue to put into PV
Exceptions
std::invalid_argumentif the Type is not a numeric scalar

Definition at line 252 of file convert.h.

252 { pv->putFrom<uint8>(from); }
Definition: tool_lib.h:67
uint8_t uint8
Definition: pvType.h:91
void epics::pvData::Convert::fromUInt ( PVScalarPtr const &  pv,
uint32  from 
)
inline

Convert a PV from an uint

Parameters
pva PV
fromvalue to put into PV
Exceptions
std::invalid_argumentif the Type is not a numeric scalar

Definition at line 266 of file convert.h.

266 { pv->putFrom<uint32>(from); }
Definition: tool_lib.h:67
uint32_t uint32
Definition: pvType.h:99
void epics::pvData::Convert::fromULong ( PVScalarPtr const &  pv,
uint64  from 
)
inline

Convert a PV from a ulong

Parameters
pva PV
fromvalue to put into PV
Exceptions
std::invalid_argumentif the Type is not a numeric scalar

Definition at line 273 of file convert.h.

273 { pv->putFrom<uint64>(from); }
Definition: tool_lib.h:67
uint64_t uint64
Definition: pvType.h:103
void epics::pvData::Convert::fromUShort ( PVScalarPtr const &  pv,
uint16  from 
)
inline

Convert a PV from a ushort

Parameters
pva PV
fromvalue to put into PV
Exceptions
std::invalid_argumentif the Type is not a numeric scalar

Definition at line 259 of file convert.h.

259 { pv->putFrom<uint16>(from); }
uint16_t uint16
Definition: pvType.h:95
Definition: tool_lib.h:67
ConvertPtr epics::pvData::Convert::getConvert ( )
static

Definition at line 153 of file Convert.cpp.

154 {
155  static ConvertPtr convert;
156  static Mutex mutex;
157  Lock xx(mutex);
158 
159  if(convert.get()==0) {
160  convert = ConvertPtr(new Convert());
161  }
162  return convert;
163 }
epicsMutex mutex
Definition: pvAccess.cpp:71
std::tr1::shared_ptr< Convert > ConvertPtr
Definition: convert.h:23
epicsMutex Mutex
Definition: lock.h:28
void epics::pvData::Convert::getString ( std::string *  buf,
PVFieldPtr const &  pvField 
)
inline

Convert a PVField to a string. If a PVField is a structure or array be prepared for a very long string.

Parameters
bufstring that will hold pvField converted to a string,
pvFieldThe PVField to convert to a string.

Definition at line 70 of file convert.h.

71  {getString(buf, pvField.get(), 0);}
void getString(std::string *buf, PVFieldPtr const &pvField)
Definition: convert.h:70
void epics::pvData::Convert::getString ( std::string *  buf,
PVField const *  pvField,
int  indentLevel 
)

Convert a PVField to a string. If a PVField is a structure or array be prepared for a very long string.

Parameters
bufstring that will hold pvField converted to a string,
pvFieldThe PVField to convert to a string.
indentLevelindentation level
int8 epics::pvData::Convert::toByte ( PVScalarPtr const &  pv)
inline

Convert a PV to a byte.

Parameters
pva PV
Returns
converted value

Definition at line 149 of file convert.h.

149 { return pv->getAs<int8>();}
int8_t int8
Definition: pvType.h:75
Definition: tool_lib.h:67
double epics::pvData::Convert::toDouble ( PVScalarPtr const &  pv)
inline

Convert a PV to a double

Parameters
pva PV
Returns
converted value
Exceptions
std::invalid_argumentif the Type is not a numeric scalar

Definition at line 211 of file convert.h.

211 { return pv->getAs<double>();}
Definition: tool_lib.h:67
float epics::pvData::Convert::toFloat ( PVScalarPtr const &  pv)
inline

Convert a PV to a float

Parameters
pva PV
Returns
converted value
Exceptions
std::invalid_argumentif the Type is not a numeric scalar

Definition at line 204 of file convert.h.

204 { return pv->getAs<float>();}
Definition: tool_lib.h:67
int32 epics::pvData::Convert::toInt ( PVScalarPtr const &  pv)
inline

Convert a PV to a int.

Parameters
pva PV
Returns
converted value
Exceptions
std::invalid_argumentif the Type is not a numeric scalar

Definition at line 163 of file convert.h.

163 { return pv->getAs<int32>();}
Definition: tool_lib.h:67
int32_t int32
Definition: pvType.h:83
int64 epics::pvData::Convert::toLong ( PVScalarPtr const &  pv)
inline

Convert a PV to an long

Parameters
pva PV
Returns
converted value
Exceptions
std::invalid_argumentif the Type is not a numeric scalar

Definition at line 170 of file convert.h.

170 { return pv->getAs<int32>();}
Definition: tool_lib.h:67
int32_t int32
Definition: pvType.h:83
int16 epics::pvData::Convert::toShort ( PVScalarPtr const &  pv)
inline

Convert a PV to a short.

Parameters
pva PV
Returns
converted value
Exceptions
std::invalid_argumentif the Type is not a numeric scalar

Definition at line 156 of file convert.h.

156 { return pv->getAs<int16>();}
Definition: tool_lib.h:67
int16_t int16
Definition: pvType.h:79
std::string epics::pvData::Convert::toString ( PVScalarPtr const &  pv)
inline

Convert a PV to a std::string

Parameters
pva PV
Returns
converted value

Definition at line 217 of file convert.h.

217 { return pv->getAs<std::string>();}
Definition: tool_lib.h:67
size_t epics::pvData::Convert::toStringArray ( PVScalarArrayPtr const &  pv,
std::size_t  offset,
std::size_t  length,
StringArray to,
std::size_t  toOffset 
)

Convert a PVScalarArray to a std::string array.

Parameters
pvThe PV.
offsetStarting element in the PV array.
lengthNumber of elements to convert to the string array.
tostd::string array to receive the converted PV data.
toOffsetStarting element in the string array.
Returns
Number of elements converted.

Definition at line 140 of file Convert.cpp.

143 {
145  pv->getAs<string>(data);
146  data.slice(offset, length);
147  if(toOffset+data.size() > to.size())
148  to.resize(toOffset+data.size());
149  std::copy(data.begin()+toOffset, data.end(), to.begin());
150  return data.size();
151 }
Definition: tool_lib.h:67
void copy(PVValueArray< T > &pvFrom, size_t fromOffset, size_t fromStride, PVValueArray< T > &pvTo, size_t toOffset, size_t toStride, size_t count)
Copy a subarray from one scalar array to another.
::epics::pvData::shared_vector< const T > const_svector
Definition: pvData.h:1185
uint8 epics::pvData::Convert::toUByte ( PVScalarPtr const &  pv)
inline

Convert a PV to a ubyte.

Parameters
pva PV
Returns
converted value

Definition at line 176 of file convert.h.

176 { return pv->getAs<uint8>();}
Definition: tool_lib.h:67
uint8_t uint8
Definition: pvType.h:91
uint32 epics::pvData::Convert::toUInt ( PVScalarPtr const &  pv)
inline

Convert a PV to a uint.

Parameters
pva PV
Returns
converted value
Exceptions
std::invalid_argumentif the Type is not a numeric scalar

Definition at line 190 of file convert.h.

190 { return pv->getAs<uint32>();}
Definition: tool_lib.h:67
uint32_t uint32
Definition: pvType.h:99
uint64 epics::pvData::Convert::toULong ( PVScalarPtr const &  pv)
inline

Convert a PV to an ulong

Parameters
pva PV
Returns
converted value
Exceptions
std::invalid_argumentif the Type is not a numeric scalar

Definition at line 197 of file convert.h.

197 { return pv->getAs<uint64>();}
Definition: tool_lib.h:67
uint64_t uint64
Definition: pvType.h:103
uint16 epics::pvData::Convert::toUShort ( PVScalarPtr const &  pv)
inline

Convert a PV to a ushort.

Parameters
pva PV
Returns
converted value
Exceptions
std::invalid_argumentif the Type is not a numeric scalar

Definition at line 183 of file convert.h.

183 { return pv->getAs<uint16>();}
uint16_t uint16
Definition: pvType.h:95
Definition: tool_lib.h:67

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