[DEV] add extra compilation flags & correct warning

This commit is contained in:
Edouard DUPIN 2013-11-27 21:33:34 +01:00
parent 564ec3130f
commit 7593b52dd9
17 changed files with 103 additions and 99 deletions

View File

@ -21,7 +21,7 @@
void ejson::Array::clear(void) { void ejson::Array::clear(void) {
for (esize_t iii=0; iii<m_value.size(); ++iii) { for (size_t iii=0; iii<m_value.size(); ++iii) {
if (NULL == m_value[iii]) { if (NULL == m_value[iii]) {
continue; continue;
} }
@ -31,9 +31,9 @@ void ejson::Array::clear(void) {
m_value.clear(); m_value.clear();
} }
bool ejson::Array::iParse(const std::string& _data, int32_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' "); JSON_PARSE_ELEMENT("start parse : 'Object' ");
for (int32_t iii=_pos+1; iii<_data.size(); iii++) { for (size_t iii=_pos+1; iii<_data.size(); iii++) {
_filePos.check(_data[iii]); _filePos.check(_data[iii]);
#ifdef ENABLE_DISPLAY_PARSED_ELEMENT #ifdef ENABLE_DISPLAY_PARSED_ELEMENT
drawElementParsed(_data[iii], _filePos); drawElementParsed(_data[iii], _filePos);
@ -131,12 +131,12 @@ bool ejson::Array::iParse(const std::string& _data, int32_t& _pos, ejson::filePo
} }
bool ejson::Array::iGenerate(std::string& _data, int32_t _indent) const { bool ejson::Array::iGenerate(std::string& _data, size_t _indent) const {
bool oneLine=true; bool oneLine=true;
if (m_value.size()>3) { if (m_value.size()>3) {
oneLine=false; oneLine=false;
} else { } else {
for (esize_t iii=0; iii<m_value.size() ; iii++) { for (size_t iii=0; iii<m_value.size() ; iii++) {
ejson::Value* tmp = m_value[iii]; ejson::Value* tmp = m_value[iii];
if (tmp == NULL) { if (tmp == NULL) {
continue; continue;
@ -165,7 +165,7 @@ bool ejson::Array::iGenerate(std::string& _data, int32_t _indent) const {
} else { } else {
_data += "[\n"; _data += "[\n";
} }
for (esize_t iii=0; iii<m_value.size() ; iii++) { for (size_t iii=0; iii<m_value.size() ; iii++) {
if (false == oneLine) { if (false == oneLine) {
addIndent(_data, _indent); addIndent(_data, _indent);
} }
@ -240,7 +240,7 @@ ejson::Value* ejson::Array::duplicate(void) const {
JSON_ERROR("Allocation error ..."); JSON_ERROR("Allocation error ...");
return NULL; return NULL;
} }
for (esize_t iii=0; iii<m_value.size(); ++iii) { for (size_t iii=0; iii<m_value.size(); ++iii) {
ejson::Value* val = m_value[iii]; ejson::Value* val = m_value[iii];
if (NULL == val) { if (NULL == val) {
continue; continue;
@ -250,7 +250,7 @@ ejson::Value* ejson::Array::duplicate(void) const {
return output; return output;
} }
ejson::Object* ejson::Array::getObject(esize_t _id) { ejson::Object* ejson::Array::getObject(size_t _id) {
ejson::Value* tmpElement = m_value[_id]; ejson::Value* tmpElement = m_value[_id];
if (NULL == tmpElement) { if (NULL == tmpElement) {
return NULL; return NULL;
@ -258,7 +258,7 @@ ejson::Object* ejson::Array::getObject(esize_t _id) {
return tmpElement->toObject(); return tmpElement->toObject();
} }
ejson::String* ejson::Array::getString(esize_t _id) { ejson::String* ejson::Array::getString(size_t _id) {
ejson::Value* tmpElement = m_value[_id]; ejson::Value* tmpElement = m_value[_id];
if (NULL == tmpElement) { if (NULL == tmpElement) {
return NULL; return NULL;
@ -266,7 +266,7 @@ ejson::String* ejson::Array::getString(esize_t _id) {
return tmpElement->toString(); return tmpElement->toString();
} }
ejson::Array* ejson::Array::getArray(esize_t _id) { ejson::Array* ejson::Array::getArray(size_t _id) {
ejson::Value* tmpElement = m_value[_id]; ejson::Value* tmpElement = m_value[_id];
if (NULL == tmpElement) { if (NULL == tmpElement) {
return NULL; return NULL;
@ -274,7 +274,7 @@ ejson::Array* ejson::Array::getArray(esize_t _id) {
return tmpElement->toArray(); return tmpElement->toArray();
} }
ejson::Null* ejson::Array::getNull(esize_t _id) { ejson::Null* ejson::Array::getNull(size_t _id) {
ejson::Value* tmpElement = m_value[_id]; ejson::Value* tmpElement = m_value[_id];
if (NULL == tmpElement) { if (NULL == tmpElement) {
return NULL; return NULL;
@ -282,7 +282,7 @@ ejson::Null* ejson::Array::getNull(esize_t _id) {
return tmpElement->toNull(); return tmpElement->toNull();
} }
ejson::Number* ejson::Array::getNumber(esize_t _id) { ejson::Number* ejson::Array::getNumber(size_t _id) {
ejson::Value* tmpElement = m_value[_id]; ejson::Value* tmpElement = m_value[_id];
if (NULL == tmpElement) { if (NULL == tmpElement) {
return NULL; return NULL;
@ -290,7 +290,7 @@ ejson::Number* ejson::Array::getNumber(esize_t _id) {
return tmpElement->toNumber(); return tmpElement->toNumber();
} }
ejson::Boolean* ejson::Array::getBoolean(esize_t _id) { ejson::Boolean* ejson::Array::getBoolean(size_t _id) {
ejson::Value* tmpElement = m_value[_id]; ejson::Value* tmpElement = m_value[_id];
if (NULL == tmpElement) { if (NULL == tmpElement) {
return NULL; return NULL;
@ -298,7 +298,7 @@ ejson::Boolean* ejson::Array::getBoolean(esize_t _id) {
return tmpElement->toBoolean(); return tmpElement->toBoolean();
} }
const std::string& ejson::Array::getStringValue(esize_t _id) { const std::string& ejson::Array::getStringValue(size_t _id) {
static const std::string errorValue(""); static const std::string errorValue("");
ejson::String* tmpElement = getString(_id); ejson::String* tmpElement = getString(_id);
if (NULL == tmpElement) { if (NULL == tmpElement) {
@ -307,7 +307,7 @@ const std::string& ejson::Array::getStringValue(esize_t _id) {
return tmpElement->get(); return tmpElement->get();
} }
std::string ejson::Array::getStringValue(esize_t _id, const std::string& _errorValue) { std::string ejson::Array::getStringValue(size_t _id, const std::string& _errorValue) {
ejson::String* tmpElement = getString(_id); ejson::String* tmpElement = getString(_id);
if (NULL == tmpElement) { if (NULL == tmpElement) {
return _errorValue; return _errorValue;
@ -315,7 +315,7 @@ std::string ejson::Array::getStringValue(esize_t _id, const std::string& _errorV
return tmpElement->get(); return tmpElement->get();
} }
double ejson::Array::getNumberValue(esize_t _id, double _errorValue) { double ejson::Array::getNumberValue(size_t _id, double _errorValue) {
ejson::Number* tmpElement = getNumber(_id); ejson::Number* tmpElement = getNumber(_id);
if (NULL == tmpElement) { if (NULL == tmpElement) {
return _errorValue; return _errorValue;
@ -323,7 +323,7 @@ double ejson::Array::getNumberValue(esize_t _id, double _errorValue) {
return tmpElement->get(); return tmpElement->get();
} }
bool ejson::Array::getBooleanValue(esize_t _id, bool _errorValue) { bool ejson::Array::getBooleanValue(size_t _id, bool _errorValue) {
ejson::Boolean* tmpElement = getBoolean(_id); ejson::Boolean* tmpElement = getBoolean(_id);
if (NULL == tmpElement) { if (NULL == tmpElement) {
return _errorValue; return _errorValue;

View File

@ -38,7 +38,7 @@ namespace ejson
* @brief get the number of sub element in the current one * @brief get the number of sub element in the current one
* @return the Number of stored element * @return the Number of stored element
*/ */
esize_t size(void) const { size_t size(void) const {
return m_value.size(); return m_value.size();
}; };
/** /**
@ -46,10 +46,10 @@ namespace ejson
* @param[in] _id Id of the element. * @param[in] _id Id of the element.
* @return NULL if the element does not exist. * @return NULL if the element does not exist.
*/ */
const ejson::Value* get(esize_t _id) const { const ejson::Value* get(size_t _id) const {
return m_value[_id]; return m_value[_id];
}; };
ejson::Value* get(esize_t _id) { ejson::Value* get(size_t _id) {
return m_value[_id]; return m_value[_id];
}; };
/** /**
@ -57,64 +57,64 @@ namespace ejson
* @param[in] _id Id of the element. * @param[in] _id Id of the element.
* @return NULL if the element does not exist. * @return NULL if the element does not exist.
*/ */
ejson::Object* getObject(esize_t _id); ejson::Object* getObject(size_t _id);
/** /**
* @brief get the pointer on an element reference with his ID (casted in String if it is an String). * @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. * @param[in] _id Id of the element.
* @return NULL if the element does not exist. * @return NULL if the element does not exist.
*/ */
ejson::String* getString(esize_t _id); ejson::String* getString(size_t _id);
/** /**
* @brief get the value of the string element (if not a string return "") * @brief get the value of the string element (if not a string return "")
* @param[in] _id Id of the element. * @param[in] _id Id of the element.
* @return value of the element. * @return value of the element.
*/ */
const std::string& getStringValue(esize_t _id); const std::string& getStringValue(size_t _id);
/** /**
* @brief get the value of the string element * @brief get the value of the string element
* @param[in] _id Id of the element. * @param[in] _id Id of the element.
* @param[in] _errorValue The return value if an error occured. * @param[in] _errorValue The return value if an error occured.
* @return value of the element, or the _errorValue. * @return value of the element, or the _errorValue.
*/ */
std::string getStringValue(esize_t _id, const std::string& _errorValue); std::string getStringValue(size_t _id, const std::string& _errorValue);
/** /**
* @brief get the pointer on an element reference with his ID (casted in Array if it is an Array). * @brief get the pointer on an element reference with his ID (casted in Array if it is an Array).
* @param[in] _id Id of the element. * @param[in] _id Id of the element.
* @return NULL if the element does not exist. * @return NULL if the element does not exist.
*/ */
ejson::Array* getArray(esize_t _id); ejson::Array* getArray(size_t _id);
/** /**
* @brief get the pointer on an element reference with his ID (casted in Null if it is an Null). * @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. * @param[in] _id Id of the element.
* @return NULL if the element does not exist. * @return NULL if the element does not exist.
*/ */
ejson::Null* getNull(esize_t _id); ejson::Null* getNull(size_t _id);
/** /**
* @brief get the pointer on an element reference with his ID (casted in Number if it is an Number). * @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. * @param[in] _id Id of the element.
* @return NULL if the element does not exist. * @return NULL if the element does not exist.
*/ */
ejson::Number* getNumber(esize_t _id); ejson::Number* getNumber(size_t _id);
/** /**
* @brief get the value of the Number element * @brief get the value of the Number element
* @param[in] _id Id of the element. * @param[in] _id Id of the element.
* @param[in] _errorValue The return value if an error occured. * @param[in] _errorValue The return value if an error occured.
* @return value of the element, or the _errorValue. * @return value of the element, or the _errorValue.
*/ */
double getNumberValue(esize_t _id, double _errorValue); double getNumberValue(size_t _id, double _errorValue);
/** /**
* @brief get the pointer on an element reference with his ID (casted in Boolean if it is an Boolean). * @brief get the pointer on an element reference with his ID (casted in Boolean if it is an Boolean).
* @param[in] _id Id of the element. * @param[in] _id Id of the element.
* @return NULL if the element does not exist. * @return NULL if the element does not exist.
*/ */
ejson::Boolean* getBoolean(esize_t _id); ejson::Boolean* getBoolean(size_t _id);
/** /**
* @brief get the value of the Boolean element * @brief get the value of the Boolean element
* @param[in] _id Id of the element. * @param[in] _id Id of the element.
* @param[in] _errorValue The return value if an error occured. * @param[in] _errorValue The return value if an error occured.
* @return value of the element, or the _errorValue. * @return value of the element, or the _errorValue.
*/ */
bool getBooleanValue(esize_t _id, bool _errorValue); bool getBooleanValue(size_t _id, bool _errorValue);
/** /**
* @brief add an element on the array. * @brief add an element on the array.
* @param[in] _element element to add. * @param[in] _element element to add.
@ -146,8 +146,8 @@ namespace ejson
bool addNumber(double _value); bool addNumber(double _value);
public: // herited function : public: // herited function :
virtual bool iParse(const std::string& _data, int32_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, int32_t _indent) const; virtual bool iGenerate(std::string& _data, size_t _indent) const;
virtual enum nodeType getType(void) const { virtual enum nodeType getType(void) const {
return typeArray; return typeArray;
}; };

View File

@ -13,7 +13,7 @@
#undef __class__ #undef __class__
#define __class__ "Boolean" #define __class__ "Boolean"
bool ejson::Boolean::iParse(const std::string& _data, int32_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' "); JSON_PARSE_ELEMENT("start parse : 'Boolean' ");
m_value=false; m_value=false;
if( _data[_pos] == 't' if( _data[_pos] == 't'
@ -42,7 +42,7 @@ bool ejson::Boolean::iParse(const std::string& _data, int32_t& _pos, ejson::file
} }
bool ejson::Boolean::iGenerate(std::string& _data, int32_t _indent) const { bool ejson::Boolean::iGenerate(std::string& _data, size_t _indent) const {
if (true == m_value) { if (true == m_value) {
_data += "true"; _data += "true";
} else { } else {

View File

@ -50,8 +50,8 @@ namespace ejson
return m_value; return m_value;
}; };
public: // herited function : public: // herited function :
virtual bool iParse(const std::string& _data, int32_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, int32_t _indent) const; virtual bool iGenerate(std::string& _data, size_t _indent) const;
virtual enum nodeType getType(void) const { virtual enum nodeType getType(void) const {
return typeString; return typeString;
}; };

View File

@ -14,7 +14,7 @@
#undef __class__ #undef __class__
#define __class__ "Null" #define __class__ "Null"
bool ejson::Null::iParse(const std::string& _data, int32_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' "); JSON_PARSE_ELEMENT("start parse : 'Null' ");
if (_pos+3 >= _data.size()){ if (_pos+3 >= _data.size()){
EJSON_CREATE_ERROR(_doc, _data, _pos, _filePos, "can not parse null !!! "); EJSON_CREATE_ERROR(_doc, _data, _pos, _filePos, "can not parse null !!! ");
@ -33,7 +33,7 @@ bool ejson::Null::iParse(const std::string& _data, int32_t& _pos, ejson::filePos
} }
bool ejson::Null::iGenerate(std::string& _data, int32_t _indent) const { bool ejson::Null::iGenerate(std::string& _data, size_t _indent) const {
_data += "null"; _data += "null";
return true; return true;
} }

View File

@ -28,8 +28,8 @@ namespace ejson
*/ */
virtual ~Null(void) { }; virtual ~Null(void) { };
public: // herited function : public: // herited function :
virtual bool iParse(const std::string& _data, int32_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, int32_t _indent) const; virtual bool iGenerate(std::string& _data, size_t _indent) const;
virtual enum nodeType getType(void) const { virtual enum nodeType getType(void) const {
return typeString; return typeString;
}; };

View File

@ -14,10 +14,10 @@
#undef __class__ #undef __class__
#define __class__ "Number" #define __class__ "Number"
bool ejson::Number::iParse(const std::string& _data, int32_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' "); JSON_PARSE_ELEMENT("start parse : 'Number' ");
std::string tmpVal; std::string tmpVal;
for (int32_t iii=_pos; iii<_data.size(); iii++) { for (size_t iii=_pos; iii<_data.size(); iii++) {
_filePos.check(_data[iii]); _filePos.check(_data[iii]);
#ifdef ENABLE_DISPLAY_PARSED_ELEMENT #ifdef ENABLE_DISPLAY_PARSED_ELEMENT
drawElementParsed(_data[iii], _filePos); drawElementParsed(_data[iii], _filePos);
@ -37,7 +37,7 @@ bool ejson::Number::iParse(const std::string& _data, int32_t& _pos, ejson::fileP
} }
bool ejson::Number::iGenerate(std::string& _data, int32_t _indent) const { bool ejson::Number::iGenerate(std::string& _data, size_t _indent) const {
// special thing to remove .000000 at the end of perfect number ... // special thing to remove .000000 at the end of perfect number ...
int64_t tmpVal = m_value; int64_t tmpVal = m_value;
if ((double)tmpVal == m_value) { if ((double)tmpVal == m_value) {

View File

@ -62,8 +62,8 @@ namespace ejson
return (int64_t)m_value; return (int64_t)m_value;
}; };
public: // herited function : public: // herited function :
virtual bool iParse(const std::string& _data, int32_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, int32_t _indent) const; virtual bool iGenerate(std::string& _data, size_t _indent) const;
virtual enum nodeType getType(void) const { virtual enum nodeType getType(void) const {
return typeString; return typeString;
}; };

View File

@ -20,7 +20,7 @@
#define __class__ "Object" #define __class__ "Object"
void ejson::Object::clear(void) { void ejson::Object::clear(void) {
for (esize_t iii=0; iii<m_value.size(); ++iii) { for (int32_t iii=0; iii<m_value.size(); ++iii) {
if (NULL == m_value[iii]) { if (NULL == m_value[iii]) {
continue; continue;
} }
@ -37,17 +37,17 @@ enum statusParsing {
parseValue, parseValue,
}; };
bool ejson::Object::iParse(const std::string& _data, int32_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; enum statusParsing mode = parseName;
std::string currentName; std::string currentName;
JSON_PARSE_ELEMENT("start parse : 'Object' "); JSON_PARSE_ELEMENT("start parse : 'Object' ");
bool standalone = true; bool standalone = true;
int32_t startPos = _pos+1; size_t startPos = _pos+1;
if (_data[_pos] != '{' ) { // when the main node call it, it can be start with != '{' if (_data[_pos] != '{' ) { // when the main node call it, it can be start with != '{'
standalone = false; standalone = false;
startPos = _pos; startPos = _pos;
} }
for (int32_t iii=startPos; iii<_data.size(); iii++) { for (size_t iii=startPos; iii<_data.size(); iii++) {
_filePos.check(_data[iii]); _filePos.check(_data[iii]);
#ifdef ENABLE_DISPLAY_PARSED_ELEMENT #ifdef ENABLE_DISPLAY_PARSED_ELEMENT
drawElementParsed(_data[iii], _filePos); drawElementParsed(_data[iii], _filePos);
@ -202,14 +202,14 @@ bool ejson::Object::iParse(const std::string& _data, int32_t& _pos, ejson::fileP
} }
return false; return false;
} }
bool ejson::Object::iGenerate(std::string& _data, int32_t _indent) const { bool ejson::Object::iGenerate(std::string& _data, size_t _indent) const {
bool oneLine=true; bool oneLine=true;
if (m_value.size()>3) { if (m_value.size()>3) {
oneLine=false; oneLine=false;
} else if (_indent<=1) { } else if (_indent<=1) {
oneLine=false; oneLine=false;
} else { } else {
for (esize_t iii=0; iii<m_value.size() ; iii++) { for (int32_t iii=0; iii<m_value.size() ; iii++) {
ejson::Value* tmp = m_value[iii]; ejson::Value* tmp = m_value[iii];
if (tmp == NULL) { if (tmp == NULL) {
continue; continue;
@ -239,7 +239,7 @@ bool ejson::Object::iGenerate(std::string& _data, int32_t _indent) const {
} else { } else {
_data += "{\n"; _data += "{\n";
} }
for (esize_t iii=0; iii<m_value.size() ; iii++) { for (int32_t iii=0; iii<m_value.size() ; iii++) {
if (false == oneLine) { if (false == oneLine) {
addIndent(_data, _indent); addIndent(_data, _indent);
} }
@ -415,7 +415,7 @@ ejson::Value* ejson::Object::duplicate(void) const {
JSON_ERROR("Allocation error ..."); JSON_ERROR("Allocation error ...");
return NULL; return NULL;
} }
for (esize_t iii=0; iii<m_value.size(); ++iii) { for (int32_t iii=0; iii<m_value.size(); ++iii) {
ejson::Value* val = m_value.getValue(iii); ejson::Value* val = m_value.getValue(iii);
std::string key = m_value.getKey(iii); std::string key = m_value.getKey(iii);
if (NULL == val) { if (NULL == val) {

View File

@ -15,10 +15,8 @@
#include <etk/math/Vector2D.h> #include <etk/math/Vector2D.h>
#include <ejson/Value.h> #include <ejson/Value.h>
namespace ejson namespace ejson {
{ class Object : public ejson::Value {
class Object : public ejson::Value
{
public: public:
/** /**
* @brief basic element of a xml structure * @brief basic element of a xml structure
@ -142,8 +140,8 @@ namespace ejson
*/ */
bool addNumber(const std::string& _name, double _value); bool addNumber(const std::string& _name, double _value);
public: // herited function : public: // herited function :
virtual bool iParse(const std::string& _data, int32_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, int32_t _indent) const; virtual bool iGenerate(std::string& _data, size_t _indent) const;
virtual enum nodeType getType(void) const { virtual enum nodeType getType(void) const {
return typeObject; return typeObject;
}; };

View File

@ -18,9 +18,9 @@
bool ejson::String::iParse(const std::string& _data, int32_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' "); JSON_PARSE_ELEMENT("start parse : 'String' ");
for (int32_t iii=_pos+1; iii<_data.size(); iii++) { for (size_t iii=_pos+1; iii<_data.size(); iii++) {
_filePos.check(_data[iii]); _filePos.check(_data[iii]);
#ifdef ENABLE_DISPLAY_PARSED_ELEMENT #ifdef ENABLE_DISPLAY_PARSED_ELEMENT
drawElementParsed(_data[iii], _filePos); drawElementParsed(_data[iii], _filePos);
@ -40,7 +40,7 @@ bool ejson::String::iParse(const std::string& _data, int32_t& _pos, ejson::fileP
} }
bool ejson::String::iGenerate(std::string& _data, int32_t _indent) const { bool ejson::String::iGenerate(std::string& _data, size_t _indent) const {
_data += "\"";; _data += "\"";;
_data += m_value; _data += m_value;
_data += "\"";; _data += "\"";;

View File

@ -22,7 +22,10 @@ namespace ejson
/** /**
* @brief basic element of a xml structure * @brief basic element of a xml structure
*/ */
String(const std::string& _value="") : m_value(_value) { }; String(const std::string& _value="") :
m_value(_value) {
};
/** /**
* @brief destructor * @brief destructor
*/ */
@ -34,15 +37,19 @@ namespace ejson
* @brief set the value of the node. * @brief set the value of the node.
* @param[in] _value New value of the node. * @param[in] _value New value of the node.
*/ */
void set(const std::string& _value) { m_value = _value; }; void set(const std::string& _value) {
m_value = _value;
};
/** /**
* @brief get the current element Value. * @brief get the current element Value.
* @return the reference of the string value. * @return the reference of the string value.
*/ */
const std::string& get(void) const { return m_value; }; const std::string& get(void) const {
return m_value;
};
public: // herited function : public: // herited function :
virtual bool iParse(const std::string& _data, int32_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, int32_t _indent) const; virtual bool iGenerate(std::string& _data, size_t _indent) const;
virtual enum nodeType getType(void) const { virtual enum nodeType getType(void) const {
return typeString; return typeString;
}; };

View File

@ -28,8 +28,8 @@ etk::CCout& ejson::operator <<(etk::CCout& _os, const ejson::filePos& _obj) {
} }
void ejson::Value::addIndent(std::string& _data, int32_t _indent) const { void ejson::Value::addIndent(std::string& _data, size_t _indent) const {
for (int32_t iii=0; iii<_indent; iii++) { for (size_t iii=0; iii<_indent; iii++) {
_data+="\t"; _data+="\t";
} }
} }
@ -44,10 +44,10 @@ void ejson::Value::drawElementParsed(char32_t _val, const ejson::filePos& _fileP
} }
} }
int32_t ejson::Value::countWhiteChar(const std::string& _data, int32_t _pos, ejson::filePos& _filePos) const { int32_t ejson::Value::countWhiteChar(const std::string& _data, size_t _pos, ejson::filePos& _filePos) const {
_filePos.clear(); _filePos.clear();
int32_t white=0; size_t white=0;
for (int32_t iii=_pos; iii<_data.size(); iii++) { for (size_t iii=_pos; iii<_data.size(); iii++) {
_filePos.check(_data[iii]); _filePos.check(_data[iii]);
if(true == etk::isWhiteChar(_data[iii])) { if(true == etk::isWhiteChar(_data[iii])) {
white++; white++;

View File

@ -47,15 +47,15 @@ namespace ejson {
class filePos { class filePos {
private: private:
int32_t m_col; size_t m_col;
int32_t m_line; size_t m_line;
public: public:
filePos(void) : filePos(void) :
m_col(0), m_col(0),
m_line(0) { m_line(0) {
}; };
filePos(int32_t _line, int32_t _col) : filePos(size_t _line, size_t _col) :
m_col(_col), m_col(_col),
m_line(_line) { m_line(_line) {
@ -66,9 +66,8 @@ namespace ejson {
return *this; return *this;
}; };
filePos& operator --(void) { filePos& operator --(void) {
if(m_col>0) {
m_col--; m_col--;
if(m_col<0) {
m_col=0;
} }
return *this; return *this;
}; };
@ -81,7 +80,7 @@ namespace ejson {
} }
return *this; return *this;
}; };
const filePos& operator +=(int32_t _col) { const filePos& operator +=(size_t _col) {
m_col += _col; m_col += _col;
return *this; return *this;
}; };
@ -102,7 +101,7 @@ namespace ejson {
} }
return false; return false;
} }
void set(int32_t _line, int32_t _col) { void set(size_t _line, size_t _col) {
m_col = _col; m_col = _col;
m_line = _line; m_line = _line;
} }
@ -138,14 +137,14 @@ namespace ejson {
* @param[in,out] file parsing position (line x col x) * @param[in,out] file parsing position (line x col x)
* @return false if an error occured. * @return false if an error occured.
*/ */
virtual bool iParse(const std::string& _data, int32_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 * @brief generate a string with the tree of the xml
* @param[in,out] _data string where to add the elements * @param[in,out] _data string where to add the elements
* @param[in] current indentation of the file * @param[in] current indentation of the file
* @return false if an error occured. * @return false if an error occured.
*/ */
virtual bool iGenerate(std::string& _data, int32_t _indent) const = 0; virtual bool iGenerate(std::string& _data, size_t _indent) const = 0;
public: public:
/** /**
* @brief get the node type. * @brief get the node type.
@ -160,7 +159,7 @@ namespace ejson {
* @param[in,out] _data String where the indentation is done. * @param[in,out] _data String where the indentation is done.
* @param[in] _indent Number of tab to add at the string. * @param[in] _indent Number of tab to add at the string.
*/ */
void addIndent(std::string& _data, int32_t _indent) const; void addIndent(std::string& _data, size_t _indent) const;
/** /**
* @brief Display the cuurent element that is curently parse. * @brief Display the cuurent element that is curently parse.
* @param[in] _val Char that is parsed. * @param[in] _val Char that is parsed.
@ -184,7 +183,7 @@ namespace ejson {
* @param[out] _filePos new poistion of te file to add. * @param[out] _filePos new poistion of te file to add.
* @return number of white element. * @return number of white element.
*/ */
int32_t countWhiteChar(const std::string& _data, int32_t _pos, ejson::filePos& _filePos) const; int32_t countWhiteChar(const std::string& _data, size_t _pos, ejson::filePos& _filePos) const;
public: public:
/** /**
* @brief Cast the element in a Value if it is possible. * @brief Cast the element in a Value if it is possible.

View File

@ -32,7 +32,7 @@ ejson::Document::~Document(void) {
} }
bool ejson::Document::iGenerate(std::string& _data, int32_t _indent) const { bool ejson::Document::iGenerate(std::string& _data, size_t _indent) const {
ejson::Object::iGenerate(_data, _indent+1); ejson::Object::iGenerate(_data, _indent+1);
_data += "\n"; _data += "\n";
return true; return true;
@ -42,7 +42,7 @@ bool ejson::Document::parse(const std::string& _data) {
JSON_VERBOSE("Start parsing document (type: string) size=" << _data.size()); JSON_VERBOSE("Start parsing document (type: string) size=" << _data.size());
clear(); clear();
ejson::filePos filePos(1,0); ejson::filePos filePos(1,0);
int32_t parsePos = 0; size_t parsePos = 0;
return iParse(_data, parsePos, filePos, *this); return iParse(_data, parsePos, filePos, *this);
} }
@ -102,7 +102,7 @@ bool ejson::Document::store(const std::string& _file) {
JSON_ERROR("Can not open (w) the file : " << _file); JSON_ERROR("Can not open (w) the file : " << _file);
return false; return false;
} }
if (tmpFile.fileWrite((char*)createData.c_str(), sizeof(char), createData.size()) != createData.size()) { if (tmpFile.fileWrite((char*)createData.c_str(), sizeof(char), createData.size()) != (int32_t)createData.size()) {
JSON_ERROR("Error while writing output XML file : " << _file); JSON_ERROR("Error while writing output XML file : " << _file);
tmpFile.fileClose(); tmpFile.fileClose();
return false; return false;
@ -117,9 +117,9 @@ void ejson::Document::display(void) {
JSON_INFO("Generated JSON : \n" << tmpp); JSON_INFO("Generated JSON : \n" << tmpp);
} }
static std::string createPosPointer(const std::string& _line, int32_t _pos) { static std::string createPosPointer(const std::string& _line, size_t _pos) {
std::string out; std::string out;
int32_t iii; size_t iii;
for (iii=0; iii<_pos && iii<_line.size(); iii++) { for (iii=0; iii<_pos && iii<_line.size(); iii++) {
if (_line[iii] == '\t') { if (_line[iii] == '\t') {
out += "\t"; out += "\t";
@ -147,7 +147,7 @@ void ejson::Document::displayError(void) {
#endif #endif
} }
void ejson::Document::createError(const std::string& _data, int32_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_comment = _comment;
m_Line = extract_line(_data, _pos); m_Line = extract_line(_data, _pos);
m_filePos = _filePos; m_filePos = _filePos;
@ -156,11 +156,11 @@ void ejson::Document::createError(const std::string& _data, int32_t _pos, const
} }
} }
bool ejson::Document::iParse(const std::string& _data, int32_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' "); JSON_PARSE_ELEMENT("start parse : 'Document' ");
bool haveMainNode=false; bool haveMainNode=false;
bool nodeParsed=false; bool nodeParsed=false;
for (int32_t iii=_pos; iii<_data.size(); iii++) { for (size_t iii=_pos; iii<_data.size(); iii++) {
_filePos.check(_data[iii]); _filePos.check(_data[iii]);
#ifdef ENABLE_DISPLAY_PARSED_ELEMENT #ifdef ENABLE_DISPLAY_PARSED_ELEMENT
drawElementParsed(_data[iii], _filePos); drawElementParsed(_data[iii], _filePos);

View File

@ -17,10 +17,8 @@
#include <ejson/Array.h> #include <ejson/Array.h>
#include <ejson/Object.h> #include <ejson/Object.h>
namespace ejson namespace ejson {
{ class Document : public ejson::Object {
class Document : public ejson::Object
{
public: public:
/** /**
* @brief Constructor * @brief Constructor
@ -76,14 +74,14 @@ namespace ejson
m_writeErrorWhenDetexted=false; m_writeErrorWhenDetexted=false;
}; };
void createError(const std::string& _data, int32_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(void); void displayError(void);
public: // herited function: public: // herited function:
virtual enum nodeType getType(void) const { virtual enum nodeType getType(void) const {
return typeDocument; return typeDocument;
}; };
virtual bool iParse(const std::string& _data, int32_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, int32_t _indent) const; virtual bool iGenerate(std::string& _data, size_t _indent) const;
virtual ejson::Document* toDocument(void) { virtual ejson::Document* toDocument(void) {
return this; return this;
}; };

View File

@ -7,6 +7,8 @@ def Create(target):
myModule.AddModuleDepend(['etk']) myModule.AddModuleDepend(['etk'])
# add extra compilation flags :
myModule.add_extra_compile_flags()
myModule.AddSrcFile([ myModule.AddSrcFile([
'ejson/debug.cpp', 'ejson/debug.cpp',
'ejson/ejson.cpp', 'ejson/ejson.cpp',