From f08b7431e4fbf6cb02774918fa26e80c39ed2b6f Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Fri, 15 Apr 2016 21:16:15 +0200 Subject: [PATCH] [DEV] change dependency on ememeory instead of std::memory --- doxy_ejson.py | 3 + ejson/Array.cpp | 124 ++++++++++++++-------------- ejson/Array.h | 44 +++++----- ejson/Boolean.cpp | 19 ++--- ejson/Boolean.h | 8 +- ejson/Null.cpp | 20 ++--- ejson/Null.h | 8 +- ejson/Number.cpp | 19 ++--- ejson/Number.h | 8 +- ejson/Object.cpp | 136 +++++++++++++++---------------- ejson/Object.h | 70 +++++++++------- ejson/String.cpp | 22 ++--- ejson/String.h | 8 +- ejson/Value.cpp | 93 +++++++++++++-------- ejson/Value.h | 204 ++++++++++++++++------------------------------ ejson/ejson.cpp | 16 ++-- ejson/ejson.h | 8 +- lutin_ejson.py | 4 +- test/test.cpp | 4 - 19 files changed, 383 insertions(+), 435 deletions(-) diff --git a/doxy_ejson.py b/doxy_ejson.py index 662222e..94b67f2 100644 --- a/doxy_ejson.py +++ b/doxy_ejson.py @@ -12,9 +12,12 @@ def create(target, module_name): my_module.set_website_sources("http://github.com/atria-soft/" + module_name) my_module.add_path([ module_name, + "doc" ]) my_module.add_module_depend([ + 'elog', 'etk', + 'ememory' ]) my_module.add_exclude_symbols([ '*operator<<*', diff --git a/ejson/Array.cpp b/ejson/Array.cpp index e35a260..80f298c 100644 --- a/ejson/Array.cpp +++ b/ejson/Array.cpp @@ -16,26 +16,22 @@ #include #include -#undef __class__ -#define __class__ "Array" - - -std::shared_ptr ejson::Array::create() { - return std::shared_ptr(new ejson::Array()); +ememory::SharedPtr ejson::Array::create() { + return ememory::SharedPtr(new ejson::Array()); } void ejson::Array::clear() { m_value.clear(); } -bool ejson::Array::iParse(const std::string& _data, size_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc) { +bool ejson::Array::iParse(const std::string& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::Document& _doc) { JSON_PARSE_ELEMENT("start parse : 'Object' "); for (size_t iii=_pos+1; iii<_data.size(); iii++) { _filePos.check(_data[iii]); #ifdef ENABLE_DISPLAY_PARSED_ELEMENT drawElementParsed(_data[iii], _filePos); #endif - ejson::filePos tmpPos; + ejson::FilePos tmpPos; if( _data[iii] == ' ' || _data[iii] == '\t' || _data[iii] == '\n' @@ -56,7 +52,7 @@ bool ejson::Array::iParse(const std::string& _data, size_t& _pos, ejson::filePos } else if (_data[iii] == '{') { // find an object: JSON_PARSE_ELEMENT("find Object"); - std::shared_ptr tmpElement = ejson::Object::create(); + ememory::SharedPtr tmpElement = ejson::Object::create(); if (tmpElement == nullptr) { EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in object"); _pos=iii; @@ -68,7 +64,7 @@ bool ejson::Array::iParse(const std::string& _data, size_t& _pos, ejson::filePos || _data[iii] == '\'') { // find a string: JSON_PARSE_ELEMENT("find String quoted"); - std::shared_ptr tmpElement = ejson::String::create(); + ememory::SharedPtr tmpElement = ejson::String::create(); if (tmpElement == nullptr) { EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in String"); _pos=iii; @@ -79,7 +75,7 @@ bool ejson::Array::iParse(const std::string& _data, size_t& _pos, ejson::filePos } else if (_data[iii] == '[') { // find a list: JSON_PARSE_ELEMENT("find List"); - std::shared_ptr tmpElement = ejson::Array::create(); + ememory::SharedPtr tmpElement = ejson::Array::create(); if (tmpElement == nullptr) { EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in Array"); _pos=iii; @@ -91,7 +87,7 @@ bool ejson::Array::iParse(const std::string& _data, size_t& _pos, ejson::filePos || _data[iii] == 't' ) { // find boolean: JSON_PARSE_ELEMENT("find Boolean"); - std::shared_ptr tmpElement = ejson::Boolean::create(); + ememory::SharedPtr tmpElement = ejson::Boolean::create(); if (tmpElement == nullptr) { EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in Boolean"); _pos=iii; @@ -102,7 +98,7 @@ bool ejson::Array::iParse(const std::string& _data, size_t& _pos, ejson::filePos } else if( _data[iii] == 'n') { // find null: JSON_PARSE_ELEMENT("find Null"); - std::shared_ptr tmpElement = ejson::Null::create(); + ememory::SharedPtr tmpElement = ejson::Null::create(); if (tmpElement == nullptr) { EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in Boolean"); _pos=iii; @@ -113,7 +109,7 @@ bool ejson::Array::iParse(const std::string& _data, size_t& _pos, ejson::filePos } else if(true == checkNumber(_data[iii])) { // find number: JSON_PARSE_ELEMENT("find Number"); - std::shared_ptr tmpElement = ejson::Number::create(); + ememory::SharedPtr tmpElement = ejson::Number::create(); if (tmpElement == nullptr) { EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in Boolean"); _pos=iii; @@ -143,7 +139,7 @@ bool ejson::Array::iGenerate(std::string& _data, size_t _indent) const { oneLine=false; } else { for (size_t iii=0; iii tmp = m_value[iii]; + ememory::SharedPtr tmp = m_value[iii]; if (tmp == nullptr) { continue; } @@ -156,7 +152,7 @@ bool ejson::Array::iGenerate(std::string& _data, size_t _indent) const { break; } if (true == tmp->isString()) { - std::shared_ptr tmp2 = tmp->toString(); + ememory::SharedPtr tmp2 = tmp->toString(); if (tmp2 != nullptr) { if(tmp2->get().size()>40) { oneLine=false; @@ -194,7 +190,7 @@ bool ejson::Array::iGenerate(std::string& _data, size_t _indent) const { return true; } -bool ejson::Array::add(std::shared_ptr _element) { +bool ejson::Array::add(ememory::SharedPtr _element) { if (_element == nullptr) { JSON_ERROR("Request add on an nullptr pointer"); return false; @@ -220,12 +216,12 @@ bool ejson::Array::addNumber(double _value) { } -bool ejson::Array::transfertIn(std::shared_ptr _obj) { +bool ejson::Array::transfertIn(ememory::SharedPtr _obj) { if (_obj == nullptr) { JSON_ERROR("Request transfer on an nullptr pointer"); return false; } - std::shared_ptr other = _obj->toArray(); + ememory::SharedPtr other = _obj->toArray(); if (other == nullptr) { JSON_ERROR("Request transfer on an element that is not an array"); return false; @@ -240,14 +236,14 @@ bool ejson::Array::transfertIn(std::shared_ptr _obj) { } // TODO : Manage error ... -std::shared_ptr ejson::Array::clone() const { - std::shared_ptr output = ejson::Array::create(); +ememory::SharedPtr ejson::Array::clone() const { + ememory::SharedPtr output = ejson::Array::create(); if (output == nullptr) { JSON_ERROR("Allocation error ..."); - return std::shared_ptr(); + return ememory::SharedPtr(); } for (size_t iii=0; iii val = m_value[iii]; + ememory::SharedPtr val = m_value[iii]; if (val == nullptr) { continue; } @@ -256,103 +252,103 @@ std::shared_ptr ejson::Array::clone() const { return output; } -std::shared_ptr ejson::Array::getObject(size_t _id) { - std::shared_ptr tmpElement = m_value[_id]; +ememory::SharedPtr ejson::Array::getObject(size_t _id) { + ememory::SharedPtr tmpElement = m_value[_id]; if (tmpElement == nullptr) { - return std::shared_ptr(); + return ememory::SharedPtr(); } return tmpElement->toObject(); } -const std::shared_ptr ejson::Array::getObject(size_t _id) const { - const std::shared_ptr tmpElement = m_value[_id]; +const ememory::SharedPtr ejson::Array::getObject(size_t _id) const { + const ememory::SharedPtr tmpElement = m_value[_id]; if (tmpElement == nullptr) { - return std::shared_ptr(); + return ememory::SharedPtr(); } return tmpElement->toObject(); } -std::shared_ptr ejson::Array::getString(size_t _id) { - std::shared_ptr tmpElement = m_value[_id]; +ememory::SharedPtr ejson::Array::getString(size_t _id) { + ememory::SharedPtr tmpElement = m_value[_id]; if (tmpElement == nullptr) { - return std::shared_ptr(); + return ememory::SharedPtr(); } return tmpElement->toString(); } -const std::shared_ptr ejson::Array::getString(size_t _id) const { - const std::shared_ptr tmpElement = m_value[_id]; +const ememory::SharedPtr ejson::Array::getString(size_t _id) const { + const ememory::SharedPtr tmpElement = m_value[_id]; if (tmpElement == nullptr) { - return std::shared_ptr(); + return ememory::SharedPtr(); } return tmpElement->toString(); } -std::shared_ptr ejson::Array::getArray(size_t _id) { - std::shared_ptr tmpElement = m_value[_id]; +ememory::SharedPtr ejson::Array::getArray(size_t _id) { + ememory::SharedPtr tmpElement = m_value[_id]; if (tmpElement == nullptr) { - return std::shared_ptr(); + return ememory::SharedPtr(); } return tmpElement->toArray(); } -const std::shared_ptr ejson::Array::getArray(size_t _id) const { - const std::shared_ptr tmpElement = m_value[_id]; +const ememory::SharedPtr ejson::Array::getArray(size_t _id) const { + const ememory::SharedPtr tmpElement = m_value[_id]; if (tmpElement == nullptr) { - return std::shared_ptr(); + return ememory::SharedPtr(); } return tmpElement->toArray(); } -std::shared_ptr ejson::Array::getNull(size_t _id) { - std::shared_ptr tmpElement = m_value[_id]; +ememory::SharedPtr ejson::Array::getNull(size_t _id) { + ememory::SharedPtr tmpElement = m_value[_id]; if (tmpElement == nullptr) { - return std::shared_ptr(); + return ememory::SharedPtr(); } return tmpElement->toNull(); } -const std::shared_ptr ejson::Array::getNull(size_t _id) const { - const std::shared_ptr tmpElement = m_value[_id]; +const ememory::SharedPtr ejson::Array::getNull(size_t _id) const { + const ememory::SharedPtr tmpElement = m_value[_id]; if (tmpElement == nullptr) { - return std::shared_ptr(); + return ememory::SharedPtr(); } return tmpElement->toNull(); } -std::shared_ptr ejson::Array::getNumber(size_t _id) { - std::shared_ptr tmpElement = m_value[_id]; +ememory::SharedPtr ejson::Array::getNumber(size_t _id) { + ememory::SharedPtr tmpElement = m_value[_id]; if (tmpElement == nullptr) { - return std::shared_ptr(); + return ememory::SharedPtr(); } return tmpElement->toNumber(); } -const std::shared_ptr ejson::Array::getNumber(size_t _id) const { - const std::shared_ptr tmpElement = m_value[_id]; +const ememory::SharedPtr ejson::Array::getNumber(size_t _id) const { + const ememory::SharedPtr tmpElement = m_value[_id]; if (tmpElement == nullptr) { - return std::shared_ptr(); + return ememory::SharedPtr(); } return tmpElement->toNumber(); } -std::shared_ptr ejson::Array::getBoolean(size_t _id) { - std::shared_ptr tmpElement = m_value[_id]; +ememory::SharedPtr ejson::Array::getBoolean(size_t _id) { + ememory::SharedPtr tmpElement = m_value[_id]; if (tmpElement == nullptr) { - return std::shared_ptr(); + return ememory::SharedPtr(); } return tmpElement->toBoolean(); } -const std::shared_ptr ejson::Array::getBoolean(size_t _id) const { - const std::shared_ptr tmpElement = m_value[_id]; +const ememory::SharedPtr ejson::Array::getBoolean(size_t _id) const { + const ememory::SharedPtr tmpElement = m_value[_id]; if (tmpElement == nullptr) { - return std::shared_ptr(); + return ememory::SharedPtr(); } return tmpElement->toBoolean(); } std::string ejson::Array::getStringValue(size_t _id) { - std::shared_ptr tmpElement = getString(_id); + ememory::SharedPtr tmpElement = getString(_id); if (tmpElement == nullptr) { return ""; } @@ -361,7 +357,7 @@ std::string ejson::Array::getStringValue(size_t _id) { const std::string& ejson::Array::getStringValue(size_t _id) const { static const std::string errorValue(""); - const std::shared_ptr tmpElement = getString(_id); + const ememory::SharedPtr tmpElement = getString(_id); if (tmpElement == nullptr) { return errorValue; } @@ -369,7 +365,7 @@ const std::string& ejson::Array::getStringValue(size_t _id) const { } std::string ejson::Array::getStringValue(size_t _id, const std::string& _errorValue) const { - const std::shared_ptr tmpElement = getString(_id); + const ememory::SharedPtr tmpElement = getString(_id); if (tmpElement == nullptr) { return _errorValue; } @@ -377,7 +373,7 @@ std::string ejson::Array::getStringValue(size_t _id, const std::string& _errorVa } double ejson::Array::getNumberValue(size_t _id, double _errorValue) const { - const std::shared_ptr tmpElement = getNumber(_id); + const ememory::SharedPtr tmpElement = getNumber(_id); if (tmpElement == nullptr) { return _errorValue; } @@ -385,7 +381,7 @@ double ejson::Array::getNumberValue(size_t _id, double _errorValue) const { } bool ejson::Array::getBooleanValue(size_t _id, bool _errorValue) const { - const std::shared_ptr tmpElement = getBoolean(_id); + const ememory::SharedPtr tmpElement = getBoolean(_id); if (tmpElement == nullptr) { return _errorValue; } diff --git a/ejson/Array.h b/ejson/Array.h index 7b686dd..d5493e8 100644 --- a/ejson/Array.h +++ b/ejson/Array.h @@ -18,13 +18,13 @@ namespace ejson { */ Array() { }; public: - static std::shared_ptr create(); + static ememory::SharedPtr create(); /** * @brief destructor */ virtual ~Array() { }; private: - std::vector > m_value; //!< vector of sub elements + std::vector > m_value; //!< vector of sub elements public: /** * @brief get the number of sub element in the current one @@ -38,19 +38,19 @@ namespace ejson { * @param[in] _id Id of the element. * @return nullptr if the element does not exist. */ - std::shared_ptr get(size_t _id) { + ememory::SharedPtr get(size_t _id) { return m_value[_id]; }; //! @previous - const std::shared_ptr get(size_t _id) const{ + const ememory::SharedPtr get(size_t _id) const{ return m_value[_id]; }; //! @previous - std::shared_ptr operator[] (size_t _id) { + ememory::SharedPtr operator[] (size_t _id) { return m_value[_id]; } //! @previous - const std::shared_ptr operator[] (size_t _id) const { + const ememory::SharedPtr operator[] (size_t _id) const { return m_value[_id]; } /** @@ -58,17 +58,17 @@ namespace ejson { * @param[in] _id Id of the element. * @return nullptr if the element does not exist. */ - std::shared_ptr getObject(size_t _id); + ememory::SharedPtr getObject(size_t _id); //! @previous - const std::shared_ptr getObject(size_t _id) const; + const ememory::SharedPtr getObject(size_t _id) const; /** * @brief get the pointer on an element reference with his ID (casted in String if it is an String). * @param[in] _id Id of the element. * @return nullptr if the element does not exist. */ - std::shared_ptr getString(size_t _id); + ememory::SharedPtr getString(size_t _id); //! @previous - const std::shared_ptr getString(size_t _id) const; + const ememory::SharedPtr getString(size_t _id) const; /** * @brief get the value of the string element (if not a string return "") * @param[in] _id Id of the element. @@ -89,25 +89,25 @@ namespace ejson { * @param[in] _id Id of the element. * @return nullptr if the element does not exist. */ - std::shared_ptr getArray(size_t _id); + ememory::SharedPtr getArray(size_t _id); //! @previous - const std::shared_ptr getArray(size_t _id) const; + const ememory::SharedPtr getArray(size_t _id) const; /** * @brief get the pointer on an element reference with his ID (casted in Null if it is an Null). * @param[in] _id Id of the element. * @return nullptr if the element does not exist. */ - std::shared_ptr getNull(size_t _id); + ememory::SharedPtr getNull(size_t _id); //! @previous - const std::shared_ptr getNull(size_t _id) const; + const ememory::SharedPtr getNull(size_t _id) const; /** * @brief get the pointer on an element reference with his ID (casted in Number if it is an Number). * @param[in] _id Id of the element. * @return nullptr if the element does not exist. */ - std::shared_ptr getNumber(size_t _id); + ememory::SharedPtr getNumber(size_t _id); //! @previous - const std::shared_ptr getNumber(size_t _id) const; + const ememory::SharedPtr getNumber(size_t _id) const; /** * @brief get the value of the Number element * @param[in] _id Id of the element. @@ -120,9 +120,9 @@ namespace ejson { * @param[in] _id Id of the element. * @return nullptr if the element does not exist. */ - std::shared_ptr getBoolean(size_t _id); + ememory::SharedPtr getBoolean(size_t _id); //! @previous - const std::shared_ptr getBoolean(size_t _id) const; + const ememory::SharedPtr getBoolean(size_t _id) const; /** * @brief get the value of the Boolean element * @param[in] _id Id of the element. @@ -135,7 +135,7 @@ namespace ejson { * @param[in] _element element to add. * @return false if an error occured. */ - bool add(std::shared_ptr _element); + bool add(ememory::SharedPtr _element); /** * @brief add a string element in the Object (automatic creation) * @param[in] _value string value to add @@ -161,11 +161,11 @@ namespace ejson { bool addNumber(double _value); public: // herited function : - virtual bool iParse(const std::string& _data, size_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc); + virtual bool iParse(const std::string& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::Document& _doc); virtual bool iGenerate(std::string& _data, size_t _indent) const; virtual void clear(); - virtual bool transfertIn(std::shared_ptr _obj); - virtual std::shared_ptr clone() const; + virtual bool transfertIn(ememory::SharedPtr _obj); + virtual ememory::SharedPtr clone() const; }; } diff --git a/ejson/Boolean.cpp b/ejson/Boolean.cpp index 474455c..c53dcf7 100644 --- a/ejson/Boolean.cpp +++ b/ejson/Boolean.cpp @@ -10,15 +10,12 @@ #include #include -#undef __class__ -#define __class__ "Boolean" - -std::shared_ptr ejson::Boolean::create(bool _value) { - return std::shared_ptr(new ejson::Boolean(_value)); +ememory::SharedPtr ejson::Boolean::create(bool _value) { + return ememory::SharedPtr(new ejson::Boolean(_value)); } -bool ejson::Boolean::iParse(const std::string& _data, size_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc) { +bool ejson::Boolean::iParse(const std::string& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::Document& _doc) { JSON_PARSE_ELEMENT("start parse : 'Boolean' "); m_value=false; if( _data[_pos] == 't' @@ -57,12 +54,12 @@ bool ejson::Boolean::iGenerate(std::string& _data, size_t _indent) const { } -bool ejson::Boolean::transfertIn(std::shared_ptr _obj) { +bool ejson::Boolean::transfertIn(ememory::SharedPtr _obj) { if (_obj == nullptr) { JSON_ERROR("Request transfer on an NULL pointer"); return false; } - std::shared_ptr other = _obj->toBoolean(); + ememory::SharedPtr other = _obj->toBoolean(); if (other == nullptr) { JSON_ERROR("Request transfer on an element that is not an Boolean"); return false; @@ -73,11 +70,11 @@ bool ejson::Boolean::transfertIn(std::shared_ptr _obj) { return true; } -std::shared_ptr ejson::Boolean::clone() const { - std::shared_ptr output = ejson::Boolean::create(m_value); +ememory::SharedPtr ejson::Boolean::clone() const { + ememory::SharedPtr output = ejson::Boolean::create(m_value); if (output == nullptr) { JSON_ERROR("Allocation error ..."); - return std::shared_ptr(); + return ememory::SharedPtr(); } return output; } diff --git a/ejson/Boolean.h b/ejson/Boolean.h index f300fa4..7404ad1 100644 --- a/ejson/Boolean.h +++ b/ejson/Boolean.h @@ -21,7 +21,7 @@ namespace ejson { }; public: - static std::shared_ptr create(bool _value=false); + static ememory::SharedPtr create(bool _value=false); /** * @brief destructor */ @@ -46,10 +46,10 @@ namespace ejson { return m_value; }; public: // herited function : - virtual bool iParse(const std::string& _data, size_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc); + virtual bool iParse(const std::string& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::Document& _doc); virtual bool iGenerate(std::string& _data, size_t _indent) const; - virtual bool transfertIn(std::shared_ptr _obj); - virtual std::shared_ptr clone() const; + virtual bool transfertIn(ememory::SharedPtr _obj); + virtual ememory::SharedPtr clone() const; }; } diff --git a/ejson/Null.cpp b/ejson/Null.cpp index 147bb1b..3abfdc3 100644 --- a/ejson/Null.cpp +++ b/ejson/Null.cpp @@ -6,20 +6,16 @@ * @license APACHE v2.0 (see license file) */ - #include #include #include -#undef __class__ -#define __class__ "Null" - -std::shared_ptr ejson::Null::create() { - return std::shared_ptr(new ejson::Null()); +ememory::SharedPtr ejson::Null::create() { + return ememory::SharedPtr(new ejson::Null()); } -bool ejson::Null::iParse(const std::string& _data, size_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc) { +bool ejson::Null::iParse(const std::string& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::Document& _doc) { JSON_PARSE_ELEMENT("start parse : 'Null' "); if (_pos+3 >= _data.size()){ EJSON_CREATE_ERROR(_doc, _data, _pos, _filePos, "can not parse null !!! "); @@ -44,12 +40,12 @@ bool ejson::Null::iGenerate(std::string& _data, size_t _indent) const { } -bool ejson::Null::transfertIn(std::shared_ptr _obj) { +bool ejson::Null::transfertIn(ememory::SharedPtr _obj) { if (_obj == nullptr) { JSON_ERROR("Request transfer on an nullptr pointer"); return false; } - std::shared_ptr other = _obj->toNull(); + ememory::SharedPtr other = _obj->toNull(); if (other == nullptr) { JSON_ERROR("Request transfer on an element that is not an Null"); return false; @@ -57,11 +53,11 @@ bool ejson::Null::transfertIn(std::shared_ptr _obj) { return true; } -std::shared_ptr ejson::Null::clone() const { - std::shared_ptr output = ejson::Null::create(); +ememory::SharedPtr ejson::Null::clone() const { + ememory::SharedPtr output = ejson::Null::create(); if (output == nullptr) { JSON_ERROR("Allocation error ..."); - return std::shared_ptr(); + return ememory::SharedPtr(); } return output; } diff --git a/ejson/Null.h b/ejson/Null.h index e6f0bab..8e84d92 100644 --- a/ejson/Null.h +++ b/ejson/Null.h @@ -18,16 +18,16 @@ namespace ejson { */ Null() { }; public: - static std::shared_ptr create(); + static ememory::SharedPtr create(); /** * @brief destructor */ virtual ~Null() { }; public: // herited function : - virtual bool iParse(const std::string& _data, size_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc); + virtual bool iParse(const std::string& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::Document& _doc); virtual bool iGenerate(std::string& _data, size_t _indent) const; - virtual bool transfertIn(std::shared_ptr _obj); - virtual std::shared_ptr clone() const; + virtual bool transfertIn(ememory::SharedPtr _obj); + virtual ememory::SharedPtr clone() const; }; } diff --git a/ejson/Number.cpp b/ejson/Number.cpp index b1a0699..88d4ff3 100644 --- a/ejson/Number.cpp +++ b/ejson/Number.cpp @@ -11,14 +11,11 @@ #include #include -#undef __class__ -#define __class__ "Number" - -std::shared_ptr ejson::Number::create(double _value) { - return std::shared_ptr(new ejson::Number(_value)); +ememory::SharedPtr ejson::Number::create(double _value) { + return ememory::SharedPtr(new ejson::Number(_value)); } -bool ejson::Number::iParse(const std::string& _data, size_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc) { +bool ejson::Number::iParse(const std::string& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::Document& _doc) { JSON_PARSE_ELEMENT("start parse : 'Number' "); std::string tmpVal; for (size_t iii=_pos; iii<_data.size(); iii++) { @@ -53,12 +50,12 @@ bool ejson::Number::iGenerate(std::string& _data, size_t _indent) const { } -bool ejson::Number::transfertIn(std::shared_ptr _obj) { +bool ejson::Number::transfertIn(ememory::SharedPtr _obj) { if (_obj == nullptr) { JSON_ERROR("Request transfer on an nullptr pointer"); return false; } - std::shared_ptr other = _obj->toNumber(); + ememory::SharedPtr other = _obj->toNumber(); if (other == nullptr) { JSON_ERROR("Request transfer on an element that is not an Number"); return false; @@ -69,11 +66,11 @@ bool ejson::Number::transfertIn(std::shared_ptr _obj) { return true; } -std::shared_ptr ejson::Number::clone() const { - std::shared_ptr output = ejson::Number::create(m_value); +ememory::SharedPtr ejson::Number::clone() const { + ememory::SharedPtr output = ejson::Number::create(m_value); if (output == nullptr) { JSON_ERROR("Allocation error ..."); - return std::shared_ptr(); + return ememory::SharedPtr(); } return output; } diff --git a/ejson/Number.h b/ejson/Number.h index bc0d660..4ccfc33 100644 --- a/ejson/Number.h +++ b/ejson/Number.h @@ -21,7 +21,7 @@ namespace ejson { }; public: - static std::shared_ptr create(double _value=0.0); + static ememory::SharedPtr create(double _value=0.0); /** * @brief destructor */ @@ -58,10 +58,10 @@ namespace ejson { return (int64_t)m_value; }; public: // herited function : - virtual bool iParse(const std::string& _data, size_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc); + virtual bool iParse(const std::string& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::Document& _doc); virtual bool iGenerate(std::string& _data, size_t _indent) const; - virtual bool transfertIn(std::shared_ptr _obj); - virtual std::shared_ptr clone() const; + virtual bool transfertIn(ememory::SharedPtr _obj); + virtual ememory::SharedPtr clone() const; }; } diff --git a/ejson/Object.cpp b/ejson/Object.cpp index 0e6846f..9ded300 100644 --- a/ejson/Object.cpp +++ b/ejson/Object.cpp @@ -16,15 +16,11 @@ #include #include -#undef __class__ -#define __class__ "Object" - - -std::shared_ptr ejson::Object::create() { - return std::shared_ptr(new ejson::Object()); +ememory::SharedPtr ejson::Object::create() { + return ememory::SharedPtr(new ejson::Object()); } -std::shared_ptr ejson::Object::create(const std::string& _data) { +ememory::SharedPtr ejson::Object::create(const std::string& _data) { ejson::Document doc; doc.parse(_data); return doc.cloneObj(); @@ -42,7 +38,7 @@ enum statusParsing { parseValue, }; -bool ejson::Object::iParse(const std::string& _data, size_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc) { +bool ejson::Object::iParse(const std::string& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::Document& _doc) { enum statusParsing mode = parseName; std::string currentName; JSON_PARSE_ELEMENT("start parse : 'Object' "); @@ -57,7 +53,7 @@ bool ejson::Object::iParse(const std::string& _data, size_t& _pos, ejson::filePo #ifdef ENABLE_DISPLAY_PARSED_ELEMENT drawElementParsed(_data[iii], _filePos); #endif - ejson::filePos tmpPos; + ejson::FilePos tmpPos; if( _data[iii] == ' ' || _data[iii] == '\t' || _data[iii] == '\n' @@ -127,7 +123,7 @@ bool ejson::Object::iParse(const std::string& _data, size_t& _pos, ejson::filePo if (_data[iii] == '{') { // find an object: JSON_PARSE_ELEMENT("find Object"); - std::shared_ptr tmpElement = ejson::Object::create(); + ememory::SharedPtr tmpElement = ejson::Object::create(); if (tmpElement == nullptr) { EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in object"); _pos=iii; @@ -140,7 +136,7 @@ bool ejson::Object::iParse(const std::string& _data, size_t& _pos, ejson::filePo || _data[iii] == '\'') { // find a string: JSON_PARSE_ELEMENT("find String quoted"); - std::shared_ptr tmpElement = ejson::String::create(); + ememory::SharedPtr tmpElement = ejson::String::create(); if (tmpElement == nullptr) { EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in String"); _pos=iii; @@ -152,7 +148,7 @@ bool ejson::Object::iParse(const std::string& _data, size_t& _pos, ejson::filePo } else if (_data[iii] == '[') { // find a list: JSON_PARSE_ELEMENT("find List"); - std::shared_ptr tmpElement = ejson::Array::create(); + ememory::SharedPtr tmpElement = ejson::Array::create(); if (tmpElement == nullptr) { EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in Array"); _pos=iii; @@ -165,7 +161,7 @@ bool ejson::Object::iParse(const std::string& _data, size_t& _pos, ejson::filePo || _data[iii] == 't' ) { // find boolean: JSON_PARSE_ELEMENT("find Boolean"); - std::shared_ptr tmpElement = ejson::Boolean::create(); + ememory::SharedPtr tmpElement = ejson::Boolean::create(); if (tmpElement == nullptr) { EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in Boolean"); _pos=iii; @@ -177,7 +173,7 @@ bool ejson::Object::iParse(const std::string& _data, size_t& _pos, ejson::filePo } else if( _data[iii] == 'n') { // find null: JSON_PARSE_ELEMENT("find Null"); - std::shared_ptr tmpElement = ejson::Null::create(); + ememory::SharedPtr tmpElement = ejson::Null::create(); if (tmpElement == nullptr) { EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in Boolean"); _pos=iii; @@ -189,7 +185,7 @@ bool ejson::Object::iParse(const std::string& _data, size_t& _pos, ejson::filePo } else if(true == checkNumber(_data[iii])) { // find number: JSON_PARSE_ELEMENT("find Number"); - std::shared_ptr tmpElement = ejson::Number::create(); + ememory::SharedPtr tmpElement = ejson::Number::create(); if (tmpElement == nullptr) { EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in Boolean"); _pos=iii; @@ -226,7 +222,7 @@ bool ejson::Object::iGenerate(std::string& _data, size_t _indent) const { oneLine=false; } else { for (int32_t iii=0; iii tmp = m_value[iii]; + ememory::SharedPtr tmp = m_value[iii]; if (tmp == nullptr) { continue; } @@ -239,7 +235,7 @@ bool ejson::Object::iGenerate(std::string& _data, size_t _indent) const { break; } if (tmp->isString() == true) { - std::shared_ptr tmp2 = tmp->toString(); + ememory::SharedPtr tmp2 = tmp->toString(); if (tmp2 != nullptr) { if( tmp2->get().size()>25 || m_value.getKey(iii).size()>25) { @@ -283,87 +279,87 @@ bool ejson::Object::exist(const std::string& _name) const { return m_value.exist(_name); } -std::shared_ptr ejson::Object::get(const std::string& _name) { +ememory::SharedPtr ejson::Object::get(const std::string& _name) { if (false == m_value.exist(_name)) { - return std::shared_ptr(); + return ememory::SharedPtr(); } return m_value[_name]; } -const std::shared_ptr ejson::Object::get(const std::string& _name) const { +const ememory::SharedPtr ejson::Object::get(const std::string& _name) const { if (false == m_value.exist(_name)) { - return std::shared_ptr(); + return ememory::SharedPtr(); } return m_value[_name]; } -std::shared_ptr ejson::Object::getObject(const std::string& _name) { - std::shared_ptr tmp = get(_name); +ememory::SharedPtr ejson::Object::getObject(const std::string& _name) { + ememory::SharedPtr tmp = get(_name); if (tmp == nullptr) { - return std::shared_ptr(); + return ememory::SharedPtr(); } return std::dynamic_pointer_cast(tmp); } -const std::shared_ptr ejson::Object::getObject(const std::string& _name) const { - const std::shared_ptr tmp = get(_name); +const ememory::SharedPtr ejson::Object::getObject(const std::string& _name) const { + const ememory::SharedPtr tmp = get(_name); if (tmp == nullptr) { - return std::shared_ptr(); + return ememory::SharedPtr(); } return std::dynamic_pointer_cast(tmp); } -std::shared_ptr ejson::Object::getArray(const std::string& _name) { - std::shared_ptr tmp = get(_name); +ememory::SharedPtr ejson::Object::getArray(const std::string& _name) { + ememory::SharedPtr tmp = get(_name); if (tmp == nullptr) { - return std::shared_ptr(); + return ememory::SharedPtr(); } return std::dynamic_pointer_cast(tmp); } -const std::shared_ptr ejson::Object::getArray(const std::string& _name) const { - const std::shared_ptr tmp = get(_name); +const ememory::SharedPtr ejson::Object::getArray(const std::string& _name) const { + const ememory::SharedPtr tmp = get(_name); if (tmp == nullptr) { - return std::shared_ptr(); + return ememory::SharedPtr(); } return std::dynamic_pointer_cast(tmp); } -std::shared_ptr ejson::Object::getNull(const std::string& _name) { - std::shared_ptr tmp = get(_name); +ememory::SharedPtr ejson::Object::getNull(const std::string& _name) { + ememory::SharedPtr tmp = get(_name); if (tmp == nullptr) { - return std::shared_ptr(); + return ememory::SharedPtr(); } return std::dynamic_pointer_cast(tmp); } -const std::shared_ptr ejson::Object::getNull(const std::string& _name) const { - const std::shared_ptr tmp = get(_name); +const ememory::SharedPtr ejson::Object::getNull(const std::string& _name) const { + const ememory::SharedPtr tmp = get(_name); if (tmp == nullptr) { - return std::shared_ptr(); + return ememory::SharedPtr(); } return std::dynamic_pointer_cast(tmp); } -std::shared_ptr ejson::Object::getString(const std::string& _name) { - std::shared_ptr tmp = get(_name); +ememory::SharedPtr ejson::Object::getString(const std::string& _name) { + ememory::SharedPtr tmp = get(_name); if (tmp == nullptr) { - return std::shared_ptr(); + return ememory::SharedPtr(); } return std::dynamic_pointer_cast(tmp); } -const std::shared_ptr ejson::Object::getString(const std::string& _name) const { - const std::shared_ptr tmp = get(_name); +const ememory::SharedPtr ejson::Object::getString(const std::string& _name) const { + const ememory::SharedPtr tmp = get(_name); if (tmp == nullptr) { - return std::shared_ptr(); + return ememory::SharedPtr(); } return std::dynamic_pointer_cast(tmp); } const std::string& ejson::Object::getStringValue(const std::string& _name) const { static const std::string errorString(""); - const std::shared_ptr tmpp = getString(_name); + const ememory::SharedPtr tmpp = getString(_name); if (tmpp == nullptr) { return errorString; } @@ -371,55 +367,55 @@ const std::string& ejson::Object::getStringValue(const std::string& _name) const } std::string ejson::Object::getStringValue(const std::string& _name, const std::string& _errorValue) const { - const std::shared_ptr tmpp = getString(_name); + const ememory::SharedPtr tmpp = getString(_name); if (tmpp == nullptr) { return _errorValue; } return tmpp->get(); } -std::shared_ptr ejson::Object::getBoolean(const std::string& _name) { - std::shared_ptr tmp = get(_name); +ememory::SharedPtr ejson::Object::getBoolean(const std::string& _name) { + ememory::SharedPtr tmp = get(_name); if (tmp == nullptr) { - return std::shared_ptr(); + return ememory::SharedPtr(); } return tmp->toBoolean(); } -const std::shared_ptr ejson::Object::getBoolean(const std::string& _name) const { - const std::shared_ptr tmp = get(_name); +const ememory::SharedPtr ejson::Object::getBoolean(const std::string& _name) const { + const ememory::SharedPtr tmp = get(_name); if (tmp == nullptr) { - return std::shared_ptr(); + return ememory::SharedPtr(); } return tmp->toBoolean(); } bool ejson::Object::getBooleanValue(const std::string& _name, bool _errorValue) const { - const std::shared_ptr tmpp = getBoolean(_name); + const ememory::SharedPtr tmpp = getBoolean(_name); if (tmpp == nullptr) { return _errorValue; } return tmpp->get(); } -std::shared_ptr ejson::Object::getNumber(const std::string& _name) { - std::shared_ptr tmp = get(_name); +ememory::SharedPtr ejson::Object::getNumber(const std::string& _name) { + ememory::SharedPtr tmp = get(_name); if (tmp == nullptr) { - return std::shared_ptr(); + return ememory::SharedPtr(); } return tmp->toNumber(); } -const std::shared_ptr ejson::Object::getNumber(const std::string& _name) const { - const std::shared_ptr tmp = get(_name); +const ememory::SharedPtr ejson::Object::getNumber(const std::string& _name) const { + const ememory::SharedPtr tmp = get(_name); if (tmp == nullptr) { - return std::shared_ptr(); + return ememory::SharedPtr(); } return tmp->toNumber(); } double ejson::Object::getNumberValue(const std::string& _name, double _errorValue) const { - const std::shared_ptr tmpp = getNumber(_name); + const ememory::SharedPtr tmpp = getNumber(_name); if (tmpp == nullptr) { return _errorValue; } @@ -427,7 +423,7 @@ double ejson::Object::getNumberValue(const std::string& _name, double _errorValu } -bool ejson::Object::add(const std::string& _name, std::shared_ptr _value) { +bool ejson::Object::add(const std::string& _name, ememory::SharedPtr _value) { if (_value == nullptr) { return false; } @@ -458,12 +454,12 @@ bool ejson::Object::addNumber(const std::string& _name, double _value) { return add(_name, ejson::Number::create(_value)); } -bool ejson::Object::transfertIn(std::shared_ptr _obj) { +bool ejson::Object::transfertIn(ememory::SharedPtr _obj) { if (_obj == nullptr) { JSON_ERROR("Request transfer on an nullptr pointer"); return false; } - std::shared_ptr other = _obj->toObject(); + ememory::SharedPtr other = _obj->toObject(); if (other == nullptr) { JSON_ERROR("Request transfer on an element that is not an object"); return false; @@ -477,7 +473,7 @@ bool ejson::Object::transfertIn(std::shared_ptr _obj) { return true; } -bool ejson::Object::cloneIn(const std::shared_ptr& _obj) const { +bool ejson::Object::cloneIn(const ememory::SharedPtr& _obj) const { if (_obj == nullptr) { return false; } @@ -490,18 +486,18 @@ bool ejson::Object::cloneIn(const std::shared_ptr& _obj) const { // TODO : Manage error ... -std::shared_ptr ejson::Object::clone() const { +ememory::SharedPtr ejson::Object::clone() const { return cloneObj(); } -std::shared_ptr ejson::Object::cloneObj() const { - std::shared_ptr output = ejson::Object::create(); +ememory::SharedPtr ejson::Object::cloneObj() const { + ememory::SharedPtr output = ejson::Object::create(); if (output == nullptr) { JSON_ERROR("Allocation error ..."); - return std::shared_ptr(); + return ememory::SharedPtr(); } for (int32_t iii=0; iii val = m_value.getValue(iii); + ememory::SharedPtr val = m_value.getValue(iii); std::string key = m_value.getKey(iii); if (val == nullptr) { continue; diff --git a/ejson/Object.h b/ejson/Object.h index a799b72..af15b5d 100644 --- a/ejson/Object.h +++ b/ejson/Object.h @@ -20,14 +20,14 @@ namespace ejson { */ Object() { }; public: - static std::shared_ptr create(); - static std::shared_ptr create(const std::string& _data); + static ememory::SharedPtr create(); + static ememory::SharedPtr create(const std::string& _data); /** * @brief destructor */ virtual ~Object() { }; protected: - etk::Hash > m_value; //!< value of the node (for element this is the name, for text it is the inside text ...) + etk::Hash > m_value; //!< value of the node (for element this is the name, for text it is the inside text ...) public: /** * @brief check if an element exist. @@ -40,15 +40,15 @@ namespace ejson { * @param[in] _name name of the object * @return pointer on the element requested or nullptr if it not the corect type or does not existed */ - std::shared_ptr get(const std::string& _name); + ememory::SharedPtr get(const std::string& _name); //! @previous - const std::shared_ptr get(const std::string& _name) const; + const ememory::SharedPtr get(const std::string& _name) const; //! @previous - std::shared_ptr operator[] (const std::string& _name) { + ememory::SharedPtr operator[] (const std::string& _name) { return get(_name); } //! @previous - const std::shared_ptr operator[] (const std::string& _name) const { + const ememory::SharedPtr operator[] (const std::string& _name) const { return get(_name); } public: @@ -71,19 +71,19 @@ namespace ejson { * @param[in] _id Id of the element. * @return nullptr if the element does not exist. */ - std::shared_ptr get(size_t _id) { + ememory::SharedPtr get(size_t _id) { return m_value[_id]; }; //! @previous - const std::shared_ptr get(size_t _id) const{ + const ememory::SharedPtr get(size_t _id) const{ return m_value[_id]; }; //! @previous - std::shared_ptr operator[] (size_t _id) { + ememory::SharedPtr operator[] (size_t _id) { return m_value[_id]; } //! @previous - const std::shared_ptr operator[] (size_t _id) const { + const ememory::SharedPtr operator[] (size_t _id) const { return m_value[_id]; } /** @@ -99,33 +99,41 @@ namespace ejson { * @param[in] _name name of the object * @return pointer on the element requested or nullptr if it not the corect type or does not existed */ - std::shared_ptr getObject(const std::string& _name); - //! @previous - const std::shared_ptr getObject(const std::string& _name) const; + ememory::SharedPtr getObject(const std::string& _name); + /** + * @brief get the sub element with his name (Casted as Object if it is possible) + * @param[in] _name name of the object + * @return pointer on the element requested or nullptr if it not the corect type or does not existed + */ + const ememory::SharedPtr getObject(const std::string& _name) const; /** * @brief get the sub element with his name (Casted as Array if it is possible) * @param[in] _name name of the object * @return pointer on the element requested or nullptr if it not the corect type or does not existed */ - std::shared_ptr getArray(const std::string& _name); - //! @previous - const std::shared_ptr getArray(const std::string& _name) const; + ememory::SharedPtr getArray(const std::string& _name); + /** + * @brief get the sub element with his name (Casted as Array if it is possible) + * @param[in] _name name of the object + * @return pointer on the element requested or nullptr if it not the corect type or does not existed + */ + const ememory::SharedPtr getArray(const std::string& _name) const; /** * @brief get the sub element with his name (Casted as Null if it is possible) * @param[in] _name name of the object * @return pointer on the element requested or nullptr if it not the corect type or does not existed */ - std::shared_ptr getNull(const std::string& _name); + ememory::SharedPtr getNull(const std::string& _name); //! @previous - const std::shared_ptr getNull(const std::string& _name) const; + const ememory::SharedPtr getNull(const std::string& _name) const; /** * @brief get the sub element with his name (Casted as String if it is possible) * @param[in] _name name of the object * @return pointer on the element requested or nullptr if it not the corect type or does not existed */ - std::shared_ptr getString(const std::string& _name); + ememory::SharedPtr getString(const std::string& _name); //! @previous - const std::shared_ptr getString(const std::string& _name) const; + const ememory::SharedPtr getString(const std::string& _name) const; /** * @brief get the sub string value of the requested element * @param[in] _name name of the object @@ -144,9 +152,9 @@ namespace ejson { * @param[in] _name name of the object * @return pointer on the element requested or nullptr if it not the corect type or does not existed */ - std::shared_ptr getBoolean(const std::string& _name); + ememory::SharedPtr getBoolean(const std::string& _name); //! @previous - const std::shared_ptr getBoolean(const std::string& _name) const; + const ememory::SharedPtr getBoolean(const std::string& _name) const; /** * @brief get the sub boolean value of the requested element. * @param[in] _name name of the object. @@ -159,9 +167,9 @@ namespace ejson { * @param[in] _name name of the object * @return pointer on the element requested or nullptr if it not the corect type or does not existed */ - std::shared_ptr getNumber(const std::string& _name); + ememory::SharedPtr getNumber(const std::string& _name); //! @previous - const std::shared_ptr getNumber(const std::string& _name) const; + const ememory::SharedPtr getNumber(const std::string& _name) const; /** * @brief get the sub Number value of the requested element. * @param[in] _name name of the object. @@ -176,7 +184,7 @@ namespace ejson { * @param[in] _value Element to add * @return false if an error occured */ - bool add(const std::string& _name, std::shared_ptr _value); + bool add(const std::string& _name, ememory::SharedPtr _value); /** * @brief add a string element in the Object (automatic creation) * @param[in] _name name of the object @@ -205,13 +213,13 @@ namespace ejson { */ bool addNumber(const std::string& _name, double _value); public: // herited function : - virtual bool iParse(const std::string& _data, size_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc); + virtual bool iParse(const std::string& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::Document& _doc); virtual bool iGenerate(std::string& _data, size_t _indent) const; virtual void clear(); - virtual bool transfertIn(std::shared_ptr _obj); - virtual bool cloneIn(const std::shared_ptr& _obj) const; - virtual std::shared_ptr clone() const; - virtual std::shared_ptr cloneObj() const; + virtual bool transfertIn(ememory::SharedPtr _obj); + virtual bool cloneIn(const ememory::SharedPtr& _obj) const; + virtual ememory::SharedPtr clone() const; + virtual ememory::SharedPtr cloneObj() const; }; } diff --git a/ejson/String.cpp b/ejson/String.cpp index f167302..7986b9c 100644 --- a/ejson/String.cpp +++ b/ejson/String.cpp @@ -13,15 +13,11 @@ #include #include -#undef __class__ -#define __class__ "String" - - -std::shared_ptr ejson::String::create(const std::string& _value) { - return std::shared_ptr(new ejson::String(_value)); +ememory::SharedPtr ejson::String::create(const std::string& _value) { + return ememory::SharedPtr(new ejson::String(_value)); } -bool ejson::String::iParse(const std::string& _data, size_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc) { +bool ejson::String::iParse(const std::string& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::Document& _doc) { JSON_PARSE_ELEMENT("start parse : 'String' "); char end = _data[_pos]; for (size_t iii=_pos+1; iii<_data.size(); iii++) { @@ -29,7 +25,7 @@ bool ejson::String::iParse(const std::string& _data, size_t& _pos, ejson::filePo #ifdef ENABLE_DISPLAY_PARSED_ELEMENT drawElementParsed(_data[iii], _filePos); #endif - ejson::filePos tmpPos; + ejson::FilePos tmpPos; // TODO : manage \x if(_data[iii] != end) { m_value += _data[iii]; @@ -52,12 +48,12 @@ bool ejson::String::iGenerate(std::string& _data, size_t _indent) const { } -bool ejson::String::transfertIn(std::shared_ptr _obj) { +bool ejson::String::transfertIn(ememory::SharedPtr _obj) { if (_obj == nullptr) { JSON_ERROR("Request transfer on an nullptr pointer"); return false; } - std::shared_ptr other = _obj->toString(); + ememory::SharedPtr other = _obj->toString(); if (other == nullptr) { JSON_ERROR("Request transfer on an element that is not an String"); return false; @@ -67,11 +63,11 @@ bool ejson::String::transfertIn(std::shared_ptr _obj) { return true; } -std::shared_ptr ejson::String::clone() const { - std::shared_ptr output = ejson::String::create(m_value); +ememory::SharedPtr ejson::String::clone() const { + ememory::SharedPtr output = ejson::String::create(m_value); if (output == nullptr) { JSON_ERROR("Allocation error ..."); - return std::shared_ptr(); + return ememory::SharedPtr(); } return output; } diff --git a/ejson/String.h b/ejson/String.h index 404d35b..5c65ccd 100644 --- a/ejson/String.h +++ b/ejson/String.h @@ -21,7 +21,7 @@ namespace ejson { }; public: - static std::shared_ptr create(const std::string& _value=""); + static ememory::SharedPtr create(const std::string& _value=""); /** * @brief destructor */ @@ -44,10 +44,10 @@ namespace ejson { return m_value; }; public: // herited function : - virtual bool iParse(const std::string& _data, size_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc); + virtual bool iParse(const std::string& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::Document& _doc); virtual bool iGenerate(std::string& _data, size_t _indent) const; - virtual bool transfertIn(std::shared_ptr _obj); - virtual std::shared_ptr clone() const; + virtual bool transfertIn(ememory::SharedPtr _obj); + virtual ememory::SharedPtr clone() const; }; } diff --git a/ejson/Value.cpp b/ejson/Value.cpp index b330293..504b508 100644 --- a/ejson/Value.cpp +++ b/ejson/Value.cpp @@ -10,23 +10,10 @@ #include #include -#undef __class__ -#define __class__ "Value" - ejson::Value::~Value() { clear(); } -std::ostream& ejson::operator <<(std::ostream& _os, const ejson::filePos& _obj) { - _os << "(l="; - _os << _obj.getLine(); - _os << ",c="; - _os << _obj.getCol(); - _os << ")"; - return _os; -} - - bool ejson::Value::isWhiteChar(char32_t _val) { if( _val == ' ' || _val == '\t' @@ -37,14 +24,13 @@ bool ejson::Value::isWhiteChar(char32_t _val) { return false; } - void ejson::Value::addIndent(std::string& _data, size_t _indent) const { for (size_t iii=0; iii<_indent; iii++) { _data+="\t"; } } -void ejson::Value::drawElementParsed(char32_t _val, const ejson::filePos& _filePos) const { +void ejson::Value::drawElementParsed(char32_t _val, const ejson::FilePos& _filePos) const { if (_val == '\n') { JSON_DEBUG(_filePos << " parse '\\n'"); } else if (_val == '\t') { @@ -54,7 +40,7 @@ void ejson::Value::drawElementParsed(char32_t _val, const ejson::filePos& _fileP } } -int32_t ejson::Value::countWhiteChar(const std::string& _data, size_t _pos, ejson::filePos& _filePos) const { +int32_t ejson::Value::countWhiteChar(const std::string& _data, size_t _pos, ejson::FilePos& _filePos) const { _filePos.clear(); size_t white=0; for (size_t iii=_pos; iii<_data.size(); iii++) { @@ -69,7 +55,6 @@ int32_t ejson::Value::countWhiteChar(const std::string& _data, size_t _pos, ejso return white; } - bool ejson::Value::checkString(char32_t _val) const { if( _val == '!' || _val == '"' @@ -121,52 +106,52 @@ bool ejson::Value::checkNumber(char32_t _val) const { return false; } -std::shared_ptr ejson::Value::toValue() { +ememory::SharedPtr ejson::Value::toValue() { return shared_from_this(); }; -const std::shared_ptr ejson::Value::toValue() const { +const ememory::SharedPtr ejson::Value::toValue() const { return shared_from_this(); }; -std::shared_ptr ejson::Value::toDocument() { +ememory::SharedPtr ejson::Value::toDocument() { return std::dynamic_pointer_cast(shared_from_this()); }; -const std::shared_ptr ejson::Value::toDocument() const { +const ememory::SharedPtr ejson::Value::toDocument() const { return std::dynamic_pointer_cast(shared_from_this()); }; -std::shared_ptr ejson::Value::toArray() { +ememory::SharedPtr ejson::Value::toArray() { return std::dynamic_pointer_cast(shared_from_this()); }; -const std::shared_ptr ejson::Value::toArray() const{ +const ememory::SharedPtr ejson::Value::toArray() const{ return std::dynamic_pointer_cast(shared_from_this()); }; -std::shared_ptr ejson::Value::toObject() { +ememory::SharedPtr ejson::Value::toObject() { return std::dynamic_pointer_cast(shared_from_this()); }; -const std::shared_ptr ejson::Value::toObject() const{ +const ememory::SharedPtr ejson::Value::toObject() const{ return std::dynamic_pointer_cast(shared_from_this()); }; -std::shared_ptr ejson::Value::toString() { +ememory::SharedPtr ejson::Value::toString() { return std::dynamic_pointer_cast(shared_from_this()); }; -const std::shared_ptr ejson::Value::toString() const{ +const ememory::SharedPtr ejson::Value::toString() const{ return std::dynamic_pointer_cast(shared_from_this()); }; -std::shared_ptr ejson::Value::toNumber() { +ememory::SharedPtr ejson::Value::toNumber() { return std::dynamic_pointer_cast(shared_from_this()); }; -const std::shared_ptr ejson::Value::toNumber() const{ +const ememory::SharedPtr ejson::Value::toNumber() const{ return std::dynamic_pointer_cast(shared_from_this()); }; -std::shared_ptr ejson::Value::toBoolean() { +ememory::SharedPtr ejson::Value::toBoolean() { return std::dynamic_pointer_cast(shared_from_this()); }; -const std::shared_ptr ejson::Value::toBoolean() const{ +const ememory::SharedPtr ejson::Value::toBoolean() const{ return std::dynamic_pointer_cast(shared_from_this()); }; -std::shared_ptr ejson::Value::toNull() { +ememory::SharedPtr ejson::Value::toNull() { return std::dynamic_pointer_cast(shared_from_this()); }; -const std::shared_ptr ejson::Value::toNull() const{ +const ememory::SharedPtr ejson::Value::toNull() const{ return std::dynamic_pointer_cast(shared_from_this()); }; @@ -176,3 +161,45 @@ void ejson::Value::display() const { JSON_INFO("Generated JSON : \n" << tmpp); } + +bool ejson::Value::isDocument() const { + return toDocument() != nullptr; +} + +bool ejson::Value::isArray() const { + return toArray() != nullptr; +} + +bool ejson::Value::isObject() const { + return toObject() != nullptr; +} + +bool ejson::Value::isString() const { + return toString() != nullptr; +} + +bool ejson::Value::isNumber() const { + return toNumber() != nullptr; +} + +bool ejson::Value::isBoolean() const { + return toBoolean() != nullptr; +} + +bool ejson::Value::isNull() const { + return toNull() != nullptr; +} + + +void ejson::Value::clear() { + +} + +bool ejson::Value::transfertIn(ememory::SharedPtr _obj) { + return false; +} + +ememory::SharedPtr ejson::Value::clone() const { + return ememory::SharedPtr(); +} + diff --git a/ejson/Value.h b/ejson/Value.h index b9ee707..e16505b 100644 --- a/ejson/Value.h +++ b/ejson/Value.h @@ -8,9 +8,12 @@ #pragma once #include -#include - +#include +#include +/** + * @brief ejson namespace containing all function for JSON interpretor + */ namespace ejson { //#define ENABLE_DISPLAY_PARSED_ELEMENT #if 1 @@ -30,88 +33,17 @@ namespace ejson { class Null; class Number; class String; - //! @not_in_doc - class filePos { - private: - size_t m_col; - size_t m_line; - public: - filePos() : - m_col(0), - m_line(0) { - - }; - filePos(size_t _line, size_t _col) : - m_col(_col), - m_line(_line) { - - }; - ~filePos() { }; - filePos& operator ++() { - m_col++; - return *this; - }; - filePos& operator --() { - if(m_col>0) { - m_col--; - } - return *this; - }; - const filePos& operator +=(const filePos& _obj) { - if (_obj.m_line == 0) { - m_col += _obj.m_col; - } else { - m_col = _obj.m_col; - m_line += _obj.m_line; - } - return *this; - }; - const filePos& operator +=(size_t _col) { - m_col += _col; - return *this; - }; - const filePos& operator= (const filePos& _obj ) { - m_col = _obj.m_col; - m_line = _obj.m_line; - return *this; - } - void newLine() { - m_col=0; - m_line++; - }; - bool check(char32_t _val) { - m_col++; - if (_val == '\n') { - newLine(); - return true; - } - return false; - } - void set(size_t _line, size_t _col) { - m_col = _col; - m_line = _line; - } - void clear() { - m_col = 0; - m_line = 0; - } - int32_t getCol() const { - return m_col; - }; - int32_t getLine() const { - return m_line; - }; - }; - std::ostream& operator <<(std::ostream& _os, const filePos& _obj); - - class Value : public std::enable_shared_from_this { + /** + * @brief Basic main object of all json elements. + */ + class Value : public ememory::EnableSharedFromThis { protected: /** * @brief basic element of a xml structure */ Value() { }; /** - * @brief destructor + * @brief Virtualize destructor */ virtual ~Value(); public: @@ -123,7 +55,7 @@ namespace ejson { * @param[in,out] file parsing position (line x col x) * @return false if an error occured. */ - virtual bool iParse(const std::string& _data, size_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc) = 0; + virtual bool iParse(const std::string& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::Document& _doc) = 0; /** * @brief generate a string with the tree of the xml * @param[in,out] _data string where to add the elements @@ -147,7 +79,7 @@ namespace ejson { * @param[in] _val Char that is parsed. * @param[in] _filePos Position of the char in the file. */ - void drawElementParsed(char32_t _val, const ejson::filePos& _filePos) const; + void drawElementParsed(char32_t _val, const ejson::FilePos& _filePos) const; /** * @brief check if an name (for object named) (not : !"#$%&'()*+,/;<=>?@[\]^`{|}~ \n\t\r). * @param[in] _val Value to check the conformity. @@ -165,135 +97,141 @@ namespace ejson { * @param[out] _filePos new poistion of te file to add. * @return number of white element. */ - int32_t countWhiteChar(const std::string& _data, size_t _pos, ejson::filePos& _filePos) const; + int32_t countWhiteChar(const std::string& _data, size_t _pos, ejson::FilePos& _filePos) const; public: /** * @brief Cast the element in a Value if it is possible. * @return pointer on the class or nullptr. */ - std::shared_ptr toValue(); - //! @previous - const std::shared_ptr toValue() const; + ememory::SharedPtr toValue(); + /** + * @brief Cast the element in a Value if it is possible. + * @return CONST pointer on the class or nullptr. + */ + const ememory::SharedPtr toValue() const; /** * @brief Cast the element in a Document if it is possible. * @return pointer on the class or nullptr. */ - std::shared_ptr toDocument(); - //! @previous - const std::shared_ptr toDocument() const; + ememory::SharedPtr toDocument(); + /** + * @brief Cast the element in a Document if it is possible. + * @return CONST pointer on the class or nullptr. + */ + const ememory::SharedPtr toDocument() const; /** * @brief Cast the element in a Array if it is possible. * @return pointer on the class or nullptr. */ - std::shared_ptr toArray(); - //! @previous - const std::shared_ptr toArray() const; + ememory::SharedPtr toArray(); + /** + * @brief Cast the element in a Array if it is possible. + * @return CONST pointer on the class or nullptr. + */ + const ememory::SharedPtr toArray() const; /** * @brief Cast the element in a Object if it is possible. * @return pointer on the class or nullptr. */ - std::shared_ptr toObject(); - //! @previous - const std::shared_ptr toObject() const; + ememory::SharedPtr toObject(); + /** + * @brief Cast the element in a Object if it is possible. + * @return CONST pointer on the class or nullptr. + */ + const ememory::SharedPtr toObject() const; /** * @brief Cast the element in a String if it is possible. * @return pointer on the class or nullptr. */ - std::shared_ptr toString(); - //! @previous - const std::shared_ptr toString() const; + ememory::SharedPtr toString(); + /** + * @brief Cast the element in a String if it is possible. + * @return CONST pointer on the class or nullptr. + */ + const ememory::SharedPtr toString() const; /** * @brief Cast the element in a Number if it is possible. * @return pointer on the class or nullptr. */ - std::shared_ptr toNumber(); - //! @previous - const std::shared_ptr toNumber() const; + ememory::SharedPtr toNumber(); + /** + * @brief Cast the element in a Number if it is possible. + * @return CONST pointer on the class or nullptr. + */ + const ememory::SharedPtr toNumber() const; /** * @brief Cast the element in a Boolean if it is possible. * @return pointer on the class or nullptr. */ - std::shared_ptr toBoolean(); - //! @previous - const std::shared_ptr toBoolean() const; + ememory::SharedPtr toBoolean(); + /** + * @brief Cast the element in a Boolean if it is possible. + * @return CONST pointer on the class or nullptr. + */ + const ememory::SharedPtr toBoolean() const; /** * @brief Cast the element in a Null if it is possible. * @return pointer on the class or nullptr. */ - std::shared_ptr toNull(); - //! @previous - const std::shared_ptr toNull() const; + ememory::SharedPtr toNull(); + /** + * @brief Cast the element in a Null if it is possible. + * @return CONST pointer on the class or nullptr. + */ + const ememory::SharedPtr toNull() const; /** * @brief check if the node is a ejson::Document * @return true if the node is a ejson::Document */ - bool isDocument() const { - return toDocument() != nullptr; - }; + bool isDocument() const; /** * @brief check if the node is a ejson::Array * @return true if the node is a ejson::Array */ - bool isArray() const { - return toArray() != nullptr; - }; + bool isArray() const; /** * @brief check if the node is a ejson::Object * @return true if the node is a ejson::Object */ - bool isObject() const { - return toObject() != nullptr; - }; + bool isObject() const; /** * @brief check if the node is a ejson::String * @return true if the node is a ejson::String */ - bool isString() const { - return toString() != nullptr; - }; + bool isString() const; /** * @brief check if the node is a ejson::Number * @return true if the node is a ejson::Number */ - bool isNumber() const { - return toNumber() != nullptr; - }; + bool isNumber() const; /** * @brief check if the node is a ejson::Boolean * @return true if the node is a ejson::Boolean */ - bool isBoolean() const { - return toBoolean() != nullptr; - }; + bool isBoolean() const; /** * @brief check if the node is a ejson::Null * @return true if the node is a ejson::Null */ - bool isNull() const { - return toNull() != nullptr; - }; + bool isNull() const; /** * @brief clear the Node */ - virtual void clear() {}; + virtual void clear(); /** * @brief Tranfert all element in the element set in parameter * @param[in,out] _obj move all parameter in the selected element * @return true if transfer is done corectly * @note all element is remove from the curent element. */ - virtual bool transfertIn(std::shared_ptr _obj) { - return false; - }; + virtual bool transfertIn(ememory::SharedPtr _obj); /** * @brief Copy the curent node and all the child in the curent one. * @return nullptr in an error occured, the pointer on the element otherwise */ - virtual std::shared_ptr clone() const { - return std::shared_ptr(); - }; + virtual ememory::SharedPtr clone() const; protected: /** * @brief check if the current element is white or not : '\t' '\n' '\r' ' ' diff --git a/ejson/ejson.cpp b/ejson/ejson.cpp index 81e3159..4dc1aec 100644 --- a/ejson/ejson.cpp +++ b/ejson/ejson.cpp @@ -17,12 +17,8 @@ #include #include -#undef __class__ -#define __class__ "Document" - - -std::shared_ptr ejson::Document::create() { - return std::shared_ptr(new ejson::Document()); +ememory::SharedPtr ejson::Document::create() { + return ememory::SharedPtr(new ejson::Document()); } ejson::Document::Document() : @@ -46,7 +42,7 @@ bool ejson::Document::iGenerate(std::string& _data, size_t _indent) const { bool ejson::Document::parse(const std::string& _data) { JSON_VERBOSE("Start parsing document (type: string) size=" << _data.size()); clear(); - ejson::filePos filePos(1,0); + ejson::FilePos filePos(1,0); size_t parsePos = 0; return iParse(_data, parsePos, filePos, *this); } @@ -140,7 +136,7 @@ void ejson::Document::displayError() { #endif } -void ejson::Document::createError(const std::string& _data, size_t _pos, const ejson::filePos& _filePos, const std::string& _comment) { +void ejson::Document::createError(const std::string& _data, size_t _pos, const ejson::FilePos& _filePos, const std::string& _comment) { m_comment = _comment; m_Line = etk::extract_line(_data, _pos); m_filePos = _filePos; @@ -149,7 +145,7 @@ void ejson::Document::createError(const std::string& _data, size_t _pos, const e } } -bool ejson::Document::iParse(const std::string& _data, size_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc) { +bool ejson::Document::iParse(const std::string& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::Document& _doc) { JSON_PARSE_ELEMENT("start parse : 'Document' "); bool haveMainNode=false; bool nodeParsed=false; @@ -158,7 +154,7 @@ bool ejson::Document::iParse(const std::string& _data, size_t& _pos, ejson::file #ifdef ENABLE_DISPLAY_PARSED_ELEMENT drawElementParsed(_data[iii], _filePos); #endif - ejson::filePos tmpPos; + ejson::FilePos tmpPos; if( _data[iii] == ' ' || _data[iii] == '\t' || _data[iii] == '\n' diff --git a/ejson/ejson.h b/ejson/ejson.h index bb42f60..29ff686 100644 --- a/ejson/ejson.h +++ b/ejson/ejson.h @@ -21,7 +21,7 @@ namespace ejson { * @brief Constructor */ Document(); - static std::shared_ptr create(); + static ememory::SharedPtr create(); /** * @brief Destructor */ @@ -59,7 +59,7 @@ namespace ejson { bool m_writeErrorWhenDetexted; std::string m_comment; std::string m_Line; - ejson::filePos m_filePos; + ejson::FilePos m_filePos; public: void displayErrorWhenDetected() { m_writeErrorWhenDetexted=true; @@ -68,10 +68,10 @@ namespace ejson { m_writeErrorWhenDetexted=false; }; - void createError(const std::string& _data, size_t _pos, const ejson::filePos& _filePos, const std::string& _comment); + void createError(const std::string& _data, size_t _pos, const ejson::FilePos& _filePos, const std::string& _comment); void displayError(); public: // herited function: - virtual bool iParse(const std::string& _data, size_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc); + virtual bool iParse(const std::string& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::Document& _doc); virtual bool iGenerate(std::string& _data, size_t _indent) const; }; }; diff --git a/lutin_ejson.py b/lutin_ejson.py index 0061d63..457dc9a 100644 --- a/lutin_ejson.py +++ b/lutin_ejson.py @@ -26,10 +26,11 @@ def get_version(): def create(target, module_name): my_module = module.Module(__file__, module_name, get_type()) - my_module.add_module_depend(['etk']) + my_module.add_module_depend(['elog', 'etk', 'ememory']) my_module.add_extra_compile_flags() my_module.add_src_file([ 'ejson/debug.cpp', + 'ejson/FilePos.cpp', 'ejson/ejson.cpp', 'ejson/Array.cpp', 'ejson/Boolean.cpp', @@ -40,6 +41,7 @@ def create(target, module_name): 'ejson/Value.cpp' ]) my_module.add_header_file([ + 'ejson/FilePos.h', 'ejson/ejson.h', 'ejson/Array.h', 'ejson/Boolean.h', diff --git a/test/test.cpp b/test/test.cpp index 30b092f..1ba277a 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -21,10 +21,6 @@ #include "testNumber.h" #include "testAll.h" -#undef __class__ -#define __class__ "ejson::test" - - int main(int argc, const char *argv[]) { // init Google test : ::testing::InitGoogleTest(&argc, const_cast(argv));