Program Listing for File convert.h

Return to documentation for file (src/pv/convert.h)

/* convert.h */
/*
 * Copyright information and license terms for this software can be
 * found in the file LICENSE that is included with the distribution
 */
#ifndef CONVERT_H
#define CONVERT_H

#include <string>
#include <stdexcept>
#include <vector>

#include <pv/pvIntrospect.h>
#include <pv/pvData.h>

#include <shareLib.h>

namespace epics { namespace pvData {

class Convert;
typedef std::tr1::shared_ptr<Convert> ConvertPtr;

class epicsShareClass Convert {
public:
    static ConvertPtr getConvert();

    void copy(PVFieldPtr const & from, PVFieldPtr const & to) {
        to->copy(*from);
    }

    inline void getString(std::string * buf,PVFieldPtr const & pvField)
    {getString(buf, pvField.get(), 0);}
    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)
    {
        pv->putFrom<std::string>(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);
    inline int8 toByte(PVScalarPtr const & pv) { return pv->getAs<int8>();}
    inline int16 toShort(PVScalarPtr const & pv) { return pv->getAs<int16>();}
    inline int32 toInt(PVScalarPtr const & pv) { return pv->getAs<int32>();}
    inline int64 toLong(PVScalarPtr const & pv) { return pv->getAs<int32>();}
    inline uint8 toUByte(PVScalarPtr const & pv) { return pv->getAs<uint8>();}
    inline uint16 toUShort(PVScalarPtr const & pv) { return pv->getAs<uint16>();}
    inline uint32 toUInt(PVScalarPtr const & pv) { return pv->getAs<uint32>();}
    inline uint64 toULong(PVScalarPtr const & pv) { return pv->getAs<uint64>();}
    inline float toFloat(PVScalarPtr const & pv) { return pv->getAs<float>();}
    inline double toDouble(PVScalarPtr const & pv) { return pv->getAs<double>();}
    inline std::string toString(PVScalarPtr const & pv) { return pv->getAs<std::string>();}
    inline void fromByte(PVScalarPtr const & pv,int8 from) { pv->putFrom<int8>(from); }
    inline void fromShort(PVScalarPtr const & pv,int16 from) { pv->putFrom<int16>(from); }
    inline void fromInt(PVScalarPtr const & pv, int32 from) { pv->putFrom<int32>(from); }
    inline void fromLong(PVScalarPtr const & pv, int64 from) { pv->putFrom<int64>(from); }
    inline void fromUByte(PVScalarPtr const & pv,uint8 from) { pv->putFrom<uint8>(from); }
    inline void fromUShort(PVScalarPtr const & pv,uint16 from) { pv->putFrom<uint16>(from); }
    inline void fromUInt(PVScalarPtr const & pv, uint32 from) { pv->putFrom<uint32>(from); }
    inline void fromULong(PVScalarPtr const & pv, uint64 from) { pv->putFrom<uint64>(from); }
    inline void fromFloat(PVScalarPtr const & pv, float from) { pv->putFrom<float>(from); }
    inline void fromDouble(PVScalarPtr const & pv, double from) { pv->putFrom<double>(from); }

};

static inline ConvertPtr getConvert() { return Convert::getConvert(); }

}}
#endif  /* CONVERT_H */