diff --git a/ejson/Object.cpp b/ejson/Object.cpp index 7b04c7c..3037571 100644 --- a/ejson/Object.cpp +++ b/ejson/Object.cpp @@ -471,8 +471,24 @@ bool ejson::Object::transfertIn(std::shared_ptr _obj) { return true; } +bool ejson::Object::cloneIn(const std::shared_ptr& _obj) const { + if (_obj == nullptr) { + return false; + } + _obj->clear(); + for (int32_t iii=0; iiiadd(m_value.getKey(iii), m_value[iii]->clone()); + } + return true; +} + + // TODO : Manage error ... std::shared_ptr ejson::Object::clone() const { + return cloneObj(); +} + +std::shared_ptr ejson::Object::cloneObj() const { std::shared_ptr output = ejson::Object::create(); if (output == nullptr) { JSON_ERROR("Allocation error ..."); diff --git a/ejson/Object.h b/ejson/Object.h index 50e0cdc..0226e99 100644 --- a/ejson/Object.h +++ b/ejson/Object.h @@ -210,7 +210,9 @@ namespace ejson { 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; }; }; diff --git a/ejson/Value.cpp b/ejson/Value.cpp index bd1b1e4..1eef344 100644 --- a/ejson/Value.cpp +++ b/ejson/Value.cpp @@ -163,4 +163,11 @@ std::shared_ptr ejson::Value::toNull() { }; const std::shared_ptr ejson::Value::toNull() const{ return std::dynamic_pointer_cast(shared_from_this()); -}; \ No newline at end of file +}; + +void ejson::Value::display() const { + std::string tmpp; + iGenerate(tmpp, 0); + JSON_INFO("Generated JSON : \n" << tmpp); +} + diff --git a/ejson/Value.h b/ejson/Value.h index 11f7e0d..a3ad64a 100644 --- a/ejson/Value.h +++ b/ejson/Value.h @@ -132,6 +132,10 @@ namespace ejson { * @return false if an error occured. */ virtual bool iGenerate(std::string& _data, size_t _indent) const = 0; + /** + * @brief Display the Document on console + */ + void display() const; protected: /** * @brief add indentation of the string input. diff --git a/ejson/ejson.cpp b/ejson/ejson.cpp index 82f4a80..81e3159 100644 --- a/ejson/ejson.cpp +++ b/ejson/ejson.cpp @@ -109,11 +109,6 @@ bool ejson::Document::store(const std::string& _file) { return true; } -void ejson::Document::display() { - std::string tmpp; - iGenerate(tmpp, 0); - JSON_INFO("Generated JSON : \n" << tmpp); -} static std::string createPosPointer(const std::string& _line, size_t _pos) { std::string out; diff --git a/ejson/ejson.h b/ejson/ejson.h index 52de0b1..ccc8d72 100644 --- a/ejson/ejson.h +++ b/ejson/ejson.h @@ -57,10 +57,6 @@ namespace ejson { * @return true : Parsing is OK */ bool store(const std::string& _file); - /** - * @brief Display the Document on console - */ - void display(); private: bool m_writeErrorWhenDetexted; std::string m_comment;