Class Convert¶
Defined in File convert.h
Class Documentation¶
-
class Convert¶
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.
Public Functions
-
inline void copy(PVFieldPtr const &from, PVFieldPtr const &to)¶
Copy from a PVField to another PVField. This calls one on copyScalar, copyArray, copyStructure. The two arguments must be compatible.
- Deprecated:
use “to->copy[Unchecked](*from)” instead
- Parameters
from – The source.
to – The destination
- Throws
std::invalid_argument – if the arguments are not compatible.
-
inline void getString(std::string *buf, PVFieldPtr const &pvField)¶
Convert a PVField to a string. If a PVField is a structure or array be prepared for a very long string.
- Parameters
buf – string that will hold pvField converted to a string,
pvField – The PVField to convert to a string.
-
void 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
buf – string that will hold pvField converted to a string,
pvField – The PVField to convert to a string.
indentLevel – indentation level
-
std::size_t fromString(PVStructurePtr const &pv, StringArray const &from, std::size_t fromStartIndex = 0)¶
Convert from an array of std::string to a PVStructure
- Parameters
pv – The PV.
from – The array of std::string value to convert and put into a PV.
fromStartIndex – The first element if the array of strings.
- Throws
std::logic_error – if the array of std::string does not have a valid values.
- Returns
The total number of fields that have been changed.
-
inline void fromString(PVScalarPtr const &pv, std::string const &from)¶
Convert from a std::string to a PVScalar
- Parameters
pv – The PV.
from – The std::string value to convert and put into a PV.
- Throws
std::logic_error – if the std::string does not have a valid value.
-
std::size_t 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
pv – The PV.
from – The std::string value to convert and put into a PV.
- Throws
std::invalid_argument – if the element Type is not a scalar.
std::logic_error – if the std::string does not have a valid array values.
- Returns
The number of elements converted.
-
std::size_t 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
pv – The PV.
offset – Starting element in a PV.
length – The number of elements to transfer.
from – The array of values to put into the PV.
fromOffset – Starting element in the source array.
- Throws
std::invalid_argument – if the element Type is not a scalar.
std::logic_error – if the std::string does not have a valid value.
- Returns
The number of elements converted.
-
std::size_t 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
pv – The PV.
offset – Starting element in the PV array.
length – Number of elements to convert to the string array.
to – std::string array to receive the converted PV data.
toOffset – Starting element in the string array.
- Returns
Number of elements converted.
-
inline int8 toByte(PVScalarPtr const &pv)¶
Convert a PV to a byte.
- Parameters
pv – a PV
- Returns
converted value
-
inline int16 toShort(PVScalarPtr const &pv)¶
Convert a PV to a short.
- Parameters
pv – a PV
- Throws
std::invalid_argument – if the Type is not a numeric scalar
- Returns
converted value
-
inline int32 toInt(PVScalarPtr const &pv)¶
Convert a PV to a int.
- Parameters
pv – a PV
- Throws
std::invalid_argument – if the Type is not a numeric scalar
- Returns
converted value
-
inline int64 toLong(PVScalarPtr const &pv)¶
Convert a PV to an long
- Parameters
pv – a PV
- Throws
std::invalid_argument – if the Type is not a numeric scalar
- Returns
converted value
-
inline uint8 toUByte(PVScalarPtr const &pv)¶
Convert a PV to a ubyte.
- Parameters
pv – a PV
- Returns
converted value
-
inline uint16 toUShort(PVScalarPtr const &pv)¶
Convert a PV to a ushort.
- Parameters
pv – a PV
- Throws
std::invalid_argument – if the Type is not a numeric scalar
- Returns
converted value
-
inline uint32 toUInt(PVScalarPtr const &pv)¶
Convert a PV to a uint.
- Parameters
pv – a PV
- Throws
std::invalid_argument – if the Type is not a numeric scalar
- Returns
converted value
-
inline uint64 toULong(PVScalarPtr const &pv)¶
Convert a PV to an ulong
- Parameters
pv – a PV
- Throws
std::invalid_argument – if the Type is not a numeric scalar
- Returns
converted value
-
inline float toFloat(PVScalarPtr const &pv)¶
Convert a PV to a float
- Parameters
pv – a PV
- Throws
std::invalid_argument – if the Type is not a numeric scalar
- Returns
converted value
-
inline double toDouble(PVScalarPtr const &pv)¶
Convert a PV to a double
- Parameters
pv – a PV
- Throws
std::invalid_argument – if the Type is not a numeric scalar
- Returns
converted value
-
inline std::string toString(PVScalarPtr const &pv)¶
Convert a PV to a std::string
- Parameters
pv – a PV
- Returns
converted value
-
inline void fromByte(PVScalarPtr const &pv, int8 from)¶
Convert a PV from a byte
- Parameters
pv – a PV
from – value to put into PV
- Throws
std::invalid_argument – if the Type is not a numeric scalar
-
inline void fromShort(PVScalarPtr const &pv, int16 from)¶
Convert a PV from a short
- Parameters
pv – a PV
from – value to put into PV
- Throws
std::invalid_argument – if the Type is not a numeric scalar
-
inline void fromInt(PVScalarPtr const &pv, int32 from)¶
Convert a PV from an int
- Parameters
pv – a PV
from – value to put into PV
- Throws
std::invalid_argument – if the Type is not a numeric scalar
-
inline void fromLong(PVScalarPtr const &pv, int64 from)¶
Convert a PV from a long
- Parameters
pv – a PV
from – value to put into PV
- Throws
std::invalid_argument – if the Type is not a numeric scalar
-
inline void fromUByte(PVScalarPtr const &pv, uint8 from)¶
Convert a PV from a ubyte
- Parameters
pv – a PV
from – value to put into PV
- Throws
std::invalid_argument – if the Type is not a numeric scalar
-
inline void fromUShort(PVScalarPtr const &pv, uint16 from)¶
Convert a PV from a ushort
- Parameters
pv – a PV
from – value to put into PV
- Throws
std::invalid_argument – if the Type is not a numeric scalar
-
inline void fromUInt(PVScalarPtr const &pv, uint32 from)¶
Convert a PV from an uint
- Parameters
pv – a PV
from – value to put into PV
- Throws
std::invalid_argument – if the Type is not a numeric scalar
-
inline void fromULong(PVScalarPtr const &pv, uint64 from)¶
Convert a PV from a ulong
- Parameters
pv – a PV
from – value to put into PV
- Throws
std::invalid_argument – if the Type is not a numeric scalar
-
inline void fromFloat(PVScalarPtr const &pv, float from)¶
Convert a PV from a float
- Parameters
pv – a PV
from – value to put into PV
- Throws
std::invalid_argument – if the Type is not a numeric scalar
-
inline void fromDouble(PVScalarPtr const &pv, double from)¶
Convert a PV from a double
- Parameters
pv – a PV
from – value to put into PV
- Throws
std::invalid_argument – if the Type is not a numeric scalar
Public Static Functions
-
static ConvertPtr getConvert()¶
-
inline void copy(PVFieldPtr const &from, PVFieldPtr const &to)¶