[DEV] change dependency on ememeory instead of std::memory

This commit is contained in:
Edouard DUPIN 2016-04-15 21:16:15 +02:00
parent edfa86c201
commit f08b7431e4
19 changed files with 383 additions and 435 deletions

View File

@ -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<<*',

View File

@ -16,26 +16,22 @@
#include <ejson/debug.h>
#include <ejson/ejson.h>
#undef __class__
#define __class__ "Array"
std::shared_ptr<ejson::Array> ejson::Array::create() {
return std::shared_ptr<ejson::Array>(new ejson::Array());
ememory::SharedPtr<ejson::Array> ejson::Array::create() {
return ememory::SharedPtr<ejson::Array>(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<ejson::Object> tmpElement = ejson::Object::create();
ememory::SharedPtr<ejson::Object> 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<ejson::String> tmpElement = ejson::String::create();
ememory::SharedPtr<ejson::String> 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<ejson::Array> tmpElement = ejson::Array::create();
ememory::SharedPtr<ejson::Array> 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<ejson::Boolean> tmpElement = ejson::Boolean::create();
ememory::SharedPtr<ejson::Boolean> 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<ejson::Null> tmpElement = ejson::Null::create();
ememory::SharedPtr<ejson::Null> 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<ejson::Number> tmpElement = ejson::Number::create();
ememory::SharedPtr<ejson::Number> 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<m_value.size() ; iii++) {
std::shared_ptr<const ejson::Value> tmp = m_value[iii];
ememory::SharedPtr<const ejson::Value> 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<const ejson::String> tmp2 = tmp->toString();
ememory::SharedPtr<const ejson::String> 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<ejson::Value> _element) {
bool ejson::Array::add(ememory::SharedPtr<ejson::Value> _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<ejson::Value> _obj) {
bool ejson::Array::transfertIn(ememory::SharedPtr<ejson::Value> _obj) {
if (_obj == nullptr) {
JSON_ERROR("Request transfer on an nullptr pointer");
return false;
}
std::shared_ptr<ejson::Array> other = _obj->toArray();
ememory::SharedPtr<ejson::Array> 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<ejson::Value> _obj) {
}
// TODO : Manage error ...
std::shared_ptr<ejson::Value> ejson::Array::clone() const {
std::shared_ptr<ejson::Array> output = ejson::Array::create();
ememory::SharedPtr<ejson::Value> ejson::Array::clone() const {
ememory::SharedPtr<ejson::Array> output = ejson::Array::create();
if (output == nullptr) {
JSON_ERROR("Allocation error ...");
return std::shared_ptr<ejson::Value>();
return ememory::SharedPtr<ejson::Value>();
}
for (size_t iii=0; iii<m_value.size(); ++iii) {
std::shared_ptr<const ejson::Value> val = m_value[iii];
ememory::SharedPtr<const ejson::Value> val = m_value[iii];
if (val == nullptr) {
continue;
}
@ -256,103 +252,103 @@ std::shared_ptr<ejson::Value> ejson::Array::clone() const {
return output;
}
std::shared_ptr<ejson::Object> ejson::Array::getObject(size_t _id) {
std::shared_ptr<ejson::Value> tmpElement = m_value[_id];
ememory::SharedPtr<ejson::Object> ejson::Array::getObject(size_t _id) {
ememory::SharedPtr<ejson::Value> tmpElement = m_value[_id];
if (tmpElement == nullptr) {
return std::shared_ptr<ejson::Object>();
return ememory::SharedPtr<ejson::Object>();
}
return tmpElement->toObject();
}
const std::shared_ptr<const ejson::Object> ejson::Array::getObject(size_t _id) const {
const std::shared_ptr<const ejson::Value> tmpElement = m_value[_id];
const ememory::SharedPtr<const ejson::Object> ejson::Array::getObject(size_t _id) const {
const ememory::SharedPtr<const ejson::Value> tmpElement = m_value[_id];
if (tmpElement == nullptr) {
return std::shared_ptr<const ejson::Object>();
return ememory::SharedPtr<const ejson::Object>();
}
return tmpElement->toObject();
}
std::shared_ptr<ejson::String> ejson::Array::getString(size_t _id) {
std::shared_ptr<ejson::Value> tmpElement = m_value[_id];
ememory::SharedPtr<ejson::String> ejson::Array::getString(size_t _id) {
ememory::SharedPtr<ejson::Value> tmpElement = m_value[_id];
if (tmpElement == nullptr) {
return std::shared_ptr<ejson::String>();
return ememory::SharedPtr<ejson::String>();
}
return tmpElement->toString();
}
const std::shared_ptr<const ejson::String> ejson::Array::getString(size_t _id) const {
const std::shared_ptr<const ejson::Value> tmpElement = m_value[_id];
const ememory::SharedPtr<const ejson::String> ejson::Array::getString(size_t _id) const {
const ememory::SharedPtr<const ejson::Value> tmpElement = m_value[_id];
if (tmpElement == nullptr) {
return std::shared_ptr<const ejson::String>();
return ememory::SharedPtr<const ejson::String>();
}
return tmpElement->toString();
}
std::shared_ptr<ejson::Array> ejson::Array::getArray(size_t _id) {
std::shared_ptr<ejson::Value> tmpElement = m_value[_id];
ememory::SharedPtr<ejson::Array> ejson::Array::getArray(size_t _id) {
ememory::SharedPtr<ejson::Value> tmpElement = m_value[_id];
if (tmpElement == nullptr) {
return std::shared_ptr<ejson::Array>();
return ememory::SharedPtr<ejson::Array>();
}
return tmpElement->toArray();
}
const std::shared_ptr<const ejson::Array> ejson::Array::getArray(size_t _id) const {
const std::shared_ptr<const ejson::Value> tmpElement = m_value[_id];
const ememory::SharedPtr<const ejson::Array> ejson::Array::getArray(size_t _id) const {
const ememory::SharedPtr<const ejson::Value> tmpElement = m_value[_id];
if (tmpElement == nullptr) {
return std::shared_ptr<const ejson::Array>();
return ememory::SharedPtr<const ejson::Array>();
}
return tmpElement->toArray();
}
std::shared_ptr<ejson::Null> ejson::Array::getNull(size_t _id) {
std::shared_ptr<ejson::Value> tmpElement = m_value[_id];
ememory::SharedPtr<ejson::Null> ejson::Array::getNull(size_t _id) {
ememory::SharedPtr<ejson::Value> tmpElement = m_value[_id];
if (tmpElement == nullptr) {
return std::shared_ptr<ejson::Null>();
return ememory::SharedPtr<ejson::Null>();
}
return tmpElement->toNull();
}
const std::shared_ptr<const ejson::Null> ejson::Array::getNull(size_t _id) const {
const std::shared_ptr<const ejson::Value> tmpElement = m_value[_id];
const ememory::SharedPtr<const ejson::Null> ejson::Array::getNull(size_t _id) const {
const ememory::SharedPtr<const ejson::Value> tmpElement = m_value[_id];
if (tmpElement == nullptr) {
return std::shared_ptr<const ejson::Null>();
return ememory::SharedPtr<const ejson::Null>();
}
return tmpElement->toNull();
}
std::shared_ptr<ejson::Number> ejson::Array::getNumber(size_t _id) {
std::shared_ptr<ejson::Value> tmpElement = m_value[_id];
ememory::SharedPtr<ejson::Number> ejson::Array::getNumber(size_t _id) {
ememory::SharedPtr<ejson::Value> tmpElement = m_value[_id];
if (tmpElement == nullptr) {
return std::shared_ptr<ejson::Number>();
return ememory::SharedPtr<ejson::Number>();
}
return tmpElement->toNumber();
}
const std::shared_ptr<const ejson::Number> ejson::Array::getNumber(size_t _id) const {
const std::shared_ptr<const ejson::Value> tmpElement = m_value[_id];
const ememory::SharedPtr<const ejson::Number> ejson::Array::getNumber(size_t _id) const {
const ememory::SharedPtr<const ejson::Value> tmpElement = m_value[_id];
if (tmpElement == nullptr) {
return std::shared_ptr<const ejson::Number>();
return ememory::SharedPtr<const ejson::Number>();
}
return tmpElement->toNumber();
}
std::shared_ptr<ejson::Boolean> ejson::Array::getBoolean(size_t _id) {
std::shared_ptr<ejson::Value> tmpElement = m_value[_id];
ememory::SharedPtr<ejson::Boolean> ejson::Array::getBoolean(size_t _id) {
ememory::SharedPtr<ejson::Value> tmpElement = m_value[_id];
if (tmpElement == nullptr) {
return std::shared_ptr<ejson::Boolean>();
return ememory::SharedPtr<ejson::Boolean>();
}
return tmpElement->toBoolean();
}
const std::shared_ptr<const ejson::Boolean> ejson::Array::getBoolean(size_t _id) const {
const std::shared_ptr<const ejson::Value> tmpElement = m_value[_id];
const ememory::SharedPtr<const ejson::Boolean> ejson::Array::getBoolean(size_t _id) const {
const ememory::SharedPtr<const ejson::Value> tmpElement = m_value[_id];
if (tmpElement == nullptr) {
return std::shared_ptr<const ejson::Boolean>();
return ememory::SharedPtr<const ejson::Boolean>();
}
return tmpElement->toBoolean();
}
std::string ejson::Array::getStringValue(size_t _id) {
std::shared_ptr<ejson::String> tmpElement = getString(_id);
ememory::SharedPtr<ejson::String> 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<const ejson::String> tmpElement = getString(_id);
const ememory::SharedPtr<const ejson::String> 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<const ejson::String> tmpElement = getString(_id);
const ememory::SharedPtr<const ejson::String> 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<const ejson::Number> tmpElement = getNumber(_id);
const ememory::SharedPtr<const ejson::Number> 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<const ejson::Boolean> tmpElement = getBoolean(_id);
const ememory::SharedPtr<const ejson::Boolean> tmpElement = getBoolean(_id);
if (tmpElement == nullptr) {
return _errorValue;
}

View File

@ -18,13 +18,13 @@ namespace ejson {
*/
Array() { };
public:
static std::shared_ptr<Array> create();
static ememory::SharedPtr<Array> create();
/**
* @brief destructor
*/
virtual ~Array() { };
private:
std::vector<std::shared_ptr<ejson::Value> > m_value; //!< vector of sub elements
std::vector<ememory::SharedPtr<ejson::Value> > 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<ejson::Value> get(size_t _id) {
ememory::SharedPtr<ejson::Value> get(size_t _id) {
return m_value[_id];
};
//! @previous
const std::shared_ptr<const ejson::Value> get(size_t _id) const{
const ememory::SharedPtr<const ejson::Value> get(size_t _id) const{
return m_value[_id];
};
//! @previous
std::shared_ptr<ejson::Value> operator[] (size_t _id) {
ememory::SharedPtr<ejson::Value> operator[] (size_t _id) {
return m_value[_id];
}
//! @previous
const std::shared_ptr<const ejson::Value> operator[] (size_t _id) const {
const ememory::SharedPtr<const ejson::Value> 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<ejson::Object> getObject(size_t _id);
ememory::SharedPtr<ejson::Object> getObject(size_t _id);
//! @previous
const std::shared_ptr<const ejson::Object> getObject(size_t _id) const;
const ememory::SharedPtr<const ejson::Object> 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<ejson::String> getString(size_t _id);
ememory::SharedPtr<ejson::String> getString(size_t _id);
//! @previous
const std::shared_ptr<const ejson::String> getString(size_t _id) const;
const ememory::SharedPtr<const ejson::String> 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<ejson::Array> getArray(size_t _id);
ememory::SharedPtr<ejson::Array> getArray(size_t _id);
//! @previous
const std::shared_ptr<const ejson::Array> getArray(size_t _id) const;
const ememory::SharedPtr<const ejson::Array> 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<ejson::Null> getNull(size_t _id);
ememory::SharedPtr<ejson::Null> getNull(size_t _id);
//! @previous
const std::shared_ptr<const ejson::Null> getNull(size_t _id) const;
const ememory::SharedPtr<const ejson::Null> 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<ejson::Number> getNumber(size_t _id);
ememory::SharedPtr<ejson::Number> getNumber(size_t _id);
//! @previous
const std::shared_ptr<const ejson::Number> getNumber(size_t _id) const;
const ememory::SharedPtr<const ejson::Number> 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<ejson::Boolean> getBoolean(size_t _id);
ememory::SharedPtr<ejson::Boolean> getBoolean(size_t _id);
//! @previous
const std::shared_ptr<const ejson::Boolean> getBoolean(size_t _id) const;
const ememory::SharedPtr<const ejson::Boolean> 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<ejson::Value> _element);
bool add(ememory::SharedPtr<ejson::Value> _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<ejson::Value> _obj);
virtual std::shared_ptr<ejson::Value> clone() const;
virtual bool transfertIn(ememory::SharedPtr<ejson::Value> _obj);
virtual ememory::SharedPtr<ejson::Value> clone() const;
};
}

View File

@ -10,15 +10,12 @@
#include <ejson/debug.h>
#include <ejson/ejson.h>
#undef __class__
#define __class__ "Boolean"
std::shared_ptr<ejson::Boolean> ejson::Boolean::create(bool _value) {
return std::shared_ptr<ejson::Boolean>(new ejson::Boolean(_value));
ememory::SharedPtr<ejson::Boolean> ejson::Boolean::create(bool _value) {
return ememory::SharedPtr<ejson::Boolean>(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<ejson::Value> _obj) {
bool ejson::Boolean::transfertIn(ememory::SharedPtr<ejson::Value> _obj) {
if (_obj == nullptr) {
JSON_ERROR("Request transfer on an NULL pointer");
return false;
}
std::shared_ptr<ejson::Boolean> other = _obj->toBoolean();
ememory::SharedPtr<ejson::Boolean> 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<ejson::Value> _obj) {
return true;
}
std::shared_ptr<ejson::Value> ejson::Boolean::clone() const {
std::shared_ptr<ejson::Boolean> output = ejson::Boolean::create(m_value);
ememory::SharedPtr<ejson::Value> ejson::Boolean::clone() const {
ememory::SharedPtr<ejson::Boolean> output = ejson::Boolean::create(m_value);
if (output == nullptr) {
JSON_ERROR("Allocation error ...");
return std::shared_ptr<ejson::Value>();
return ememory::SharedPtr<ejson::Value>();
}
return output;
}

View File

@ -21,7 +21,7 @@ namespace ejson {
};
public:
static std::shared_ptr<Boolean> create(bool _value=false);
static ememory::SharedPtr<Boolean> 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<ejson::Value> _obj);
virtual std::shared_ptr<ejson::Value> clone() const;
virtual bool transfertIn(ememory::SharedPtr<ejson::Value> _obj);
virtual ememory::SharedPtr<ejson::Value> clone() const;
};
}

View File

@ -6,20 +6,16 @@
* @license APACHE v2.0 (see license file)
*/
#include <ejson/Null.h>
#include <ejson/debug.h>
#include <ejson/ejson.h>
#undef __class__
#define __class__ "Null"
std::shared_ptr<ejson::Null> ejson::Null::create() {
return std::shared_ptr<ejson::Null>(new ejson::Null());
ememory::SharedPtr<ejson::Null> ejson::Null::create() {
return ememory::SharedPtr<ejson::Null>(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<ejson::Value> _obj) {
bool ejson::Null::transfertIn(ememory::SharedPtr<ejson::Value> _obj) {
if (_obj == nullptr) {
JSON_ERROR("Request transfer on an nullptr pointer");
return false;
}
std::shared_ptr<ejson::Null> other = _obj->toNull();
ememory::SharedPtr<ejson::Null> 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<ejson::Value> _obj) {
return true;
}
std::shared_ptr<ejson::Value> ejson::Null::clone() const {
std::shared_ptr<ejson::Null> output = ejson::Null::create();
ememory::SharedPtr<ejson::Value> ejson::Null::clone() const {
ememory::SharedPtr<ejson::Null> output = ejson::Null::create();
if (output == nullptr) {
JSON_ERROR("Allocation error ...");
return std::shared_ptr<ejson::Value>();
return ememory::SharedPtr<ejson::Value>();
}
return output;
}

View File

@ -18,16 +18,16 @@ namespace ejson {
*/
Null() { };
public:
static std::shared_ptr<Null> create();
static ememory::SharedPtr<Null> 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<ejson::Value> _obj);
virtual std::shared_ptr<ejson::Value> clone() const;
virtual bool transfertIn(ememory::SharedPtr<ejson::Value> _obj);
virtual ememory::SharedPtr<ejson::Value> clone() const;
};
}

View File

@ -11,14 +11,11 @@
#include <ejson/debug.h>
#include <ejson/ejson.h>
#undef __class__
#define __class__ "Number"
std::shared_ptr<ejson::Number> ejson::Number::create(double _value) {
return std::shared_ptr<ejson::Number>(new ejson::Number(_value));
ememory::SharedPtr<ejson::Number> ejson::Number::create(double _value) {
return ememory::SharedPtr<ejson::Number>(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<ejson::Value> _obj) {
bool ejson::Number::transfertIn(ememory::SharedPtr<ejson::Value> _obj) {
if (_obj == nullptr) {
JSON_ERROR("Request transfer on an nullptr pointer");
return false;
}
std::shared_ptr<ejson::Number> other = _obj->toNumber();
ememory::SharedPtr<ejson::Number> 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<ejson::Value> _obj) {
return true;
}
std::shared_ptr<ejson::Value> ejson::Number::clone() const {
std::shared_ptr<ejson::Number> output = ejson::Number::create(m_value);
ememory::SharedPtr<ejson::Value> ejson::Number::clone() const {
ememory::SharedPtr<ejson::Number> output = ejson::Number::create(m_value);
if (output == nullptr) {
JSON_ERROR("Allocation error ...");
return std::shared_ptr<ejson::Value>();
return ememory::SharedPtr<ejson::Value>();
}
return output;
}

View File

@ -21,7 +21,7 @@ namespace ejson {
};
public:
static std::shared_ptr<Number> create(double _value=0.0);
static ememory::SharedPtr<Number> 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<ejson::Value> _obj);
virtual std::shared_ptr<ejson::Value> clone() const;
virtual bool transfertIn(ememory::SharedPtr<ejson::Value> _obj);
virtual ememory::SharedPtr<ejson::Value> clone() const;
};
}

View File

@ -16,15 +16,11 @@
#include <ejson/debug.h>
#include <ejson/ejson.h>
#undef __class__
#define __class__ "Object"
std::shared_ptr<ejson::Object> ejson::Object::create() {
return std::shared_ptr<ejson::Object>(new ejson::Object());
ememory::SharedPtr<ejson::Object> ejson::Object::create() {
return ememory::SharedPtr<ejson::Object>(new ejson::Object());
}
std::shared_ptr<ejson::Object> ejson::Object::create(const std::string& _data) {
ememory::SharedPtr<ejson::Object> 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<ejson::Object> tmpElement = ejson::Object::create();
ememory::SharedPtr<ejson::Object> 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<ejson::String> tmpElement = ejson::String::create();
ememory::SharedPtr<ejson::String> 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<ejson::Array> tmpElement = ejson::Array::create();
ememory::SharedPtr<ejson::Array> 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<ejson::Boolean> tmpElement = ejson::Boolean::create();
ememory::SharedPtr<ejson::Boolean> 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<ejson::Null> tmpElement = ejson::Null::create();
ememory::SharedPtr<ejson::Null> 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<ejson::Number> tmpElement = ejson::Number::create();
ememory::SharedPtr<ejson::Number> 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<m_value.size() ; iii++) {
std::shared_ptr<ejson::Value> tmp = m_value[iii];
ememory::SharedPtr<ejson::Value> 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<ejson::String> tmp2 = tmp->toString();
ememory::SharedPtr<ejson::String> 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::Value> ejson::Object::get(const std::string& _name) {
ememory::SharedPtr<ejson::Value> ejson::Object::get(const std::string& _name) {
if (false == m_value.exist(_name)) {
return std::shared_ptr<ejson::Value>();
return ememory::SharedPtr<ejson::Value>();
}
return m_value[_name];
}
const std::shared_ptr<const ejson::Value> ejson::Object::get(const std::string& _name) const {
const ememory::SharedPtr<const ejson::Value> ejson::Object::get(const std::string& _name) const {
if (false == m_value.exist(_name)) {
return std::shared_ptr<const ejson::Value>();
return ememory::SharedPtr<const ejson::Value>();
}
return m_value[_name];
}
std::shared_ptr<ejson::Object> ejson::Object::getObject(const std::string& _name) {
std::shared_ptr<ejson::Value> tmp = get(_name);
ememory::SharedPtr<ejson::Object> ejson::Object::getObject(const std::string& _name) {
ememory::SharedPtr<ejson::Value> tmp = get(_name);
if (tmp == nullptr) {
return std::shared_ptr<ejson::Object>();
return ememory::SharedPtr<ejson::Object>();
}
return std::dynamic_pointer_cast<ejson::Object>(tmp);
}
const std::shared_ptr<const ejson::Object> ejson::Object::getObject(const std::string& _name) const {
const std::shared_ptr<const ejson::Value> tmp = get(_name);
const ememory::SharedPtr<const ejson::Object> ejson::Object::getObject(const std::string& _name) const {
const ememory::SharedPtr<const ejson::Value> tmp = get(_name);
if (tmp == nullptr) {
return std::shared_ptr<const ejson::Object>();
return ememory::SharedPtr<const ejson::Object>();
}
return std::dynamic_pointer_cast<const ejson::Object>(tmp);
}
std::shared_ptr<ejson::Array> ejson::Object::getArray(const std::string& _name) {
std::shared_ptr<ejson::Value> tmp = get(_name);
ememory::SharedPtr<ejson::Array> ejson::Object::getArray(const std::string& _name) {
ememory::SharedPtr<ejson::Value> tmp = get(_name);
if (tmp == nullptr) {
return std::shared_ptr<ejson::Array>();
return ememory::SharedPtr<ejson::Array>();
}
return std::dynamic_pointer_cast<ejson::Array>(tmp);
}
const std::shared_ptr<const ejson::Array> ejson::Object::getArray(const std::string& _name) const {
const std::shared_ptr<const ejson::Value> tmp = get(_name);
const ememory::SharedPtr<const ejson::Array> ejson::Object::getArray(const std::string& _name) const {
const ememory::SharedPtr<const ejson::Value> tmp = get(_name);
if (tmp == nullptr) {
return std::shared_ptr<const ejson::Array>();
return ememory::SharedPtr<const ejson::Array>();
}
return std::dynamic_pointer_cast<const ejson::Array>(tmp);
}
std::shared_ptr<ejson::Null> ejson::Object::getNull(const std::string& _name) {
std::shared_ptr<ejson::Value> tmp = get(_name);
ememory::SharedPtr<ejson::Null> ejson::Object::getNull(const std::string& _name) {
ememory::SharedPtr<ejson::Value> tmp = get(_name);
if (tmp == nullptr) {
return std::shared_ptr<ejson::Null>();
return ememory::SharedPtr<ejson::Null>();
}
return std::dynamic_pointer_cast<ejson::Null>(tmp);
}
const std::shared_ptr<const ejson::Null> ejson::Object::getNull(const std::string& _name) const {
const std::shared_ptr<const ejson::Value> tmp = get(_name);
const ememory::SharedPtr<const ejson::Null> ejson::Object::getNull(const std::string& _name) const {
const ememory::SharedPtr<const ejson::Value> tmp = get(_name);
if (tmp == nullptr) {
return std::shared_ptr<const ejson::Null>();
return ememory::SharedPtr<const ejson::Null>();
}
return std::dynamic_pointer_cast<const ejson::Null>(tmp);
}
std::shared_ptr<ejson::String> ejson::Object::getString(const std::string& _name) {
std::shared_ptr<ejson::Value> tmp = get(_name);
ememory::SharedPtr<ejson::String> ejson::Object::getString(const std::string& _name) {
ememory::SharedPtr<ejson::Value> tmp = get(_name);
if (tmp == nullptr) {
return std::shared_ptr<ejson::String>();
return ememory::SharedPtr<ejson::String>();
}
return std::dynamic_pointer_cast<ejson::String>(tmp);
}
const std::shared_ptr<const ejson::String> ejson::Object::getString(const std::string& _name) const {
const std::shared_ptr<const ejson::Value> tmp = get(_name);
const ememory::SharedPtr<const ejson::String> ejson::Object::getString(const std::string& _name) const {
const ememory::SharedPtr<const ejson::Value> tmp = get(_name);
if (tmp == nullptr) {
return std::shared_ptr<const ejson::String>();
return ememory::SharedPtr<const ejson::String>();
}
return std::dynamic_pointer_cast<const ejson::String>(tmp);
}
const std::string& ejson::Object::getStringValue(const std::string& _name) const {
static const std::string errorString("");
const std::shared_ptr<const ejson::String> tmpp = getString(_name);
const ememory::SharedPtr<const ejson::String> 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<const ejson::String> tmpp = getString(_name);
const ememory::SharedPtr<const ejson::String> tmpp = getString(_name);
if (tmpp == nullptr) {
return _errorValue;
}
return tmpp->get();
}
std::shared_ptr<ejson::Boolean> ejson::Object::getBoolean(const std::string& _name) {
std::shared_ptr<ejson::Value> tmp = get(_name);
ememory::SharedPtr<ejson::Boolean> ejson::Object::getBoolean(const std::string& _name) {
ememory::SharedPtr<ejson::Value> tmp = get(_name);
if (tmp == nullptr) {
return std::shared_ptr<ejson::Boolean>();
return ememory::SharedPtr<ejson::Boolean>();
}
return tmp->toBoolean();
}
const std::shared_ptr<const ejson::Boolean> ejson::Object::getBoolean(const std::string& _name) const {
const std::shared_ptr<const ejson::Value> tmp = get(_name);
const ememory::SharedPtr<const ejson::Boolean> ejson::Object::getBoolean(const std::string& _name) const {
const ememory::SharedPtr<const ejson::Value> tmp = get(_name);
if (tmp == nullptr) {
return std::shared_ptr<const ejson::Boolean>();
return ememory::SharedPtr<const ejson::Boolean>();
}
return tmp->toBoolean();
}
bool ejson::Object::getBooleanValue(const std::string& _name, bool _errorValue) const {
const std::shared_ptr<const ejson::Boolean> tmpp = getBoolean(_name);
const ememory::SharedPtr<const ejson::Boolean> tmpp = getBoolean(_name);
if (tmpp == nullptr) {
return _errorValue;
}
return tmpp->get();
}
std::shared_ptr<ejson::Number> ejson::Object::getNumber(const std::string& _name) {
std::shared_ptr<ejson::Value> tmp = get(_name);
ememory::SharedPtr<ejson::Number> ejson::Object::getNumber(const std::string& _name) {
ememory::SharedPtr<ejson::Value> tmp = get(_name);
if (tmp == nullptr) {
return std::shared_ptr<ejson::Number>();
return ememory::SharedPtr<ejson::Number>();
}
return tmp->toNumber();
}
const std::shared_ptr<const ejson::Number> ejson::Object::getNumber(const std::string& _name) const {
const std::shared_ptr<const ejson::Value> tmp = get(_name);
const ememory::SharedPtr<const ejson::Number> ejson::Object::getNumber(const std::string& _name) const {
const ememory::SharedPtr<const ejson::Value> tmp = get(_name);
if (tmp == nullptr) {
return std::shared_ptr<const ejson::Number>();
return ememory::SharedPtr<const ejson::Number>();
}
return tmp->toNumber();
}
double ejson::Object::getNumberValue(const std::string& _name, double _errorValue) const {
const std::shared_ptr<const ejson::Number> tmpp = getNumber(_name);
const ememory::SharedPtr<const ejson::Number> 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<ejson::Value> _value) {
bool ejson::Object::add(const std::string& _name, ememory::SharedPtr<ejson::Value> _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<ejson::Value> _obj) {
bool ejson::Object::transfertIn(ememory::SharedPtr<ejson::Value> _obj) {
if (_obj == nullptr) {
JSON_ERROR("Request transfer on an nullptr pointer");
return false;
}
std::shared_ptr<ejson::Object> other = _obj->toObject();
ememory::SharedPtr<ejson::Object> 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<ejson::Value> _obj) {
return true;
}
bool ejson::Object::cloneIn(const std::shared_ptr<ejson::Object>& _obj) const {
bool ejson::Object::cloneIn(const ememory::SharedPtr<ejson::Object>& _obj) const {
if (_obj == nullptr) {
return false;
}
@ -490,18 +486,18 @@ bool ejson::Object::cloneIn(const std::shared_ptr<ejson::Object>& _obj) const {
// TODO : Manage error ...
std::shared_ptr<ejson::Value> ejson::Object::clone() const {
ememory::SharedPtr<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();
ememory::SharedPtr<ejson::Object> ejson::Object::cloneObj() const {
ememory::SharedPtr<ejson::Object> output = ejson::Object::create();
if (output == nullptr) {
JSON_ERROR("Allocation error ...");
return std::shared_ptr<ejson::Object>();
return ememory::SharedPtr<ejson::Object>();
}
for (int32_t iii=0; iii<m_value.size(); ++iii) {
std::shared_ptr<ejson::Value> val = m_value.getValue(iii);
ememory::SharedPtr<ejson::Value> val = m_value.getValue(iii);
std::string key = m_value.getKey(iii);
if (val == nullptr) {
continue;

View File

@ -20,14 +20,14 @@ namespace ejson {
*/
Object() { };
public:
static std::shared_ptr<Object> create();
static std::shared_ptr<Object> create(const std::string& _data);
static ememory::SharedPtr<Object> create();
static ememory::SharedPtr<Object> create(const std::string& _data);
/**
* @brief destructor
*/
virtual ~Object() { };
protected:
etk::Hash<std::shared_ptr<ejson::Value> > m_value; //!< value of the node (for element this is the name, for text it is the inside text ...)
etk::Hash<ememory::SharedPtr<ejson::Value> > 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<ejson::Value> get(const std::string& _name);
ememory::SharedPtr<ejson::Value> get(const std::string& _name);
//! @previous
const std::shared_ptr<const ejson::Value> get(const std::string& _name) const;
const ememory::SharedPtr<const ejson::Value> get(const std::string& _name) const;
//! @previous
std::shared_ptr<ejson::Value> operator[] (const std::string& _name) {
ememory::SharedPtr<ejson::Value> operator[] (const std::string& _name) {
return get(_name);
}
//! @previous
const std::shared_ptr<const ejson::Value> operator[] (const std::string& _name) const {
const ememory::SharedPtr<const ejson::Value> 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<ejson::Value> get(size_t _id) {
ememory::SharedPtr<ejson::Value> get(size_t _id) {
return m_value[_id];
};
//! @previous
const std::shared_ptr<const ejson::Value> get(size_t _id) const{
const ememory::SharedPtr<const ejson::Value> get(size_t _id) const{
return m_value[_id];
};
//! @previous
std::shared_ptr<ejson::Value> operator[] (size_t _id) {
ememory::SharedPtr<ejson::Value> operator[] (size_t _id) {
return m_value[_id];
}
//! @previous
const std::shared_ptr<const ejson::Value> operator[] (size_t _id) const {
const ememory::SharedPtr<const ejson::Value> 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<ejson::Object> getObject(const std::string& _name);
//! @previous
const std::shared_ptr<const ejson::Object> getObject(const std::string& _name) const;
ememory::SharedPtr<ejson::Object> 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<const ejson::Object> 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<ejson::Array> getArray(const std::string& _name);
//! @previous
const std::shared_ptr<const ejson::Array> getArray(const std::string& _name) const;
ememory::SharedPtr<ejson::Array> 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<const ejson::Array> 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<ejson::Null> getNull(const std::string& _name);
ememory::SharedPtr<ejson::Null> getNull(const std::string& _name);
//! @previous
const std::shared_ptr<const ejson::Null> getNull(const std::string& _name) const;
const ememory::SharedPtr<const ejson::Null> 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<ejson::String> getString(const std::string& _name);
ememory::SharedPtr<ejson::String> getString(const std::string& _name);
//! @previous
const std::shared_ptr<const ejson::String> getString(const std::string& _name) const;
const ememory::SharedPtr<const ejson::String> 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<ejson::Boolean> getBoolean(const std::string& _name);
ememory::SharedPtr<ejson::Boolean> getBoolean(const std::string& _name);
//! @previous
const std::shared_ptr<const ejson::Boolean> getBoolean(const std::string& _name) const;
const ememory::SharedPtr<const ejson::Boolean> 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<ejson::Number> getNumber(const std::string& _name);
ememory::SharedPtr<ejson::Number> getNumber(const std::string& _name);
//! @previous
const std::shared_ptr<const ejson::Number> getNumber(const std::string& _name) const;
const ememory::SharedPtr<const ejson::Number> 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<ejson::Value> _value);
bool add(const std::string& _name, ememory::SharedPtr<ejson::Value> _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<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;
virtual bool transfertIn(ememory::SharedPtr<ejson::Value> _obj);
virtual bool cloneIn(const ememory::SharedPtr<ejson::Object>& _obj) const;
virtual ememory::SharedPtr<ejson::Value> clone() const;
virtual ememory::SharedPtr<ejson::Object> cloneObj() const;
};
}

View File

@ -13,15 +13,11 @@
#include <ejson/debug.h>
#include <ejson/ejson.h>
#undef __class__
#define __class__ "String"
std::shared_ptr<ejson::String> ejson::String::create(const std::string& _value) {
return std::shared_ptr<ejson::String>(new ejson::String(_value));
ememory::SharedPtr<ejson::String> ejson::String::create(const std::string& _value) {
return ememory::SharedPtr<ejson::String>(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<ejson::Value> _obj) {
bool ejson::String::transfertIn(ememory::SharedPtr<ejson::Value> _obj) {
if (_obj == nullptr) {
JSON_ERROR("Request transfer on an nullptr pointer");
return false;
}
std::shared_ptr<ejson::String> other = _obj->toString();
ememory::SharedPtr<ejson::String> 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<ejson::Value> _obj) {
return true;
}
std::shared_ptr<ejson::Value> ejson::String::clone() const {
std::shared_ptr<ejson::String> output = ejson::String::create(m_value);
ememory::SharedPtr<ejson::Value> ejson::String::clone() const {
ememory::SharedPtr<ejson::String> output = ejson::String::create(m_value);
if (output == nullptr) {
JSON_ERROR("Allocation error ...");
return std::shared_ptr<ejson::Value>();
return ememory::SharedPtr<ejson::Value>();
}
return output;
}

View File

@ -21,7 +21,7 @@ namespace ejson {
};
public:
static std::shared_ptr<String> create(const std::string& _value="");
static ememory::SharedPtr<String> 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<ejson::Value> _obj);
virtual std::shared_ptr<ejson::Value> clone() const;
virtual bool transfertIn(ememory::SharedPtr<ejson::Value> _obj);
virtual ememory::SharedPtr<ejson::Value> clone() const;
};
}

View File

@ -10,23 +10,10 @@
#include <ejson/debug.h>
#include <ejson/ejson.h>
#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> ejson::Value::toValue() {
ememory::SharedPtr<ejson::Value> ejson::Value::toValue() {
return shared_from_this();
};
const std::shared_ptr<const ejson::Value> ejson::Value::toValue() const {
const ememory::SharedPtr<const ejson::Value> ejson::Value::toValue() const {
return shared_from_this();
};
std::shared_ptr<ejson::Document> ejson::Value::toDocument() {
ememory::SharedPtr<ejson::Document> ejson::Value::toDocument() {
return std::dynamic_pointer_cast<ejson::Document>(shared_from_this());
};
const std::shared_ptr<const ejson::Document> ejson::Value::toDocument() const {
const ememory::SharedPtr<const ejson::Document> ejson::Value::toDocument() const {
return std::dynamic_pointer_cast<const ejson::Document>(shared_from_this());
};
std::shared_ptr<ejson::Array> ejson::Value::toArray() {
ememory::SharedPtr<ejson::Array> ejson::Value::toArray() {
return std::dynamic_pointer_cast<ejson::Array>(shared_from_this());
};
const std::shared_ptr<const ejson::Array> ejson::Value::toArray() const{
const ememory::SharedPtr<const ejson::Array> ejson::Value::toArray() const{
return std::dynamic_pointer_cast<const ejson::Array>(shared_from_this());
};
std::shared_ptr<ejson::Object> ejson::Value::toObject() {
ememory::SharedPtr<ejson::Object> ejson::Value::toObject() {
return std::dynamic_pointer_cast<ejson::Object>(shared_from_this());
};
const std::shared_ptr<const ejson::Object> ejson::Value::toObject() const{
const ememory::SharedPtr<const ejson::Object> ejson::Value::toObject() const{
return std::dynamic_pointer_cast<const ejson::Object>(shared_from_this());
};
std::shared_ptr<ejson::String> ejson::Value::toString() {
ememory::SharedPtr<ejson::String> ejson::Value::toString() {
return std::dynamic_pointer_cast<ejson::String>(shared_from_this());
};
const std::shared_ptr<const ejson::String> ejson::Value::toString() const{
const ememory::SharedPtr<const ejson::String> ejson::Value::toString() const{
return std::dynamic_pointer_cast<const ejson::String>(shared_from_this());
};
std::shared_ptr<ejson::Number> ejson::Value::toNumber() {
ememory::SharedPtr<ejson::Number> ejson::Value::toNumber() {
return std::dynamic_pointer_cast<ejson::Number>(shared_from_this());
};
const std::shared_ptr<const ejson::Number> ejson::Value::toNumber() const{
const ememory::SharedPtr<const ejson::Number> ejson::Value::toNumber() const{
return std::dynamic_pointer_cast<const ejson::Number>(shared_from_this());
};
std::shared_ptr<ejson::Boolean> ejson::Value::toBoolean() {
ememory::SharedPtr<ejson::Boolean> ejson::Value::toBoolean() {
return std::dynamic_pointer_cast<ejson::Boolean>(shared_from_this());
};
const std::shared_ptr<const ejson::Boolean> ejson::Value::toBoolean() const{
const ememory::SharedPtr<const ejson::Boolean> ejson::Value::toBoolean() const{
return std::dynamic_pointer_cast<const ejson::Boolean>(shared_from_this());
};
std::shared_ptr<ejson::Null> ejson::Value::toNull() {
ememory::SharedPtr<ejson::Null> ejson::Value::toNull() {
return std::dynamic_pointer_cast<ejson::Null>(shared_from_this());
};
const std::shared_ptr<const ejson::Null> ejson::Value::toNull() const{
const ememory::SharedPtr<const ejson::Null> ejson::Value::toNull() const{
return std::dynamic_pointer_cast<const ejson::Null>(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<ejson::Value> _obj) {
return false;
}
ememory::SharedPtr<ejson::Value> ejson::Value::clone() const {
return ememory::SharedPtr<ejson::Value>();
}

View File

@ -8,9 +8,12 @@
#pragma once
#include <etk/types.h>
#include <memory>
#include <ememory/memory.h>
#include <ejson/FilePos.h>
/**
* @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<Value> {
/**
* @brief Basic main object of all json elements.
*/
class Value : public ememory::EnableSharedFromThis<Value> {
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<ejson::Value> toValue();
//! @previous
const std::shared_ptr<const ejson::Value> toValue() const;
ememory::SharedPtr<ejson::Value> toValue();
/**
* @brief Cast the element in a Value if it is possible.
* @return CONST pointer on the class or nullptr.
*/
const ememory::SharedPtr<const ejson::Value> toValue() const;
/**
* @brief Cast the element in a Document if it is possible.
* @return pointer on the class or nullptr.
*/
std::shared_ptr<ejson::Document> toDocument();
//! @previous
const std::shared_ptr<const ejson::Document> toDocument() const;
ememory::SharedPtr<ejson::Document> toDocument();
/**
* @brief Cast the element in a Document if it is possible.
* @return CONST pointer on the class or nullptr.
*/
const ememory::SharedPtr<const ejson::Document> toDocument() const;
/**
* @brief Cast the element in a Array if it is possible.
* @return pointer on the class or nullptr.
*/
std::shared_ptr<ejson::Array> toArray();
//! @previous
const std::shared_ptr<const ejson::Array> toArray() const;
ememory::SharedPtr<ejson::Array> toArray();
/**
* @brief Cast the element in a Array if it is possible.
* @return CONST pointer on the class or nullptr.
*/
const ememory::SharedPtr<const ejson::Array> toArray() const;
/**
* @brief Cast the element in a Object if it is possible.
* @return pointer on the class or nullptr.
*/
std::shared_ptr<ejson::Object> toObject();
//! @previous
const std::shared_ptr<const ejson::Object> toObject() const;
ememory::SharedPtr<ejson::Object> toObject();
/**
* @brief Cast the element in a Object if it is possible.
* @return CONST pointer on the class or nullptr.
*/
const ememory::SharedPtr<const ejson::Object> toObject() const;
/**
* @brief Cast the element in a String if it is possible.
* @return pointer on the class or nullptr.
*/
std::shared_ptr<ejson::String> toString();
//! @previous
const std::shared_ptr<const ejson::String> toString() const;
ememory::SharedPtr<ejson::String> toString();
/**
* @brief Cast the element in a String if it is possible.
* @return CONST pointer on the class or nullptr.
*/
const ememory::SharedPtr<const ejson::String> toString() const;
/**
* @brief Cast the element in a Number if it is possible.
* @return pointer on the class or nullptr.
*/
std::shared_ptr<ejson::Number> toNumber();
//! @previous
const std::shared_ptr<const ejson::Number> toNumber() const;
ememory::SharedPtr<ejson::Number> toNumber();
/**
* @brief Cast the element in a Number if it is possible.
* @return CONST pointer on the class or nullptr.
*/
const ememory::SharedPtr<const ejson::Number> toNumber() const;
/**
* @brief Cast the element in a Boolean if it is possible.
* @return pointer on the class or nullptr.
*/
std::shared_ptr<ejson::Boolean> toBoolean();
//! @previous
const std::shared_ptr<const ejson::Boolean> toBoolean() const;
ememory::SharedPtr<ejson::Boolean> toBoolean();
/**
* @brief Cast the element in a Boolean if it is possible.
* @return CONST pointer on the class or nullptr.
*/
const ememory::SharedPtr<const ejson::Boolean> toBoolean() const;
/**
* @brief Cast the element in a Null if it is possible.
* @return pointer on the class or nullptr.
*/
std::shared_ptr<ejson::Null> toNull();
//! @previous
const std::shared_ptr<const ejson::Null> toNull() const;
ememory::SharedPtr<ejson::Null> toNull();
/**
* @brief Cast the element in a Null if it is possible.
* @return CONST pointer on the class or nullptr.
*/
const ememory::SharedPtr<const ejson::Null> 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<ejson::Value> _obj) {
return false;
};
virtual bool transfertIn(ememory::SharedPtr<ejson::Value> _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<ejson::Value> clone() const {
return std::shared_ptr<ejson::Value>();
};
virtual ememory::SharedPtr<ejson::Value> clone() const;
protected:
/**
* @brief check if the current element is white or not : '\t' '\n' '\r' ' '

View File

@ -17,12 +17,8 @@
#include <ejson/Number.h>
#include <ejson/Boolean.h>
#undef __class__
#define __class__ "Document"
std::shared_ptr<ejson::Document> ejson::Document::create() {
return std::shared_ptr<ejson::Document>(new ejson::Document());
ememory::SharedPtr<ejson::Document> ejson::Document::create() {
return ememory::SharedPtr<ejson::Document>(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'

View File

@ -21,7 +21,7 @@ namespace ejson {
* @brief Constructor
*/
Document();
static std::shared_ptr<Document> create();
static ememory::SharedPtr<Document> 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;
};
};

View File

@ -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',

View File

@ -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<char **>(argv));