|
PVData C++
|
00001 /* convert.h */ 00002 /* 00003 * Copyright information and license terms for this software can be 00004 * found in the file LICENSE that is included with the distribution 00005 */ 00009 #ifndef CONVERT_H 00010 #define CONVERT_H 00011 00012 #include <string> 00013 #include <stdexcept> 00014 #include <vector> 00015 00016 #include <pv/pvIntrospect.h> 00017 #include <pv/pvData.h> 00018 00019 #include <shareLib.h> 00020 00021 namespace epics { namespace pvData { 00022 00023 class Convert; 00024 typedef std::tr1::shared_ptr<Convert> ConvertPtr; 00025 00047 class epicsShareClass Convert { 00048 public: 00049 static ConvertPtr getConvert(); 00050 00060 void copy(PVFieldPtr const & from, PVFieldPtr const & to) { 00061 to->copy(*from); 00062 } 00063 00070 inline void getString(std::string * buf,PVFieldPtr const & pvField) 00071 {getString(buf, pvField.get(), 0);} 00079 void getString(std::string * buf,PVField const * pvField,int indentLevel); 00088 std::size_t fromString( 00089 PVStructurePtr const &pv, 00090 StringArray const & from, 00091 std::size_t fromStartIndex = 0); 00098 void fromString(PVScalarPtr const & pv, std::string const & from) 00099 { 00100 pv->putFrom<std::string>(from); 00101 } 00102 00112 std::size_t fromString(PVScalarArrayPtr const & pv, std::string from); 00125 std::size_t fromStringArray( 00126 PVScalarArrayPtr const & pv, 00127 std::size_t offset, std::size_t length, 00128 StringArray const & from, 00129 std::size_t fromOffset); 00139 std::size_t toStringArray(PVScalarArrayPtr const & pv, 00140 std::size_t offset, 00141 std::size_t length, 00142 StringArray & to, 00143 std::size_t toOffset); 00149 inline int8 toByte(PVScalarPtr const & pv) { return pv->getAs<int8>();} 00156 inline int16 toShort(PVScalarPtr const & pv) { return pv->getAs<int16>();} 00163 inline int32 toInt(PVScalarPtr const & pv) { return pv->getAs<int32>();} 00170 inline int64 toLong(PVScalarPtr const & pv) { return pv->getAs<int32>();} 00176 inline uint8 toUByte(PVScalarPtr const & pv) { return pv->getAs<uint8>();} 00183 inline uint16 toUShort(PVScalarPtr const & pv) { return pv->getAs<uint16>();} 00190 inline uint32 toUInt(PVScalarPtr const & pv) { return pv->getAs<uint32>();} 00197 inline uint64 toULong(PVScalarPtr const & pv) { return pv->getAs<uint64>();} 00204 inline float toFloat(PVScalarPtr const & pv) { return pv->getAs<float>();} 00211 inline double toDouble(PVScalarPtr const & pv) { return pv->getAs<double>();} 00217 inline std::string toString(PVScalarPtr const & pv) { return pv->getAs<std::string>();} 00224 inline void fromByte(PVScalarPtr const & pv,int8 from) { pv->putFrom<int8>(from); } 00231 inline void fromShort(PVScalarPtr const & pv,int16 from) { pv->putFrom<int16>(from); } 00238 inline void fromInt(PVScalarPtr const & pv, int32 from) { pv->putFrom<int32>(from); } 00245 inline void fromLong(PVScalarPtr const & pv, int64 from) { pv->putFrom<int64>(from); } 00252 inline void fromUByte(PVScalarPtr const & pv,uint8 from) { pv->putFrom<uint8>(from); } 00259 inline void fromUShort(PVScalarPtr const & pv,uint16 from) { pv->putFrom<uint16>(from); } 00266 inline void fromUInt(PVScalarPtr const & pv, uint32 from) { pv->putFrom<uint32>(from); } 00273 inline void fromULong(PVScalarPtr const & pv, uint64 from) { pv->putFrom<uint64>(from); } 00280 inline void fromFloat(PVScalarPtr const & pv, float from) { pv->putFrom<float>(from); } 00287 inline void fromDouble(PVScalarPtr const & pv, double from) { pv->putFrom<double>(from); } 00288 00289 }; 00290 00291 static inline ConvertPtr getConvert() { return Convert::getConvert(); } 00292 00293 }} 00294 #endif /* CONVERT_H */
1.7.4