Library: Foundation
Package: Dynamic
Header: Poco/Dynamic/VarHolder.h
Description
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.
Inheritance
Known Derived Classes: VarHolderImpl
Member Summary
Member Functions: clone, cloneHolder, convert, convertSignedFloatToUnsigned, convertSignedToUnsigned, convertToFP, convertToSigned, convertToSmaller, convertToUnsigned, convertUnsignedToSigned, isArray, isBoolean, isDate, isDateTime, isDeque, isInteger, isList, isNumeric, isOrdered, isSigned, isString, isStruct, isTime, isUUID, isVector, size, type
Types Aliases
ArrayValueType
using ArrayValueType = Var;
Constructors
VarHolder
VarHolder();
Creates the VarHolder.
Destructor
~VarHolder
virtual ~VarHolder();
Destroys the VarHolder.
Member Functions
clone
virtual VarHolder * clone(
Placeholder < VarHolder > * pHolder = nullptr
) 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.
convert
virtual void convert(
Int8 & val
) const;
Throws BadCastException. Must be overridden in a type specialization in order to support the conversion.
convert
virtual void convert(
Int16 & val
) const;
Throws BadCastException. Must be overridden in a type specialization in order to support the conversion.
convert
virtual void convert(
Int32 & val
) const;
Throws BadCastException. Must be overridden in a type specialization in order to support the conversion.
convert
virtual void convert(
Int64 & val
) const;
Throws BadCastException. Must be overridden in a type specialization in order to support the conversion.
convert
virtual void convert(
UInt8 & val
) const;
Throws BadCastException. Must be overridden in a type specialization in order to support the conversion.
convert
virtual void convert(
UInt16 & val
) const;
Throws BadCastException. Must be overridden in a type specialization in order to support the conversion.
convert
virtual void convert(
UInt32 & val
) const;
Throws BadCastException. Must be overridden in a type specialization in order to support the conversion.
convert
virtual void convert(
UInt64 & val
) const;
Throws BadCastException. Must be overridden in a type specialization in order to support the conversion.
convert
virtual void convert(
DateTime & val
) const;
Throws BadCastException. Must be overridden in a type specialization in order to support the conversion.
convert
virtual void convert(
LocalDateTime & val
) const;
Throws BadCastException. Must be overridden in a type specialization in order to support the conversion.
convert
virtual void convert(
Timestamp & val
) const;
Throws BadCastException. Must be overridden in a type specialization in order to support the conversion.
convert
virtual void convert(
UUID & val
) const;
Throws BadCastException. Must be overridden in a type specialization in order to support the conversion.
convert
virtual void convert(
long long & val
) const;
Throws BadCastException. Must be overridden in a type specialization in order to suport the conversion.
convert
virtual void convert(
unsigned long long & val
) const;
Throws BadCastException. Must be overridden in a type specialization in order to suport the conversion.
convert
virtual void convert(
bool & val
) const;
Throws BadCastException. Must be overridden in a type specialization in order to support the conversion.
convert
virtual void convert(
float & val
) const;
Throws BadCastException. Must be overridden in a type specialization in order to support the conversion.
convert
virtual void convert(
double & val
) const;
Throws BadCastException. Must be overridden in a type specialization in order to support the conversion.
convert
virtual void convert(
char & val
) const;
Throws BadCastException. Must be overridden in a type specialization in order to support the conversion.
convert
virtual void convert(
std::string & val
) const;
Throws BadCastException. Must be overridden in a type specialization in order to support the conversion.
convert
virtual void convert(
Poco::UTF16String & val
) const;
Throws BadCastException. Must be overridden in a type specialization in order to support the conversion.
isArray
virtual bool isArray() const;
Returns true.
isBoolean
virtual bool isBoolean() const;
Returns false. Must be properly overridden in a type specialization in order to support the diagnostic.
isDate
virtual bool isDate() const;
Returns false. Must be properly overridden in a type specialization in order to support the diagnostic.
isDateTime
virtual bool isDateTime() const;
Returns false. Must be properly overridden in a type specialization in order to support the diagnostic.
isDeque
virtual bool isDeque() const;
Returns false. Must be properly overridden in a type specialization in order to support the diagnostic.
isInteger
virtual bool isInteger() const;
Returns false. Must be properly overridden in a type specialization in order to support the diagnostic.
isList
virtual bool isList() const;
Returns false. Must be properly overridden in a type specialization in order to support the diagnostic.
isNumeric
virtual bool isNumeric() const;
Returns false. Must be properly overridden in a type specialization in order to support the diagnostic.
isOrdered
virtual bool isOrdered() const;
Returns false. Must be properly overridden in a type specialization in order to support the diagnostic.
isSigned
virtual bool isSigned() const;
Returns false. Must be properly overridden in a type specialization in order to support the diagnostic.
isString
virtual bool isString() const;
Returns false. Must be properly overridden in a type specialization in order to support the diagnostic.
isStruct
virtual bool isStruct() const;
Returns false. Must be properly overridden in a type specialization in order to support the diagnostic.
isTime
virtual bool isTime() const;
Returns false. Must be properly overridden in a type specialization in order to support the diagnostic.
isUUID
virtual bool isUUID() const;
Returns false. Must be properly overridden in a type specialization in order to support the diagnostic.
isVector
virtual bool isVector() const;
Returns false. Must be properly overridden in a type specialization in order to support the diagnostic.
size
virtual std::size_t size() const;
Returns 1 iff Var is not empty or this function overridden.
type
virtual const std::type_info & type() const = 0;
Implementation must return the type information (typeid) for the stored content.
cloneHolder
template < typename T > VarHolder * cloneHolder(
Placeholder < VarHolder > * pVarHolder,
const T & val
) const;
Instantiates value holder wrapper.
Called from clone() member function of the implementation.
When the smal object optimization is enabled (POCO_NO_SOO not defined), 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).
convertSignedFloatToUnsigned
template < typename F, typename T, std::enable_if_t < std::is_floating_point_v < F >, bool > = true, std::enable_if_t < std::is_integral_v < T > && ! std::is_signed_v < T >, T > * = nullptr > static void convertSignedFloatToUnsigned(
const F & from,
T & to
);
Converts floating point data types to unsigned integral 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.
convertSignedToUnsigned
template < typename F, typename T, std::enable_if_t < std::is_integral_v < F > && std::is_signed_v < F >, F > * = nullptr, std::enable_if_t < std::is_integral_v < T > && ! std::is_signed_v < T >, T > * = nullptr > static void convertSignedToUnsigned(
const F & from,
T & to
);
Converts unsigned integral data types from larger to smaller, as well as to floating-point, types. Since lower limit is always 0 for unsigned 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. Converts 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.
convertToFP
template < typename F, typename T, std::enable_if_t < std::is_integral_v < F >, bool > = true, std::enable_if_t < std::is_floating_point_v < T >, bool > = true > static void convertToFP(
F & from,
T & to
);
Converts unsigned integral data types to floating-point data types. If the number of significant digits used for the integer vaue exceeds the number of available digits in the floatinng-point destination (ie. if precision would be lost by casting the value), RangeException is thrown.
convertToSigned
template < typename F, typename T, std::enable_if_t < std::is_signed_v < F > && std::is_signed_v < T > && (sizeof (F)<= sizeof (T))> * = nullptr > void convertToSigned(
const F & from,
T & to
) const;
convertToSigned
template < typename F, typename T, std::enable_if_t < std::is_signed_v < F > && std::is_signed_v < T > && (sizeof (F)> sizeof (T))> * = nullptr > void convertToSigned(
const F & from,
T & to
) const;
convertToSigned
template < typename F, typename T, std::enable_if_t < ! std::is_signed_v < F > && std::is_signed_v < T >> * = nullptr > void convertToSigned(
const F & from,
T & to
) const;
convertToSmaller
template < typename F, typename T, std::enable_if_t < std::is_integral_v < F > && std::is_signed_v < T >, F > * = nullptr, std::enable_if_t < std::is_floating_point_v < T >, T > * = nullptr > static void convertToSmaller(
const F & from,
T & to
);
Converts signed integral, as well as floating-point, 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. Converts signed integral values from integral to floating-point type. Checks for the loss of precision and if from value is within limits of type T (i.e. check calls do not throw), it is converted.
convertToSmaller
template < typename F, typename T, std::enable_if_t < std::is_same_v < F, bool >> * = nullptr, std::enable_if_t < std::is_floating_point_v < T >, T > * = nullptr > static void convertToSmaller(
const F & from,
T & to
);
Converts boolean values to floating-point type.
convertToUnsigned
template < typename F, typename T, std::enable_if_t < ! std::is_signed_v < F > && ! std::is_signed_v < T > && (sizeof (F)<= sizeof (T))> * = nullptr > void convertToUnsigned(
const F & from,
T & to
) const;
convertToUnsigned
template < typename F, typename T, std::enable_if_t < ! std::is_signed_v < F > && ! std::is_signed_v < T > && (sizeof (F)> sizeof (T))> * = nullptr > void convertToUnsigned(
const F & from,
T & to
) const;
convertToUnsigned
template < typename F, typename T, std::enable_if_t < std::is_signed_v < F > && ! std::is_signed_v < T >> * = nullptr > void convertToUnsigned(
const F & from,
T & to
) const;
convertUnsignedToSigned
template < typename F, typename T, std::enable_if_t < std::is_integral_v < F > && ! std::is_signed_v < F >, F > * = nullptr, std::enable_if_t < std::is_integral_v < T > && std::is_signed_v < T >, T > * = nullptr > static void convertUnsignedToSigned(
const F & from,
T & to
);
Converts unsigned integral data types to signed integral data types. If upper limit is within the target data type limits, the conversion is performed.