📄 dynamicanyholder.h
字号:
void convert(Int16& val) const
{
convertToSmaller(_val, val);
}
void convert(Int32& val) const
{
convertToSmaller(_val, val);
}
void convert(Int64& val) const
{
convertToSmaller(_val, val);
}
void convert(UInt8& val) const
{
convertSignedToUnsigned(_val, val);
}
void convert(UInt16& val) const
{
convertSignedToUnsigned(_val, val);
}
void convert(UInt32& val) const
{
convertSignedToUnsigned(_val, val);
}
void convert(UInt64& val) const
{
convertSignedToUnsigned(_val, val);
}
void convert(bool& val) const
{
val = !(_val <= std::numeric_limits<float>::min() &&
_val >= -1 * std::numeric_limits<float>::min());
}
void convert(float& val) const
{
val = _val;
}
void convert(double& val) const
{
val = _val;
}
void convert(char& val) const
{
UInt8 tmp;
convert(tmp);
val = static_cast<char>(tmp);
}
void convert(std::string& val) const
{
val = NumberFormatter::format(_val);
}
DynamicAnyHolder* clone() const
{
return new DynamicAnyHolderImpl(_val);
}
const float& value() const
{
return _val;
}
private:
float _val;
};
template <>
class DynamicAnyHolderImpl<double>: public DynamicAnyHolder
{
public:
DynamicAnyHolderImpl(double val): _val(val)
{
}
~DynamicAnyHolderImpl()
{
}
const std::type_info& type() const
{
return typeid(double);
}
void convert(Int8& val) const
{
convertToSmaller(_val, val);
}
void convert(Int16& val) const
{
convertToSmaller(_val, val);
}
void convert(Int32& val) const
{
convertToSmaller(_val, val);
}
void convert(Int64& val) const
{
convertToSmaller(_val, val);
}
void convert(UInt8& val) const
{
convertSignedToUnsigned(_val, val);
}
void convert(UInt16& val) const
{
convertSignedToUnsigned(_val, val);
}
void convert(UInt32& val) const
{
convertSignedToUnsigned(_val, val);
}
void convert(UInt64& val) const
{
convertSignedToUnsigned(_val, val);
}
void convert(bool& val) const
{
val = !(_val <= std::numeric_limits<double>::min() &&
_val >= -1 * std::numeric_limits<double>::min());
}
void convert(float& val) const
{
double fMin = -1 * std::numeric_limits<float>::max();
double fMax = std::numeric_limits<float>::max();
if (_val < fMin) throw RangeException("Value too small.");
if (_val > fMax) throw RangeException("Value too large.");
val = static_cast<float>(_val);
}
void convert(double& val) const
{
val = _val;
}
void convert(char& val) const
{
UInt8 tmp;
convert(tmp);
val = static_cast<char>(tmp);
}
void convert(std::string& val) const
{
val = NumberFormatter::format(_val);
}
DynamicAnyHolder* clone() const
{
return new DynamicAnyHolderImpl(_val);
}
const double& value() const
{
return _val;
}
private:
double _val;
};
template <>
class DynamicAnyHolderImpl<char>: public DynamicAnyHolder
{
public:
DynamicAnyHolderImpl(char val): _val(val)
{
}
~DynamicAnyHolderImpl()
{
}
const std::type_info& type() const
{
return typeid(char);
}
void convert(Int8& val) const
{
val = static_cast<Int8>(_val);
}
void convert(Int16& val) const
{
val = static_cast<UInt8>(_val);
}
void convert(Int32& val) const
{
val = static_cast<UInt8>(_val);
}
void convert(Int64& val) const
{
val = static_cast<UInt8>(_val);
}
void convert(UInt8& val) const
{
val = static_cast<UInt8>(_val);
}
void convert(UInt16& val) const
{
val = static_cast<UInt8>(_val);
}
void convert(UInt32& val) const
{
val = static_cast<UInt8>(_val);
}
void convert(UInt64& val) const
{
val = static_cast<UInt8>(_val);
}
void convert(bool& val) const
{
val = (_val != '\0');
}
void convert(float& val) const
{
val = static_cast<float>(_val);
}
void convert(double& val) const
{
val = static_cast<double>(_val);
}
void convert(char& val) const
{
val = _val;
}
void convert(std::string& val) const
{
val = std::string(1, _val);
}
DynamicAnyHolder* clone() const
{
return new DynamicAnyHolderImpl(_val);
}
const char& value() const
{
return _val;
}
private:
char _val;
};
template <>
class DynamicAnyHolderImpl<std::string>: public DynamicAnyHolder
{
public:
DynamicAnyHolderImpl(const char* pVal): _val(pVal)
{
}
DynamicAnyHolderImpl(const std::string& val): _val(val)
{
}
~DynamicAnyHolderImpl()
{
}
const std::type_info& type() const
{
return typeid(std::string);
}
void convert(Int8& val) const
{
int v = NumberParser::parse(_val);
convertToSmaller(v, val);
}
void convert(Int16& val) const
{
int v = NumberParser::parse(_val);
convertToSmaller(v, val);
}
void convert(Int32& val) const
{
val = NumberParser::parse(_val);
}
void convert(Int64& val) const
{
val = NumberParser::parse64(_val);
}
void convert(UInt8& val) const
{
unsigned int v = NumberParser::parseUnsigned(_val);
convertToSmallerUnsigned(v, val);
}
void convert(UInt16& val) const
{
unsigned int v = NumberParser::parseUnsigned(_val);
convertToSmallerUnsigned(v, val);
}
void convert(UInt32& val) const
{
val = NumberParser::parseUnsigned(_val);
}
void convert(UInt64& val) const
{
val = NumberParser::parseUnsigned64(_val);
}
void convert(bool& val) const
{
static const std::string VAL_FALSE("false");
static const std::string VAL_INTFALSE("0");
if (_val == VAL_INTFALSE || (icompare(_val, VAL_FALSE) == 0))
val = false;
else
val = true;
}
void convert(float& val) const
{
double v = NumberParser::parseFloat(_val);
convertToSmaller(v, val);
}
void convert(double& val) const
{
val = NumberParser::parseFloat(_val);
}
void convert(char& val) const
{
if (_val.empty())
val = '\0';
else
val = _val[0];
}
void convert(std::string& val) const
{
val = _val;
}
DynamicAnyHolder* clone() const
{
return new DynamicAnyHolderImpl(_val);
}
const std::string& value() const
{
return _val;
}
private:
std::string _val;
};
#ifndef POCO_LONG_IS_64_BIT
template <>
class DynamicAnyHolderImpl<long>: public DynamicAnyHolder
{
public:
DynamicAnyHolderImpl(long val): _val(val)
{
}
~DynamicAnyHolderImpl()
{
}
const std::type_info& type() const
{
return typeid(long);
}
void convert(Int8& val) const
{
convertToSmaller(_val, val);
}
void convert(Int16& val) const
{
convertToSmaller(_val, val);
}
void convert(Int32& val) const
{
val = static_cast<Int32>(_val);
}
void convert(Int64& val) const
{
val = static_cast<Int64>(_val);
}
void convert(UInt8& val) const
{
convertSignedToUnsigned(_val, val);
}
void convert(UInt16& val) const
{
convertSignedToUnsigned(_val, val);
}
void convert(UInt32& val) const
{
convertSignedToUnsigned(_val, val);
}
void convert(UInt64& val) const
{
convertSignedToUnsigned(_val, val);
}
void convert(bool& val) const
{
val = (_val != 0);
}
void convert(float& val) const
{
val = static_cast<float>(_val);
}
void convert(double& val) const
{
val = static_cast<double>(_val);
}
void convert(char& val) const
{
UInt8 tmp;
convert(tmp);
val = static_cast<char>(tmp);
}
void convert(std::string& val) const
{
val = NumberFormatter::format(_val);
}
DynamicAnyHolder* clone() const
{
return new DynamicAnyHolderImpl(_val);
}
const long& value() const
{
return _val;
}
private:
long _val;
};
template <>
class DynamicAnyHolderImpl<unsigned long>: public DynamicAnyHolder
{
public:
DynamicAnyHolderImpl(unsigned long val): _val(val)
{
}
~DynamicAnyHolderImpl()
{
}
const std::type_info& type() const
{
return typeid(unsigned long);
}
void convert(Int8& val) const
{
convertUnsignedToSigned(_val, val);
}
void convert(Int16& val) const
{
convertUnsignedToSigned(_val, val);
}
void convert(Int32& val) const
{
convertUnsignedToSigned(_val, val);
}
void convert(Int64& val) const
{
convertUnsignedToSigned(_val, val);
}
void convert(UInt8& val) const
{
convertToSmallerUnsigned(_val, val);
}
void convert(UInt16& val) const
{
convertToSmallerUnsigned(_val, val);
}
void convert(UInt32& val) const
{
convertToSmallerUnsigned(_val, val);
}
void convert(UInt64& val) const
{
val = static_cast<UInt64>(_val);
}
void convert(bool& val) const
{
val = (_val != 0);
}
void convert(float& val) const
{
val = static_cast<float>(_val);
}
void convert(double& val) const
{
val = static_cast<double>(_val);
}
void convert(char& val) const
{
UInt8 tmp;
convert(tmp);
val = static_cast<char>(tmp);
}
void convert(std::string& val) const
{
val = NumberFormatter::format(_val);
}
DynamicAnyHolder* clone() const
{
return new DynamicAnyHolderImpl(_val);
}
const unsigned long& value() const
{
return _val;
}
private:
unsigned long _val;
};
#endif // 64bit
} // namespace Poco
#endif // Foundation_DynamicAnyHolder_INCLUDED
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -