mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-25 02:06:04 +02:00
Arithmetic operators for DynamicAny
This commit is contained in:
@@ -69,19 +69,147 @@ DynamicAny::~DynamicAny()
|
||||
}
|
||||
|
||||
|
||||
void DynamicAny::swap(DynamicAny& ptr)
|
||||
DynamicAny& DynamicAny::operator = (const DynamicAny& other)
|
||||
{
|
||||
std::swap(_pHolder, ptr._pHolder);
|
||||
DynamicAny tmp(other);
|
||||
swap(tmp);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
const std::type_info& DynamicAny::type() const
|
||||
DynamicAny DynamicAny::operator + (const DynamicAny& other) const
|
||||
{
|
||||
return _pHolder->type();
|
||||
if (isInteger())
|
||||
{
|
||||
if(isSigned())
|
||||
return add<Poco::Int64>(other);
|
||||
else
|
||||
return add<Poco::UInt64>(other);
|
||||
}
|
||||
else if (isNumeric())
|
||||
return add<double>(other);
|
||||
else if (isString())
|
||||
return add<std::string>(other);
|
||||
else
|
||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||
}
|
||||
|
||||
|
||||
DynamicAny& DynamicAny::operator[](std::vector<DynamicAny>::size_type n)
|
||||
DynamicAny& DynamicAny::operator += (const DynamicAny& other)
|
||||
{
|
||||
if (isInteger())
|
||||
{
|
||||
if(isSigned())
|
||||
return *this = add<Poco::Int64>(other);
|
||||
else
|
||||
return *this = add<Poco::UInt64>(other);
|
||||
}
|
||||
else if (isNumeric())
|
||||
return *this = add<double>(other);
|
||||
else if (isString())
|
||||
return *this = add<std::string>(other);
|
||||
else
|
||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||
}
|
||||
|
||||
|
||||
DynamicAny DynamicAny::operator - (const DynamicAny& other) const
|
||||
{
|
||||
if (isInteger())
|
||||
{
|
||||
if(isSigned())
|
||||
return subtract<Poco::Int64>(other);
|
||||
else
|
||||
return subtract<Poco::UInt64>(other);
|
||||
}
|
||||
else if (isNumeric())
|
||||
return subtract<double>(other);
|
||||
else
|
||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||
}
|
||||
|
||||
|
||||
DynamicAny& DynamicAny::operator -= (const DynamicAny& other)
|
||||
{
|
||||
if (isInteger())
|
||||
{
|
||||
if(isSigned())
|
||||
return *this = subtract<Poco::Int64>(other);
|
||||
else
|
||||
return *this = subtract<Poco::UInt64>(other);
|
||||
}
|
||||
else if (isNumeric())
|
||||
return *this = subtract<double>(other);
|
||||
else
|
||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||
}
|
||||
|
||||
|
||||
DynamicAny DynamicAny::operator * (const DynamicAny& other) const
|
||||
{
|
||||
if (isInteger())
|
||||
{
|
||||
if(isSigned())
|
||||
return multiply<Poco::Int64>(other);
|
||||
else
|
||||
return multiply<Poco::UInt64>(other);
|
||||
}
|
||||
else if (isNumeric())
|
||||
return multiply<double>(other);
|
||||
else
|
||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||
}
|
||||
|
||||
|
||||
DynamicAny& DynamicAny::operator *= (const DynamicAny& other)
|
||||
{
|
||||
if (isInteger())
|
||||
{
|
||||
if(isSigned())
|
||||
return *this = multiply<Poco::Int64>(other);
|
||||
else
|
||||
return *this = multiply<Poco::UInt64>(other);
|
||||
}
|
||||
else if (isNumeric())
|
||||
return *this = multiply<double>(other);
|
||||
else
|
||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||
}
|
||||
|
||||
|
||||
DynamicAny DynamicAny::operator / (const DynamicAny& other) const
|
||||
{
|
||||
if (isInteger())
|
||||
{
|
||||
if(isSigned())
|
||||
return divide<Poco::Int64>(other);
|
||||
else
|
||||
return divide<Poco::UInt64>(other);
|
||||
}
|
||||
else if (isNumeric())
|
||||
return divide<double>(other);
|
||||
else
|
||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||
}
|
||||
|
||||
|
||||
DynamicAny& DynamicAny::operator /= (const DynamicAny& other)
|
||||
{
|
||||
if (isInteger())
|
||||
{
|
||||
if(isSigned())
|
||||
return *this = divide<Poco::Int64>(other);
|
||||
else
|
||||
return *this = divide<Poco::UInt64>(other);
|
||||
}
|
||||
else if (isNumeric())
|
||||
return *this = divide<double>(other);
|
||||
else
|
||||
throw InvalidArgumentException("Invalid operation for this data type.");
|
||||
}
|
||||
|
||||
|
||||
DynamicAny& DynamicAny::operator [] (std::vector<DynamicAny>::size_type n)
|
||||
{
|
||||
DynamicAnyHolderImpl<std::vector<DynamicAny> >* pHolder = dynamic_cast<DynamicAnyHolderImpl<std::vector<DynamicAny> > *>(_pHolder);
|
||||
if (pHolder)
|
||||
@@ -91,7 +219,7 @@ DynamicAny& DynamicAny::operator[](std::vector<DynamicAny>::size_type n)
|
||||
}
|
||||
|
||||
|
||||
const DynamicAny& DynamicAny::operator[](std::vector<DynamicAny>::size_type n) const
|
||||
const DynamicAny& DynamicAny::operator [] (std::vector<DynamicAny>::size_type n) const
|
||||
{
|
||||
const DynamicAnyHolderImpl<std::vector<DynamicAny> >* pHolder = dynamic_cast<const DynamicAnyHolderImpl<std::vector<DynamicAny> > *>(_pHolder);
|
||||
if (pHolder)
|
||||
@@ -101,8 +229,7 @@ const DynamicAny& DynamicAny::operator[](std::vector<DynamicAny>::size_type n) c
|
||||
}
|
||||
|
||||
|
||||
|
||||
DynamicAny& DynamicAny::operator[](const std::string& name)
|
||||
DynamicAny& DynamicAny::operator [] (const std::string& name)
|
||||
{
|
||||
DynamicAnyHolderImpl<DynamicStruct>* pHolder = dynamic_cast<DynamicAnyHolderImpl<DynamicStruct> *>(_pHolder);
|
||||
if (pHolder)
|
||||
@@ -112,7 +239,7 @@ DynamicAny& DynamicAny::operator[](const std::string& name)
|
||||
}
|
||||
|
||||
|
||||
const DynamicAny& DynamicAny::operator[](const std::string& name) const
|
||||
const DynamicAny& DynamicAny::operator [] (const std::string& name) const
|
||||
{
|
||||
const DynamicAnyHolderImpl<DynamicStruct>* pHolder = dynamic_cast<const DynamicAnyHolderImpl<DynamicStruct>* >(_pHolder);
|
||||
if (pHolder)
|
||||
|
||||
Reference in New Issue
Block a user