[DEV] modify interface

This commit is contained in:
Edouard DUPIN 2015-01-23 21:23:43 +01:00
parent dd2c3b15e9
commit 5e0c804a56
6 changed files with 30 additions and 10 deletions

View File

@ -471,8 +471,24 @@ bool ejson::Object::transfertIn(std::shared_ptr<ejson::Value> _obj) {
return true;
}
bool ejson::Object::cloneIn(const std::shared_ptr<ejson::Object>& _obj) const {
if (_obj == nullptr) {
return false;
}
_obj->clear();
for (int32_t iii=0; iii<m_value.size(); ++iii) {
_obj->add(m_value.getKey(iii), m_value[iii]->clone());
}
return true;
}
// TODO : Manage error ...
std::shared_ptr<ejson::Value> ejson::Object::clone() const {
return cloneObj();
}
std::shared_ptr<ejson::Object> ejson::Object::cloneObj() const {
std::shared_ptr<ejson::Object> output = ejson::Object::create();
if (output == nullptr) {
JSON_ERROR("Allocation error ...");

View File

@ -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<ejson::Value> _obj);
virtual bool cloneIn(const std::shared_ptr<ejson::Object>& _obj) const;
virtual std::shared_ptr<ejson::Value> clone() const;
virtual std::shared_ptr<ejson::Object> cloneObj() const;
};
};

View File

@ -163,4 +163,11 @@ std::shared_ptr<ejson::Null> ejson::Value::toNull() {
};
const std::shared_ptr<const ejson::Null> ejson::Value::toNull() const{
return std::dynamic_pointer_cast<const ejson::Null>(shared_from_this());
};
};
void ejson::Value::display() const {
std::string tmpp;
iGenerate(tmpp, 0);
JSON_INFO("Generated JSON : \n" << tmpp);
}

View File

@ -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.

View File

@ -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;

View File

@ -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;