PVData C++  8.0.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
convert.h
1 /* convert.h */
2 /*
3  * Copyright information and license terms for this software can be
4  * found in the file LICENSE that is included with the distribution
5  */
9 #ifndef CONVERT_H
10 #define CONVERT_H
11 
12 #include <string>
13 #include <stdexcept>
14 #include <vector>
15 
16 #include <pv/pvIntrospect.h>
17 #include <pv/pvData.h>
18 
19 #include <shareLib.h>
20 
21 namespace epics { namespace pvData {
22 
23 class Convert;
24 typedef std::tr1::shared_ptr<Convert> ConvertPtr;
25 
47 class epicsShareClass Convert {
48 public:
49  static ConvertPtr getConvert();
50 
60  void copy(PVFieldPtr const & from, PVFieldPtr const & to) {
61  to->copy(*from);
62  }
63 
70  inline void getString(std::string * buf,PVFieldPtr const & pvField)
71  {getString(buf, pvField.get(), 0);}
79  void getString(std::string * buf,PVField const * pvField,int indentLevel);
88  std::size_t fromString(
89  PVStructurePtr const &pv,
90  StringArray const & from,
91  std::size_t fromStartIndex = 0);
98  void fromString(PVScalarPtr const & pv, std::string const & from)
99  {
100  pv->putFrom<std::string>(from);
101  }
102 
112  std::size_t fromString(PVScalarArrayPtr const & pv, std::string from);
125  std::size_t fromStringArray(
126  PVScalarArrayPtr const & pv,
127  std::size_t offset, std::size_t length,
128  StringArray const & from,
129  std::size_t fromOffset);
139  std::size_t toStringArray(PVScalarArrayPtr const & pv,
140  std::size_t offset,
141  std::size_t length,
142  StringArray & to,
143  std::size_t toOffset);
149  inline int8 toByte(PVScalarPtr const & pv) { return pv->getAs<int8>();}
156  inline int16 toShort(PVScalarPtr const & pv) { return pv->getAs<int16>();}
163  inline int32 toInt(PVScalarPtr const & pv) { return pv->getAs<int32>();}
170  inline int64 toLong(PVScalarPtr const & pv) { return pv->getAs<int32>();}
176  inline uint8 toUByte(PVScalarPtr const & pv) { return pv->getAs<uint8>();}
183  inline uint16 toUShort(PVScalarPtr const & pv) { return pv->getAs<uint16>();}
190  inline uint32 toUInt(PVScalarPtr const & pv) { return pv->getAs<uint32>();}
197  inline uint64 toULong(PVScalarPtr const & pv) { return pv->getAs<uint64>();}
204  inline float toFloat(PVScalarPtr const & pv) { return pv->getAs<float>();}
211  inline double toDouble(PVScalarPtr const & pv) { return pv->getAs<double>();}
217  inline std::string toString(PVScalarPtr const & pv) { return pv->getAs<std::string>();}
224  inline void fromByte(PVScalarPtr const & pv,int8 from) { pv->putFrom<int8>(from); }
231  inline void fromShort(PVScalarPtr const & pv,int16 from) { pv->putFrom<int16>(from); }
238  inline void fromInt(PVScalarPtr const & pv, int32 from) { pv->putFrom<int32>(from); }
245  inline void fromLong(PVScalarPtr const & pv, int64 from) { pv->putFrom<int64>(from); }
252  inline void fromUByte(PVScalarPtr const & pv,uint8 from) { pv->putFrom<uint8>(from); }
259  inline void fromUShort(PVScalarPtr const & pv,uint16 from) { pv->putFrom<uint16>(from); }
266  inline void fromUInt(PVScalarPtr const & pv, uint32 from) { pv->putFrom<uint32>(from); }
273  inline void fromULong(PVScalarPtr const & pv, uint64 from) { pv->putFrom<uint64>(from); }
280  inline void fromFloat(PVScalarPtr const & pv, float from) { pv->putFrom<float>(from); }
287  inline void fromDouble(PVScalarPtr const & pv, double from) { pv->putFrom<double>(from); }
288 
289 };
290 
291 static inline ConvertPtr getConvert() { return Convert::getConvert(); }
292 
293 }}
294 #endif /* CONVERT_H */
double toDouble(PVScalarPtr const &pv)
Definition: convert.h:211
void fromUInt(PVScalarPtr const &pv, uint32 from)
Definition: convert.h:266
void copy(PVFieldPtr const &from, PVFieldPtr const &to)
Definition: convert.h:60
uint64 toULong(PVScalarPtr const &pv)
Definition: convert.h:197
int16 toShort(PVScalarPtr const &pv)
Definition: convert.h:156
void fromULong(PVScalarPtr const &pv, uint64 from)
Definition: convert.h:273
uint32_t uint32
Definition: pvType.h:99
std::tr1::shared_ptr< PVScalar > PVScalarPtr
Definition: pvData.h:77
void fromLong(PVScalarPtr const &pv, int64 from)
Definition: convert.h:245
float toFloat(PVScalarPtr const &pv)
Definition: convert.h:204
std::string toString(PVScalarPtr const &pv)
Definition: convert.h:217
uint8_t uint8
Definition: pvType.h:91
uint8 toUByte(PVScalarPtr const &pv)
Definition: convert.h:176
int16_t int16
Definition: pvType.h:79
void fromByte(PVScalarPtr const &pv, int8 from)
Definition: convert.h:224
void fromFloat(PVScalarPtr const &pv, float from)
Definition: convert.h:280
std::tr1::shared_ptr< PVScalarArray > PVScalarArrayPtr
Definition: pvData.h:82
std::tr1::shared_ptr< PVField > PVFieldPtr
Definition: pvData.h:66
int32 toInt(PVScalarPtr const &pv)
Definition: convert.h:163
int64_t int64
Definition: pvType.h:87
void fromUShort(PVScalarPtr const &pv, uint16 from)
Definition: convert.h:259
void fromDouble(PVScalarPtr const &pv, double from)
Definition: convert.h:287
int32_t int32
Definition: pvType.h:83
void fromUByte(PVScalarPtr const &pv, uint8 from)
Definition: convert.h:252
PVField is the base class for each PVData field.
Definition: pvData.h:152
Conversion and Copy facility for pvData.
Definition: convert.h:47
int8 toByte(PVScalarPtr const &pv)
Definition: convert.h:149
int64 toLong(PVScalarPtr const &pv)
Definition: convert.h:170
std::tr1::shared_ptr< PVStructure > PVStructurePtr
Definition: pvData.h:87
void fromInt(PVScalarPtr const &pv, int32 from)
Definition: convert.h:238
uint16_t uint16
Definition: pvType.h:95
uint32 toUInt(PVScalarPtr const &pv)
Definition: convert.h:190
int8_t int8
Definition: pvType.h:75
void fromString(PVScalarPtr const &pv, std::string const &from)
Definition: convert.h:98
uint64_t uint64
Definition: pvType.h:103
uint16 toUShort(PVScalarPtr const &pv)
Definition: convert.h:183
void fromShort(PVScalarPtr const &pv, int16 from)
Definition: convert.h:231
void getString(std::string *buf, PVFieldPtr const &pvField)
Definition: convert.h:70