class Poco::Dynamic::VarHolder
Overview
Interface for a data holder used by the Var class. More…
#include <VarHolder.h> class VarHolder { public: // typedefs typedef Var ArrayValueType; // methods virtual VarHolder* clone(Placeholder<VarHolder>* pHolder = 0) const = 0; virtual const std::type_info& type() const = 0; virtual void convert(Int8& val) const; virtual void convert(Int16& val) const; virtual void convert(Int32& val) const; virtual void convert(Int64& val) const; virtual void convert(UInt8& val) const; virtual void convert(UInt16& val) const; virtual void convert(UInt32& val) const; virtual void convert(UInt64& val) const; virtual void convert(DateTime& val) const; virtual void convert(LocalDateTime& val) const; virtual void convert(Timestamp& val) const; void convert(long& val) const; void convert(unsigned long& val) const; virtual void convert(bool& val) const; virtual void convert(float& val) const; virtual void convert(double& val) const; virtual void convert(char& val) const; virtual void convert(std::string& val) const; virtual void convert(Poco::UTF16String& val) const; virtual bool isArray() const; virtual bool isVector() const; virtual bool isList() const; virtual bool isDeque() const; virtual bool isStruct() const; virtual bool isInteger() const; virtual bool isSigned() const; virtual bool isNumeric() const; virtual bool isBoolean() const; virtual bool isString() const; virtual std::size_t size() const; protected: // methods template <typename T> VarHolder* cloneHolder( Placeholder<VarHolder>* pVarHolder, const T& val ) const; template < typename F, typename T > void convertToSmaller( const F& from, T& to ) const; template < typename F, typename T > void convertToSmallerUnsigned( const F& from, T& to ) const; template < typename F, typename T > void convertSignedToUnsigned( const F& from, T& to ) const; template < typename F, typename T > void convertSignedFloatToUnsigned( const F& from, T& to ) const; template < typename F, typename T > void convertUnsignedToSigned( const F& from, T& to ) const; }; // direct descendants template <typename T> class VarHolderImpl; template <> class VarHolderImpl<bool>; template <> class VarHolderImpl<char>; template <> class VarHolderImpl<DateTime>; template <> class VarHolderImpl<double>; template <> class VarHolderImpl<float>; template <> class VarHolderImpl<Int16>; template <> class VarHolderImpl<Int32>; template <> class VarHolderImpl<Int64>; template <> class VarHolderImpl<Int8>; template <> class VarHolderImpl<JSON::Array>; template <> class VarHolderImpl<JSON::Array::Ptr>; template <> class VarHolderImpl<JSON::Object>; template <> class VarHolderImpl<JSON::Object::Ptr>; template <> class VarHolderImpl<LocalDateTime>; template <> class VarHolderImpl<long>; template <> class VarHolderImpl<Pair<int>>; template <> class VarHolderImpl<Pair<std::string>>; template <typename T> class VarHolderImpl<std::deque<T>>; template <typename T> class VarHolderImpl<std::list<T>>; template <> class VarHolderImpl<std::string>; template <typename T> class VarHolderImpl<std::vector<T>>; template <> class VarHolderImpl<Struct<int>>; template <> class VarHolderImpl<Struct<std::string>>; template <> class VarHolderImpl<Timestamp>; template <> class VarHolderImpl<UInt16>; template <> class VarHolderImpl<UInt32>; template <> class VarHolderImpl<UInt64>; template <> class VarHolderImpl<UInt8>; template <> class VarHolderImpl<unsigned long>; template <> class VarHolderImpl<UTF16String>;
Detailed Documentation
Interface for a data holder used by the Var class.
Provides methods to convert between data types. Only data types for which VarHolder specialization exists are supported.
Provided are specializations for all C++ built-in types with addition of std::string, Poco::UTF16String, DateTime, LocalDateTime, Timestamp, std::vector<Var> and DynamicStruct.
Additional types can be supported by adding specializations. When implementing specializations, the only condition is that they reside in Poco namespace and implement the pure virtual functions clone() and type().
Those conversions that are not implemented shall fail back to this base class implementation. All the convert() function overloads in this class throw BadCastException.
Methods
virtual VarHolder* clone(Placeholder<VarHolder>* pHolder = 0) const = 0
Implementation must implement this function to deep-copy the VarHolder.
If small object optimization is enabled (i.e. if POCO_NO_SOO is not defined), VarHolder will be instantiated in-place if it’s size is smaller than POCO_SMALL_OBJECT_SIZE.
virtual const std::type_info& type() const = 0
Implementation must return the type information (typeid) for the stored content.
virtual void convert(Int8& val) const
Throws BadCastException.
Must be overriden in a type specialization in order to suport the conversion.
virtual void convert(Int16& val) const
Throws BadCastException.
Must be overriden in a type specialization in order to suport the conversion.
virtual void convert(Int32& val) const
Throws BadCastException.
Must be overriden in a type specialization in order to suport the conversion.
virtual void convert(Int64& val) const
Throws BadCastException.
Must be overriden in a type specialization in order to suport the conversion.
virtual void convert(UInt8& val) const
Throws BadCastException.
Must be overriden in a type specialization in order to suport the conversion.
virtual void convert(UInt16& val) const
Throws BadCastException.
Must be overriden in a type specialization in order to suport the conversion.
virtual void convert(UInt32& val) const
Throws BadCastException.
Must be overriden in a type specialization in order to suport the conversion.
virtual void convert(UInt64& val) const
Throws BadCastException.
Must be overriden in a type specialization in order to suport the conversion.
virtual void convert(DateTime& val) const
Throws BadCastException.
Must be overriden in a type specialization in order to suport the conversion.
virtual void convert(LocalDateTime& val) const
Throws BadCastException.
Must be overriden in a type specialization in order to suport the conversion.
virtual void convert(Timestamp& val) const
Throws BadCastException.
Must be overriden in a type specialization in order to suport the conversion.
void convert(long& val) const
Calls convert(Int32).
void convert(unsigned long& val) const
Calls convert(UInt32).
virtual void convert(bool& val) const
Throws BadCastException.
Must be overriden in a type specialization in order to suport the conversion.
virtual void convert(float& val) const
Throws BadCastException.
Must be overriden in a type specialization in order to suport the conversion.
virtual void convert(double& val) const
Throws BadCastException.
Must be overriden in a type specialization in order to suport the conversion.
virtual void convert(char& val) const
Throws BadCastException.
Must be overriden in a type specialization in order to suport the conversion.
virtual void convert(std::string& val) const
Throws BadCastException.
Must be overriden in a type specialization in order to suport the conversion.
virtual void convert(Poco::UTF16String& val) const
Throws BadCastException.
Must be overriden in a type specialization in order to suport the conversion.
virtual bool isArray() const
Returns true.
virtual bool isVector() const
Returns false.
Must be properly overriden in a type specialization in order to suport the diagnostic.
virtual bool isList() const
Returns false.
Must be properly overriden in a type specialization in order to suport the diagnostic.
virtual bool isDeque() const
Returns false.
Must be properly overriden in a type specialization in order to suport the diagnostic.
virtual bool isStruct() const
Returns false.
Must be properly overriden in a type specialization in order to suport the diagnostic.
virtual bool isInteger() const
Returns false.
Must be properly overriden in a type specialization in order to suport the diagnostic.
virtual bool isSigned() const
Returns false.
Must be properly overriden in a type specialization in order to suport the diagnostic.
virtual bool isNumeric() const
Returns false.
Must be properly overriden in a type specialization in order to suport the diagnostic.
virtual bool isBoolean() const
Returns false.
Must be properly overriden in a type specialization in order to suport the diagnostic.
virtual bool isString() const
Returns false.
Must be properly overriden in a type specialization in order to suport the diagnostic.
virtual std::size_t size() const
Returns 1 iff Var is not empty or this function overriden.
template <typename T> VarHolder* cloneHolder( Placeholder<VarHolder>* pVarHolder, const T& val ) const
Instantiates value holder wrapper.
If size of the wrapper is larger than POCO_SMALL_OBJECT_SIZE, holder is instantiated on the heap, otherwise it is instantiated in-place (in the pre-allocated buffer inside the holder).
Called from clone() member function of the implementation when smal object optimization is enabled.
template < typename F, typename T > void convertToSmaller( const F& from, T& to ) const
This function is meant to convert signed numeric values from larger to smaller type.
It checks the upper and lower bound and if from value is within limits of type T (i.e. check calls do not throw), it is converted.
template < typename F, typename T > void convertToSmallerUnsigned( const F& from, T& to ) const
This function is meant for converting unsigned integral data types, from larger to smaller type.
Since lower limit is always 0 for unigned types, only the upper limit is checked, thus saving some cycles compared to the signed version of the function. If the value to be converted is smaller than the maximum value for the target type, the conversion is performed.
template < typename F, typename T > void convertSignedToUnsigned( const F& from, T& to ) const
This function is meant for converting signed integral data types to unsigned data types.
Negative values can not be converted and if one is encountered, RangeException is thrown. If upper limit is within the target data type limits, the conversion is performed.
template < typename F, typename T > void convertSignedFloatToUnsigned( const F& from, T& to ) const
This function is meant for converting floating point data types to unsigned integral data types.
Negative values can not be converted and if one is encountered, RangeException is thrown. If uper limit is within the target data type limits, the conversion is performed.
template < typename F, typename T > void convertUnsignedToSigned( const F& from, T& to ) const
This function is meant for converting unsigned integral data types to unsigned data types.
Negative values can not be converted and if one is encountered, RangeException is thrown. If upper limit is within the target data type limits, the converiosn is performed.