Skip to content

Commit

Permalink
Usage modern C++ features on JSON modules (enhanced) (#4613)
Browse files Browse the repository at this point in the history
  • Loading branch information
matejk authored Jul 25, 2024
1 parent 891c1e0 commit 5117e27
Show file tree
Hide file tree
Showing 19 changed files with 286 additions and 368 deletions.
98 changes: 47 additions & 51 deletions JSON/include/Poco/JSON/Array.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class JSON_API Array
private:
void resetDynArray() const;

typedef SharedPtr<Poco::Dynamic::Array> ArrayPtr;
using ArrayPtr = SharedPtr<Poco::Dynamic::Array>;

ValueVec _values;
mutable ArrayPtr _pArray;
Expand Down Expand Up @@ -340,98 +340,96 @@ class VarHolderImpl<JSON::Array::Ptr>: public VarHolder
{
}

~VarHolderImpl()
{
}
~VarHolderImpl() override = default;

const std::type_info& type() const
const std::type_info& type() const override
{
return typeid(JSON::Array::Ptr);
}

void convert(Int8&) const
void convert(Int8&) const override
{
throw BadCastException();
}

void convert(Int16&) const
void convert(Int16&) const override
{
throw BadCastException();
}

void convert(Int32&) const
void convert(Int32&) const override
{
throw BadCastException();
}

void convert(Int64&) const
void convert(Int64&) const override
{
throw BadCastException();
}

void convert(UInt8&) const
void convert(UInt8&) const override
{
throw BadCastException();
}

void convert(UInt16&) const
void convert(UInt16&) const override
{
throw BadCastException();
}

void convert(UInt32&) const
void convert(UInt32&) const override
{
throw BadCastException();
}

void convert(UInt64&) const
void convert(UInt64&) const override
{
throw BadCastException();
}

void convert(bool& value) const
void convert(bool& value) const override
{
value = !_val.isNull() && _val->size() > 0;
}

void convert(float&) const
void convert(float&) const override
{
throw BadCastException();
}

void convert(double&) const
void convert(double&) const override
{
throw BadCastException();
}

void convert(char&) const
void convert(char&) const override
{
throw BadCastException();
}

void convert(std::string& s) const
void convert(std::string& s) const override
{
std::ostringstream oss;
_val->stringify(oss);
s = oss.str();
}

void convert(DateTime& /*val*/) const
void convert(DateTime& /*val*/) const override
{
throw BadCastException("Cannot convert Array to DateTime");
}

void convert(LocalDateTime& /*ldt*/) const
void convert(LocalDateTime& /*ldt*/) const override
{
throw BadCastException("Cannot convert Array to LocalDateTime");
}

void convert(Timestamp& /*ts*/) const
void convert(Timestamp& /*ts*/) const override
{
throw BadCastException("Cannot convert Array to Timestamp");
}

VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
VarHolder* clone(Placeholder<VarHolder>* pVarHolder = nullptr) const override
{
return cloneHolder(pVarHolder, _val);
}
Expand All @@ -441,22 +439,22 @@ class VarHolderImpl<JSON::Array::Ptr>: public VarHolder
return _val;
}

bool isInteger() const
bool isInteger() const override
{
return false;
}

bool isSigned() const
bool isSigned() const override
{
return false;
}

bool isNumeric() const
bool isNumeric() const override
{
return false;
}

bool isString() const
bool isString() const override
{
return false;
}
Expand All @@ -474,98 +472,96 @@ class VarHolderImpl<JSON::Array>: public VarHolder
{
}

~VarHolderImpl()
{
}
~VarHolderImpl() override = default;

const std::type_info& type() const
const std::type_info& type() const override
{
return typeid(JSON::Array);
}

void convert(Int8&) const
void convert(Int8&) const override
{
throw BadCastException();
}

void convert(Int16&) const
void convert(Int16&) const override
{
throw BadCastException();
}

void convert(Int32&) const
void convert(Int32&) const override
{
throw BadCastException();
}

void convert(Int64&) const
void convert(Int64&) const override
{
throw BadCastException();
}

void convert(UInt8&) const
void convert(UInt8&) const override
{
throw BadCastException();
}

void convert(UInt16&) const
void convert(UInt16&) const override
{
throw BadCastException();
}

void convert(UInt32&) const
void convert(UInt32&) const override
{
throw BadCastException();
}

void convert(UInt64&) const
void convert(UInt64&) const override
{
throw BadCastException();
}

void convert(bool& value) const
void convert(bool& value) const override
{
value = _val.size() > 0;
}

void convert(float&) const
void convert(float&) const override
{
throw BadCastException();
}

void convert(double&) const
void convert(double&) const override
{
throw BadCastException();
}

void convert(char&) const
void convert(char&) const override
{
throw BadCastException();
}

void convert(std::string& s) const
void convert(std::string& s) const override
{
std::ostringstream oss;
_val.stringify(oss);
s = oss.str();
}

void convert(DateTime& /*val*/) const
void convert(DateTime& /*val*/) const override
{
throw BadCastException("Cannot convert Array to DateTime");
}

void convert(LocalDateTime& /*ldt*/) const
void convert(LocalDateTime& /*ldt*/) const override
{
throw BadCastException("Cannot convert Array to LocalDateTime");
}

void convert(Timestamp& /*ts*/) const
void convert(Timestamp& /*ts*/) const override
{
throw BadCastException("Cannot convert Array to Timestamp");
}

VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
VarHolder* clone(Placeholder<VarHolder>* pVarHolder = nullptr) const override
{
return cloneHolder(pVarHolder, _val);
}
Expand All @@ -575,22 +571,22 @@ class VarHolderImpl<JSON::Array>: public VarHolder
return _val;
}

bool isInteger() const
bool isInteger() const override
{
return false;
}

bool isSigned() const
bool isSigned() const override
{
return false;
}

bool isNumeric() const
bool isNumeric() const override
{
return false;
}

bool isString() const
bool isString() const override
{
return false;
}
Expand Down
Loading

0 comments on commit 5117e27

Please sign in to comment.