[DEV] clean API and ionterface (add documentation adn add remove elements
This commit is contained in:
parent
f756cfd131
commit
2ece8a2477
37
doc/write.md
37
doc/write.md
@ -28,31 +28,42 @@ Writing a stream is done like this:
|
||||
Operation on Tree {#ejson_tutorial_write_operation}
|
||||
=================
|
||||
|
||||
Add Node/Declaration:
|
||||
@snippet write.cpp ejson_sample_write_add_declaration
|
||||
Add String:
|
||||
@snippet write.cpp ejson_sample_write_add_string_1
|
||||
@snippet write.cpp ejson_sample_write_add_string_2
|
||||
|
||||
Add an Node/Element:
|
||||
@snippet write.cpp ejson_sample_write_add_element
|
||||
Add Null:
|
||||
@snippet write.cpp ejson_sample_write_add_null_1
|
||||
@snippet write.cpp ejson_sample_write_add_null_2
|
||||
|
||||
Remove a Node/Element:
|
||||
@snippet write.cpp ejson_sample_write_rm_node
|
||||
Add Number:
|
||||
@snippet write.cpp ejson_sample_write_add_number_1
|
||||
@snippet write.cpp ejson_sample_write_add_number_2
|
||||
|
||||
Add Boolean:
|
||||
@snippet write.cpp ejson_sample_write_add_boolean_1
|
||||
@snippet write.cpp ejson_sample_write_add_boolean_1
|
||||
|
||||
Add an attribute (simple version):
|
||||
@snippet write.cpp ejson_sample_write_add_attribute_simple
|
||||
Add Array with values:
|
||||
@snippet write.cpp ejson_sample_write_add_array
|
||||
|
||||
Add an attribute (complex version):
|
||||
@snippet write.cpp ejson_sample_write_add_attribute_complex
|
||||
Add Object with values:
|
||||
@snippet write.cpp ejson_sample_write_add_object
|
||||
|
||||
Remove a Value in an Object:
|
||||
@snippet write.cpp ejson_sample_write_rm_object
|
||||
|
||||
Remove a Value in an Object:
|
||||
@snippet write.cpp ejson_sample_write_rm_array
|
||||
|
||||
Remove an attribute:
|
||||
@snippet write.cpp ejson_sample_write_rm_attribute
|
||||
|
||||
Object concept {#ejson_tutorial_concept}
|
||||
==============
|
||||
|
||||
the ejson concept is to abstract the implementation of the internal system. All the element are maped on shared memory.
|
||||
The ejson concept is to abstract the implementation of the internal system. All the element are mapped on shared memory.
|
||||
Then if you asign an element to an other, it is the same. You need to clone it if you want to have new standalone element.
|
||||
|
||||
@snippet write.cpp ejson_sample_read_clone
|
||||
|
||||
All example file {#ejson_tutorial_write_all}
|
||||
================
|
||||
|
@ -8,13 +8,17 @@
|
||||
#include <ejson/Array.h>
|
||||
#include <ejson/debug.h>
|
||||
#include <ejson/internal/Array.h>
|
||||
#include <ejson/Boolean.h>
|
||||
#include <ejson/String.h>
|
||||
#include <ejson/Null.h>
|
||||
#include <ejson/Number.h>
|
||||
|
||||
ejson::Array::Array(ememory::SharedPtr<ejson::internal::Value> _internalValue) :
|
||||
ejson::Value(_internalValue) {
|
||||
if (m_data == nullptr) {
|
||||
return;
|
||||
}
|
||||
if (m_data->isArray() == false) {
|
||||
if (m_data->getType() != ejson::valueType::array) {
|
||||
// try to set wrong type inside ... ==> remove it ...
|
||||
m_data = nullptr;
|
||||
}
|
||||
@ -59,45 +63,16 @@ const ejson::Value ejson::Array::operator[] (size_t _id) const {
|
||||
return ejson::Value(static_cast<ejson::internal::Array*>(m_data.get())->get(_id));
|
||||
}
|
||||
|
||||
std::string ejson::Array::getStringValue(size_t _id) {
|
||||
if (m_data == nullptr) {
|
||||
EJSON_ERROR("Can not parse (nullptr) ...");
|
||||
return "";
|
||||
}
|
||||
return static_cast<ejson::internal::Array*>(m_data.get())->getStringValue(_id);
|
||||
}
|
||||
|
||||
const std::string& ejson::Array::getStringValue(size_t _id) const {
|
||||
if (m_data == nullptr) {
|
||||
static const std::string errorValue = "";
|
||||
EJSON_ERROR("Can not getStringValue (nullptr) ...");
|
||||
return errorValue;
|
||||
}
|
||||
return static_cast<const ejson::internal::Array*>(m_data.get())->getStringValue(_id);
|
||||
}
|
||||
|
||||
std::string ejson::Array::getStringValue(size_t _id, const std::string& _errorValue) const {
|
||||
if (m_data == nullptr) {
|
||||
EJSON_ERROR("Can not getStringValue (nullptr) ...");
|
||||
return _errorValue;
|
||||
}
|
||||
return static_cast<const ejson::internal::Array*>(m_data.get())->getStringValue(_id, _errorValue);
|
||||
return (*this)[_id].toString().get(_errorValue);
|
||||
}
|
||||
|
||||
double ejson::Array::getNumberValue(size_t _id, double _errorValue) const {
|
||||
if (m_data == nullptr) {
|
||||
EJSON_ERROR("Can not getNumberValue (nullptr) ...");
|
||||
return _errorValue;
|
||||
}
|
||||
return static_cast<const ejson::internal::Array*>(m_data.get())->getNumberValue(_id, _errorValue);
|
||||
return (*this)[_id].toNumber().get(_errorValue);
|
||||
}
|
||||
|
||||
bool ejson::Array::getBooleanValue(size_t _id, bool _errorValue) const {
|
||||
if (m_data == nullptr) {
|
||||
EJSON_ERROR("Can not getBooleanValue (nullptr) ...");
|
||||
return _errorValue;
|
||||
}
|
||||
return static_cast<const ejson::internal::Array*>(m_data.get())->getBooleanValue(_id, _errorValue);
|
||||
return (*this)[_id].toBoolean().get(_errorValue);
|
||||
}
|
||||
|
||||
bool ejson::Array::add(const ejson::Value& _element) {
|
||||
@ -108,36 +83,39 @@ bool ejson::Array::add(const ejson::Value& _element) {
|
||||
return static_cast<ejson::internal::Array*>(m_data.get())->add(_element.m_data);
|
||||
}
|
||||
|
||||
bool ejson::Array::addString(const std::string& _value) {
|
||||
void ejson::Array::remove(size_t _id) {
|
||||
if (m_data == nullptr) {
|
||||
EJSON_ERROR("Can not addString (nullptr) ...");
|
||||
return false;
|
||||
EJSON_ERROR("Can not remove (nullptr) ...");
|
||||
return;
|
||||
}
|
||||
return static_cast<ejson::internal::Array*>(m_data.get())->addString(_value);
|
||||
static_cast<ejson::internal::Array*>(m_data.get())->remove(_id);
|
||||
}
|
||||
|
||||
ejson::Array::iterator ejson::Array::remove(const ejson::Array::iterator& _it) {
|
||||
if (m_data == nullptr) {
|
||||
EJSON_ERROR("Can not remove (nullptr) ...");
|
||||
return _it;
|
||||
}
|
||||
static_cast<ejson::internal::Array*>(m_data.get())->remove(_it.getId());
|
||||
return ejson::Array::iterator(*this, _it.getId());
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool ejson::Array::addString(const std::string& _value) {
|
||||
return add(ejson::String(_value));
|
||||
}
|
||||
|
||||
bool ejson::Array::addNull() {
|
||||
if (m_data == nullptr) {
|
||||
EJSON_ERROR("Can not addNull (nullptr) ...");
|
||||
return false;
|
||||
}
|
||||
return static_cast<ejson::internal::Array*>(m_data.get())->addNull();
|
||||
return add(ejson::Null());
|
||||
}
|
||||
|
||||
bool ejson::Array::addBoolean(bool _value) {
|
||||
if (m_data == nullptr) {
|
||||
EJSON_ERROR("Can not addBoolean (nullptr) ...");
|
||||
return false;
|
||||
}
|
||||
return static_cast<ejson::internal::Array*>(m_data.get())->addBoolean(_value);
|
||||
return add(ejson::Boolean(_value));
|
||||
}
|
||||
|
||||
bool ejson::Array::addNumber(double _value) {
|
||||
if (m_data == nullptr) {
|
||||
EJSON_ERROR("Can not addNumber (nullptr) ...");
|
||||
return false;
|
||||
}
|
||||
return static_cast<ejson::internal::Array*>(m_data.get())->addNumber(_value);
|
||||
return add(ejson::Number(_value));
|
||||
}
|
||||
|
||||
ejson::Array::iterator ejson::Array::begin() {
|
||||
|
@ -45,36 +45,33 @@ namespace ejson {
|
||||
* @return nullptr if the element does not exist.
|
||||
*/
|
||||
ejson::Value operator[] (size_t _id);
|
||||
const ejson::Value operator[] (size_t _id) const;
|
||||
/**
|
||||
* @brief get the value of the string element (if not a string return "")
|
||||
* @brief get the pointer on an element reference with his ID.
|
||||
* @param[in] _id Id of the element.
|
||||
* @return value of the element.
|
||||
* @return nullptr if the element does not exist.
|
||||
*/
|
||||
std::string getStringValue(size_t _id);
|
||||
//! @previous
|
||||
const std::string& getStringValue(size_t _id) const;
|
||||
const ejson::Value operator[] (size_t _id) const;
|
||||
/**
|
||||
* @brief get the value of the string element
|
||||
* @param[in] _id Id of the element.
|
||||
* @param[in] _errorValue The return value if an error occured.
|
||||
* @return value of the element, or the _errorValue.
|
||||
*/
|
||||
std::string getStringValue(size_t _id, const std::string& _errorValue) const;
|
||||
std::string getStringValue(size_t _id, const std::string& _errorValue="") const;
|
||||
/**
|
||||
* @brief get the value of the Number element
|
||||
* @param[in] _id Id of the element.
|
||||
* @param[in] _errorValue The return value if an error occured.
|
||||
* @return value of the element, or the _errorValue.
|
||||
*/
|
||||
double getNumberValue(size_t _id, double _errorValue) const;
|
||||
double getNumberValue(size_t _id, double _errorValue=0.0) const;
|
||||
/**
|
||||
* @brief get the value of the Boolean element
|
||||
* @param[in] _id Id of the element.
|
||||
* @param[in] _errorValue The return value if an error occured.
|
||||
* @return value of the element, or the _errorValue.
|
||||
*/
|
||||
bool getBooleanValue(size_t _id, bool _errorValue) const;
|
||||
bool getBooleanValue(size_t _id, bool _errorValue=false) const;
|
||||
/**
|
||||
* @brief add an element on the array.
|
||||
* @param[in] _element element to add.
|
||||
@ -104,6 +101,11 @@ namespace ejson {
|
||||
* @return false if an error occured
|
||||
*/
|
||||
bool addNumber(double _value);
|
||||
/**
|
||||
* @brief Remove Value with his Id
|
||||
* @param[in] _id Id of the element.
|
||||
*/
|
||||
void remove(size_t _id);
|
||||
public:
|
||||
using iterator = ejson::iterator<ejson::Array>; //!< Specify iterator of the Array methode
|
||||
/**
|
||||
@ -126,6 +128,11 @@ namespace ejson {
|
||||
* @return const iterator on the next of the last position of the Value
|
||||
*/
|
||||
const iterator end() const;
|
||||
/**
|
||||
* @brief Remove Value with his iterator
|
||||
* @param[in] _it Iterator on the Value.
|
||||
*/
|
||||
iterator remove(const iterator& _it);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ ejson::Boolean::Boolean(ememory::SharedPtr<ejson::internal::Value> _internalValu
|
||||
if (m_data == nullptr) {
|
||||
return;
|
||||
}
|
||||
if (m_data->isBoolean() == false) {
|
||||
if (m_data->getType() != ejson::valueType::boolean) {
|
||||
// try to set wrong type inside ... ==> remove it ...
|
||||
m_data = nullptr;
|
||||
}
|
||||
@ -45,10 +45,10 @@ void ejson::Boolean::set(bool _value) {
|
||||
static_cast<ejson::internal::Boolean*>(m_data.get())->set(_value);
|
||||
}
|
||||
|
||||
bool ejson::Boolean::get() const {
|
||||
bool ejson::Boolean::get(bool _errorValue) const {
|
||||
if (m_data == nullptr) {
|
||||
EJSON_ERROR("Can not get (nullptr) ...");
|
||||
return false;
|
||||
return _errorValue;
|
||||
}
|
||||
return static_cast<ejson::internal::Boolean*>(m_data.get())->get();
|
||||
}
|
||||
|
@ -41,9 +41,10 @@ namespace ejson {
|
||||
void set(bool _value);
|
||||
/**
|
||||
* @brief get the current element Value.
|
||||
* @param[in] _errorValue Value return if no value Exist
|
||||
* @return the reference of the string value.
|
||||
*/
|
||||
bool get() const;
|
||||
bool get(bool _errorValue=false) const;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ ejson::Document::Document(ememory::SharedPtr<ejson::internal::Value> _internalVa
|
||||
if (m_data == nullptr) {
|
||||
return;
|
||||
}
|
||||
if (m_data->isDocument() == false) {
|
||||
if (m_data->getType() != ejson::valueType::document) {
|
||||
// try to set wrong type inside ... ==> remove it ...
|
||||
m_data = nullptr;
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ ejson::Null::Null(ememory::SharedPtr<ejson::internal::Value> _internalValue) :
|
||||
if (m_data == nullptr) {
|
||||
return;
|
||||
}
|
||||
if (m_data->isNull() == false) {
|
||||
if (m_data->getType() != ejson::valueType::null) {
|
||||
// try to set wrong type inside ... ==> remove it ...
|
||||
m_data = nullptr;
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ ejson::Number::Number(ememory::SharedPtr<ejson::internal::Value> _internalValue)
|
||||
if (m_data == nullptr) {
|
||||
return;
|
||||
}
|
||||
if (m_data->isNumber() == false) {
|
||||
if (m_data->getType() != ejson::valueType::number) {
|
||||
// try to set wrong type inside ... ==> remove it ...
|
||||
m_data = nullptr;
|
||||
}
|
||||
@ -44,35 +44,10 @@ void ejson::Number::set(double _value) {
|
||||
static_cast<ejson::internal::Number*>(m_data.get())->set(_value);
|
||||
}
|
||||
|
||||
double ejson::Number::get() const {
|
||||
if (m_data == nullptr) {
|
||||
EJSON_ERROR("Can not parse (nullptr) ...");
|
||||
return 0.0;
|
||||
}
|
||||
return static_cast<ejson::internal::Number*>(m_data.get())->get();
|
||||
}
|
||||
|
||||
double ejson::Number::get(double _errorValue) const {
|
||||
if (m_data == nullptr) {
|
||||
EJSON_ERROR("Can not parse (nullptr) ...");
|
||||
EJSON_ERROR("Can not get (nullptr) ...");
|
||||
return _errorValue;
|
||||
}
|
||||
return static_cast<ejson::internal::Number*>(m_data.get())->get();
|
||||
}
|
||||
|
||||
int32_t ejson::Number::getInt32() const {
|
||||
if (m_data == nullptr) {
|
||||
EJSON_ERROR("Can not getInt32 (nullptr) ...");
|
||||
return 0;
|
||||
}
|
||||
return static_cast<ejson::internal::Number*>(m_data.get())->getInt32();
|
||||
}
|
||||
|
||||
int64_t ejson::Number::getInt64() const {
|
||||
if (m_data == nullptr) {
|
||||
EJSON_ERROR("Can not getInt64 (nullptr) ...");
|
||||
return 0;
|
||||
}
|
||||
return static_cast<ejson::internal::Number*>(m_data.get())->getInt64();
|
||||
}
|
||||
|
||||
|
@ -40,27 +40,12 @@ namespace ejson {
|
||||
* @param[in] _value New value of the node.
|
||||
*/
|
||||
void set(double _value);
|
||||
/**
|
||||
* @brief Get the current element Value.
|
||||
* @return The double number registered
|
||||
*/
|
||||
double get() const;
|
||||
/**
|
||||
* @brief Get the current element Value.
|
||||
* @param[in] _errorValue Value return if no value Exist
|
||||
* @return The double number registered
|
||||
*/
|
||||
double get(double _errorValue) const;
|
||||
/**
|
||||
* @brief Get the current element Value.
|
||||
* @return The 32 bit integer number registered
|
||||
*/
|
||||
int32_t getInt32() const;
|
||||
/**
|
||||
* @brief Get the current element Value.
|
||||
* @return The 64 bit integer number registered
|
||||
*/
|
||||
int64_t getInt64() const;
|
||||
double get(double _errorValue=0.0) const;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ ejson::Object::Object(ememory::SharedPtr<ejson::internal::Value> _internalValue)
|
||||
if (m_data == nullptr) {
|
||||
return;
|
||||
}
|
||||
if (m_data->isObject() == false) {
|
||||
if (m_data->getType() != ejson::valueType::null) {
|
||||
// try to set wrong type inside ... ==> remove it ...
|
||||
m_data = nullptr;
|
||||
}
|
||||
@ -106,37 +106,16 @@ std::string ejson::Object::getKey(size_t _id) const {
|
||||
return static_cast<ejson::internal::Object*>(m_data.get())->getKey(_id);
|
||||
}
|
||||
|
||||
const std::string& ejson::Object::getStringValue(const std::string& _name) const {
|
||||
if (m_data == nullptr) {
|
||||
static const std::string errorString = "";
|
||||
EJSON_ERROR("Can not getStringValue (nullptr) ...");
|
||||
return errorString;
|
||||
}
|
||||
return static_cast<const ejson::internal::Object*>(m_data.get())->getStringValue(_name);
|
||||
}
|
||||
|
||||
std::string ejson::Object::getStringValue(const std::string& _name, const std::string& _errorValue) const {
|
||||
if (m_data == nullptr) {
|
||||
EJSON_ERROR("Can not getStringValue (nullptr) ...");
|
||||
return "";
|
||||
}
|
||||
return static_cast<const ejson::internal::Object*>(m_data.get())->getStringValue(_name, _errorValue);
|
||||
return (*this)[_name].toString().get(_errorValue);
|
||||
}
|
||||
|
||||
bool ejson::Object::getBooleanValue(const std::string& _name, bool _errorValue) const {
|
||||
if (m_data == nullptr) {
|
||||
EJSON_ERROR("Can not getBooleanValue (nullptr) ...");
|
||||
return false;
|
||||
}
|
||||
return static_cast<const ejson::internal::Object*>(m_data.get())->getBooleanValue(_name, _errorValue);
|
||||
return (*this)[_name].toBoolean().get(_errorValue);
|
||||
}
|
||||
|
||||
double ejson::Object::getNumberValue(const std::string& _name, double _errorValue) const {
|
||||
if (m_data == nullptr) {
|
||||
EJSON_ERROR("Can not getNumberValue (nullptr) ...");
|
||||
return 0.0;
|
||||
}
|
||||
return static_cast<const ejson::internal::Object*>(m_data.get())->getNumberValue(_name, _errorValue);
|
||||
return (*this)[_name].toNumber().get(_errorValue);
|
||||
}
|
||||
|
||||
bool ejson::Object::add(const std::string& _name, const ejson::Value& _value) {
|
||||
@ -148,35 +127,44 @@ bool ejson::Object::add(const std::string& _name, const ejson::Value& _value) {
|
||||
}
|
||||
|
||||
bool ejson::Object::addString(const std::string& _name, const std::string& _value) {
|
||||
if (m_data == nullptr) {
|
||||
EJSON_ERROR("Can not addString (nullptr) ...");
|
||||
return false;
|
||||
}
|
||||
return static_cast<ejson::internal::Object*>(m_data.get())->addString(_name, _value);
|
||||
return add(_name, ejson::String(_value));
|
||||
}
|
||||
|
||||
bool ejson::Object::addNull(const std::string& _name) {
|
||||
if (m_data == nullptr) {
|
||||
EJSON_ERROR("Can not addNull (nullptr) ...");
|
||||
return false;
|
||||
}
|
||||
return static_cast<ejson::internal::Object*>(m_data.get())->addNull(_name);
|
||||
return add(_name, ejson::Null());
|
||||
}
|
||||
|
||||
bool ejson::Object::addBoolean(const std::string& _name, bool _value) {
|
||||
if (m_data == nullptr) {
|
||||
EJSON_ERROR("Can not addBoolean (nullptr) ...");
|
||||
return false;
|
||||
}
|
||||
return static_cast<ejson::internal::Object*>(m_data.get())->addBoolean(_name, _value);
|
||||
return add(_name, ejson::Boolean(_value));
|
||||
}
|
||||
|
||||
bool ejson::Object::addNumber(const std::string& _name, double _value) {
|
||||
return add(_name, ejson::Number(_value));
|
||||
}
|
||||
|
||||
void ejson::Object::remove(const std::string& _name) {
|
||||
if (m_data == nullptr) {
|
||||
EJSON_ERROR("Can not addNumber (nullptr) ...");
|
||||
return false;
|
||||
EJSON_ERROR("Can not remove (nullptr) ...");
|
||||
return;
|
||||
}
|
||||
return static_cast<ejson::internal::Object*>(m_data.get())->addNumber(_name, _value);
|
||||
static_cast<ejson::internal::Object*>(m_data.get())->remove(_name);
|
||||
}
|
||||
|
||||
void ejson::Object::remove(size_t _id) {
|
||||
if (m_data == nullptr) {
|
||||
EJSON_ERROR("Can not remove (nullptr) ...");
|
||||
return;
|
||||
}
|
||||
static_cast<ejson::internal::Object*>(m_data.get())->remove(_id);
|
||||
}
|
||||
|
||||
ejson::Object::iterator ejson::Object::remove(const ejson::Object::iterator& _it) {
|
||||
if (m_data == nullptr) {
|
||||
EJSON_ERROR("Can not remove (nullptr) ...");
|
||||
return _it;
|
||||
}
|
||||
static_cast<ejson::internal::Object*>(m_data.get())->remove(_it.getId());
|
||||
return ejson::Object::iterator(*this, _it.getId());
|
||||
}
|
||||
|
||||
|
||||
|
@ -44,13 +44,13 @@ namespace ejson {
|
||||
public:
|
||||
/**
|
||||
* @brief check if an element exist.
|
||||
* @param[in] _name name of the object.
|
||||
* @param[in] _name Name of the object.
|
||||
* @return The existance of the element.
|
||||
*/
|
||||
bool valueExist(const std::string& _name) const;
|
||||
/**
|
||||
* @brief get the sub element with his name (no cast check)
|
||||
* @param[in] _name name of the object
|
||||
* @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
|
||||
*/
|
||||
ejson::Value operator[] (const std::string& _name);
|
||||
@ -79,19 +79,13 @@ namespace ejson {
|
||||
* @return The name (key).
|
||||
*/
|
||||
std::string getKey(size_t _id) const;
|
||||
/**
|
||||
* @brief get the sub string value of the requested element
|
||||
* @param[in] _name name of the object
|
||||
* @return Value of the string or an error string (empty)
|
||||
*/
|
||||
const std::string& getStringValue(const std::string& _name) const;
|
||||
/**
|
||||
* @brief get the sub string value of the requested element (with error return value)
|
||||
* @param[in] _name name of the object
|
||||
* @param[in] _errorValue The return value if the element does not exist.
|
||||
* @return Value of the string or an error string (empty)
|
||||
*/
|
||||
std::string getStringValue(const std::string& _name, const std::string& _errorValue) const;
|
||||
std::string getStringValue(const std::string& _name, const std::string& _errorValue="") const;
|
||||
/**
|
||||
* @brief get the sub boolean value of the requested element.
|
||||
* @param[in] _name name of the object.
|
||||
@ -141,6 +135,16 @@ namespace ejson {
|
||||
* @return false if an error occured
|
||||
*/
|
||||
bool addNumber(const std::string& _name, double _value);
|
||||
/**
|
||||
* @brief Remove Value with his name
|
||||
* @param[in] _name Name of the object
|
||||
*/
|
||||
void remove(const std::string& _name);
|
||||
/**
|
||||
* @brief Remove Value with his id
|
||||
* @param[in] _id Id of the element.
|
||||
*/
|
||||
void remove(size_t _id);
|
||||
public:
|
||||
using iterator = ejson::iterator<ejson::Object>; //!< Specify iterator of the Object methode
|
||||
/**
|
||||
@ -163,6 +167,11 @@ namespace ejson {
|
||||
* @return const iterator on the next of the last position of the Value
|
||||
*/
|
||||
const iterator end() const;
|
||||
/**
|
||||
* @brief Remove Value with his iterator
|
||||
* @param[in] _it Iterator on the Value.
|
||||
*/
|
||||
iterator remove(const iterator& _it);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ ejson::String::String(ememory::SharedPtr<ejson::internal::Value> _internalValue)
|
||||
if (m_data == nullptr) {
|
||||
return;
|
||||
}
|
||||
if (m_data->isString() == false) {
|
||||
if (m_data->getType() != ejson::valueType::string) {
|
||||
// try to set wrong type inside ... ==> remove it ...
|
||||
m_data = nullptr;
|
||||
}
|
||||
@ -43,11 +43,10 @@ void ejson::String::set(const std::string& _value) {
|
||||
static_cast<ejson::internal::String*>(m_data.get())->set(_value);
|
||||
}
|
||||
|
||||
const std::string& ejson::String::get() const {
|
||||
std::string ejson::String::get(const std::string& _errorValue) const {
|
||||
if (m_data == nullptr) {
|
||||
static const std::string errorValue = "";
|
||||
EJSON_ERROR("Can not get (nullptr) ...");
|
||||
return errorValue;
|
||||
return _errorValue;
|
||||
}
|
||||
return static_cast<ejson::internal::String*>(m_data.get())->get();
|
||||
}
|
||||
|
@ -41,9 +41,10 @@ namespace ejson {
|
||||
void set(const std::string& _value);
|
||||
/**
|
||||
* @brief get the current element Value.
|
||||
* @param[in] _errorValue The return value if an error occured.
|
||||
* @return the reference of the string value.
|
||||
*/
|
||||
const std::string& get() const;
|
||||
std::string get(const std::string& _errorValue="") const;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -125,49 +125,50 @@ bool ejson::Value::isDocument() const {
|
||||
if (m_data == nullptr) {
|
||||
return false;
|
||||
}
|
||||
return m_data->isDocument();
|
||||
enum ejson::valueType type = m_data->getType();
|
||||
return type == ejson::valueType::document;
|
||||
}
|
||||
|
||||
bool ejson::Value::isArray() const {
|
||||
if (m_data == nullptr) {
|
||||
return false;
|
||||
}
|
||||
return m_data->isArray();
|
||||
return m_data->getType() == ejson::valueType::array;
|
||||
}
|
||||
|
||||
bool ejson::Value::isObject() const {
|
||||
if (m_data == nullptr) {
|
||||
return false;
|
||||
}
|
||||
return m_data->isObject();
|
||||
return m_data->getType() == ejson::valueType::object;
|
||||
}
|
||||
|
||||
bool ejson::Value::isString() const {
|
||||
if (m_data == nullptr) {
|
||||
return false;
|
||||
}
|
||||
return m_data->isString();
|
||||
return m_data->getType() == ejson::valueType::string;
|
||||
}
|
||||
|
||||
bool ejson::Value::isNumber() const {
|
||||
if (m_data == nullptr) {
|
||||
return false;
|
||||
}
|
||||
return m_data->isNumber();
|
||||
return m_data->getType() == ejson::valueType::number;
|
||||
}
|
||||
|
||||
bool ejson::Value::isBoolean() const {
|
||||
if (m_data == nullptr) {
|
||||
return false;
|
||||
}
|
||||
return m_data->isBoolean();
|
||||
return m_data->getType() == ejson::valueType::boolean;
|
||||
}
|
||||
|
||||
bool ejson::Value::isNull() const {
|
||||
if (m_data == nullptr) {
|
||||
return false;
|
||||
}
|
||||
return m_data->isNull();
|
||||
return m_data->getType() == ejson::valueType::null;
|
||||
}
|
||||
|
||||
|
||||
|
@ -63,6 +63,8 @@ namespace ejson {
|
||||
void display() const;
|
||||
/**
|
||||
* @brief Check if the element exit
|
||||
* @return true The element exist
|
||||
* @return False The element does NOT exist
|
||||
*/
|
||||
bool exist() const;
|
||||
/**
|
||||
|
@ -120,3 +120,8 @@ ejson::Value ejson::iterator<EJSON_BASE_T>::operator *() noexcept {
|
||||
return m_data[m_id];
|
||||
}
|
||||
|
||||
template<class EJSON_BASE_T>
|
||||
size_t ejson::iterator<EJSON_BASE_T>::getId() const noexcept {
|
||||
return m_id;
|
||||
}
|
||||
|
||||
|
@ -162,21 +162,20 @@ bool ejson::internal::Array::iGenerate(std::string& _data, size_t _indent) const
|
||||
if (tmp == nullptr) {
|
||||
continue;
|
||||
}
|
||||
if (true == tmp->isObject()) {
|
||||
if ( tmp->getType() == ejson::valueType::object
|
||||
|| tmp->getType() == ejson::valueType::document) {
|
||||
oneLine=false;
|
||||
break;
|
||||
}
|
||||
if (true == tmp->isArray()) {
|
||||
if (tmp->getType() == ejson::valueType::array) {
|
||||
oneLine=false;
|
||||
break;
|
||||
}
|
||||
if (true == tmp->isString()) {
|
||||
ememory::SharedPtr<const ejson::internal::String> tmp2 = tmp->toString();
|
||||
if (tmp2 != nullptr) {
|
||||
if(tmp2->get().size()>40) {
|
||||
oneLine=false;
|
||||
break;
|
||||
}
|
||||
if (tmp->getType() == ejson::valueType::string) {
|
||||
ememory::SharedPtr<const ejson::internal::String> tmp2 = std::static_pointer_cast<const ejson::internal::String>(tmp);
|
||||
if(tmp2->get().size()>40) {
|
||||
oneLine=false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -218,20 +217,11 @@ bool ejson::internal::Array::add(ememory::SharedPtr<ejson::internal::Value> _ele
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ejson::internal::Array::addString(const std::string& _value) {
|
||||
return add(ejson::internal::String::create(_value));
|
||||
}
|
||||
|
||||
bool ejson::internal::Array::addNull() {
|
||||
return add(ejson::internal::Null::create());
|
||||
}
|
||||
|
||||
bool ejson::internal::Array::addBoolean(bool _value) {
|
||||
return add(ejson::internal::Boolean::create(_value));
|
||||
}
|
||||
|
||||
bool ejson::internal::Array::addNumber(double _value) {
|
||||
return add(ejson::internal::Number::create(_value));
|
||||
void ejson::internal::Array::remove(size_t _id) {
|
||||
if (_id > m_value.size()) {
|
||||
EJSON_ERROR("try remove out of bound element");
|
||||
}
|
||||
m_value.erase(m_value.begin() + _id);
|
||||
}
|
||||
|
||||
|
||||
@ -240,11 +230,11 @@ bool ejson::internal::Array::transfertIn(ememory::SharedPtr<ejson::internal::Val
|
||||
EJSON_ERROR("Request transfer on an nullptr pointer");
|
||||
return false;
|
||||
}
|
||||
ememory::SharedPtr<ejson::internal::Array> other = _obj->toArray();
|
||||
if (other == nullptr) {
|
||||
EJSON_ERROR("Request transfer on an element that is not an array");
|
||||
if (_obj->getType() != ejson::valueType::array) {
|
||||
EJSON_ERROR("Request transfer on an element that is not an Array");
|
||||
return false;
|
||||
}
|
||||
ememory::SharedPtr<ejson::internal::Array> other = std::static_pointer_cast<ejson::internal::Array>(_obj);
|
||||
// remove destination elements
|
||||
other->clear();
|
||||
// Copy to the destination
|
||||
@ -271,140 +261,3 @@ ememory::SharedPtr<ejson::internal::Value> ejson::internal::Array::clone() const
|
||||
return output;
|
||||
}
|
||||
|
||||
ememory::SharedPtr<ejson::internal::Object> ejson::internal::Array::getObject(size_t _id) {
|
||||
ememory::SharedPtr<ejson::internal::Value> tmpElement = m_value[_id];
|
||||
if (tmpElement == nullptr) {
|
||||
return ememory::SharedPtr<ejson::internal::Object>();
|
||||
}
|
||||
return tmpElement->toObject();
|
||||
}
|
||||
const ememory::SharedPtr<const ejson::internal::Object> ejson::internal::Array::getObject(size_t _id) const {
|
||||
const ememory::SharedPtr<const ejson::internal::Value> tmpElement = m_value[_id];
|
||||
if (tmpElement == nullptr) {
|
||||
return ememory::SharedPtr<const ejson::internal::Object>();
|
||||
}
|
||||
return tmpElement->toObject();
|
||||
}
|
||||
|
||||
ememory::SharedPtr<ejson::internal::String> ejson::internal::Array::getString(size_t _id) {
|
||||
ememory::SharedPtr<ejson::internal::Value> tmpElement = m_value[_id];
|
||||
if (tmpElement == nullptr) {
|
||||
return ememory::SharedPtr<ejson::internal::String>();
|
||||
}
|
||||
return tmpElement->toString();
|
||||
}
|
||||
|
||||
const ememory::SharedPtr<const ejson::internal::String> ejson::internal::Array::getString(size_t _id) const {
|
||||
const ememory::SharedPtr<const ejson::internal::Value> tmpElement = m_value[_id];
|
||||
if (tmpElement == nullptr) {
|
||||
return ememory::SharedPtr<const ejson::internal::String>();
|
||||
}
|
||||
return tmpElement->toString();
|
||||
}
|
||||
|
||||
ememory::SharedPtr<ejson::internal::Array> ejson::internal::Array::getArray(size_t _id) {
|
||||
ememory::SharedPtr<ejson::internal::Value> tmpElement = m_value[_id];
|
||||
if (tmpElement == nullptr) {
|
||||
return ememory::SharedPtr<ejson::internal::Array>();
|
||||
}
|
||||
return tmpElement->toArray();
|
||||
}
|
||||
|
||||
const ememory::SharedPtr<const ejson::internal::Array> ejson::internal::Array::getArray(size_t _id) const {
|
||||
const ememory::SharedPtr<const ejson::internal::Value> tmpElement = m_value[_id];
|
||||
if (tmpElement == nullptr) {
|
||||
return ememory::SharedPtr<const ejson::internal::Array>();
|
||||
}
|
||||
return tmpElement->toArray();
|
||||
}
|
||||
|
||||
ememory::SharedPtr<ejson::internal::Null> ejson::internal::Array::getNull(size_t _id) {
|
||||
ememory::SharedPtr<ejson::internal::Value> tmpElement = m_value[_id];
|
||||
if (tmpElement == nullptr) {
|
||||
return ememory::SharedPtr<ejson::internal::Null>();
|
||||
}
|
||||
return tmpElement->toNull();
|
||||
}
|
||||
|
||||
const ememory::SharedPtr<const ejson::internal::Null> ejson::internal::Array::getNull(size_t _id) const {
|
||||
const ememory::SharedPtr<const ejson::internal::Value> tmpElement = m_value[_id];
|
||||
if (tmpElement == nullptr) {
|
||||
return ememory::SharedPtr<const ejson::internal::Null>();
|
||||
}
|
||||
return tmpElement->toNull();
|
||||
}
|
||||
|
||||
ememory::SharedPtr<ejson::internal::Number> ejson::internal::Array::getNumber(size_t _id) {
|
||||
ememory::SharedPtr<ejson::internal::Value> tmpElement = m_value[_id];
|
||||
if (tmpElement == nullptr) {
|
||||
return ememory::SharedPtr<ejson::internal::Number>();
|
||||
}
|
||||
return tmpElement->toNumber();
|
||||
}
|
||||
|
||||
const ememory::SharedPtr<const ejson::internal::Number> ejson::internal::Array::getNumber(size_t _id) const {
|
||||
const ememory::SharedPtr<const ejson::internal::Value> tmpElement = m_value[_id];
|
||||
if (tmpElement == nullptr) {
|
||||
return ememory::SharedPtr<const ejson::internal::Number>();
|
||||
}
|
||||
return tmpElement->toNumber();
|
||||
}
|
||||
|
||||
ememory::SharedPtr<ejson::internal::Boolean> ejson::internal::Array::getBoolean(size_t _id) {
|
||||
ememory::SharedPtr<ejson::internal::Value> tmpElement = m_value[_id];
|
||||
if (tmpElement == nullptr) {
|
||||
return ememory::SharedPtr<ejson::internal::Boolean>();
|
||||
}
|
||||
return tmpElement->toBoolean();
|
||||
}
|
||||
|
||||
const ememory::SharedPtr<const ejson::internal::Boolean> ejson::internal::Array::getBoolean(size_t _id) const {
|
||||
const ememory::SharedPtr<const ejson::internal::Value> tmpElement = m_value[_id];
|
||||
if (tmpElement == nullptr) {
|
||||
return ememory::SharedPtr<const ejson::internal::Boolean>();
|
||||
}
|
||||
return tmpElement->toBoolean();
|
||||
}
|
||||
|
||||
std::string ejson::internal::Array::getStringValue(size_t _id) {
|
||||
ememory::SharedPtr<ejson::internal::String> tmpElement = getString(_id);
|
||||
if (tmpElement == nullptr) {
|
||||
return "";
|
||||
}
|
||||
return tmpElement->get();
|
||||
}
|
||||
|
||||
const std::string& ejson::internal::Array::getStringValue(size_t _id) const {
|
||||
static const std::string errorValue("");
|
||||
const ememory::SharedPtr<const ejson::internal::String> tmpElement = getString(_id);
|
||||
if (tmpElement == nullptr) {
|
||||
return errorValue;
|
||||
}
|
||||
return tmpElement->get();
|
||||
}
|
||||
|
||||
std::string ejson::internal::Array::getStringValue(size_t _id, const std::string& _errorValue) const {
|
||||
const ememory::SharedPtr<const ejson::internal::String> tmpElement = getString(_id);
|
||||
if (tmpElement == nullptr) {
|
||||
return _errorValue;
|
||||
}
|
||||
return tmpElement->get();
|
||||
}
|
||||
|
||||
double ejson::internal::Array::getNumberValue(size_t _id, double _errorValue) const {
|
||||
const ememory::SharedPtr<const ejson::internal::Number> tmpElement = getNumber(_id);
|
||||
if (tmpElement == nullptr) {
|
||||
return _errorValue;
|
||||
}
|
||||
return tmpElement->get();
|
||||
}
|
||||
|
||||
bool ejson::internal::Array::getBooleanValue(size_t _id, bool _errorValue) const {
|
||||
const ememory::SharedPtr<const ejson::internal::Boolean> tmpElement = getBoolean(_id);
|
||||
if (tmpElement == nullptr) {
|
||||
return _errorValue;
|
||||
}
|
||||
return tmpElement->get();
|
||||
}
|
||||
|
||||
|
||||
|
@ -19,13 +19,9 @@ namespace ejson {
|
||||
*/
|
||||
Array() {
|
||||
m_type = ejson::valueType::array;
|
||||
};
|
||||
}
|
||||
public:
|
||||
static ememory::SharedPtr<Array> create();
|
||||
/**
|
||||
* @brief destructor
|
||||
*/
|
||||
virtual ~Array() { };
|
||||
private:
|
||||
std::vector<ememory::SharedPtr<ejson::internal::Value> > m_value; //!< vector of sub elements
|
||||
public:
|
||||
@ -35,7 +31,7 @@ namespace ejson {
|
||||
*/
|
||||
size_t size() const {
|
||||
return m_value.size();
|
||||
};
|
||||
}
|
||||
/**
|
||||
* @brief get the pointer on an element reference with his ID.
|
||||
* @param[in] _id Id of the element.
|
||||
@ -43,96 +39,11 @@ namespace ejson {
|
||||
*/
|
||||
ememory::SharedPtr<ejson::internal::Value> get(size_t _id) {
|
||||
return m_value[_id];
|
||||
};
|
||||
}
|
||||
//! @previous
|
||||
const ememory::SharedPtr<const ejson::internal::Value> get(size_t _id) const{
|
||||
return m_value[_id];
|
||||
};
|
||||
//! @previous
|
||||
ememory::SharedPtr<ejson::internal::Value> operator[] (size_t _id) {
|
||||
return m_value[_id];
|
||||
}
|
||||
//! @previous
|
||||
const ememory::SharedPtr<const ejson::internal::Value> operator[] (size_t _id) const {
|
||||
return m_value[_id];
|
||||
}
|
||||
/**
|
||||
* @brief get the pointer on an element reference with his ID (casted in Object if it is an object).
|
||||
* @param[in] _id Id of the element.
|
||||
* @return nullptr if the element does not exist.
|
||||
*/
|
||||
ememory::SharedPtr<ejson::internal::Object> getObject(size_t _id);
|
||||
//! @previous
|
||||
const ememory::SharedPtr<const ejson::internal::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.
|
||||
*/
|
||||
ememory::SharedPtr<ejson::internal::String> getString(size_t _id);
|
||||
//! @previous
|
||||
const ememory::SharedPtr<const ejson::internal::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.
|
||||
* @return value of the element.
|
||||
*/
|
||||
std::string getStringValue(size_t _id);
|
||||
//! @previous
|
||||
const std::string& getStringValue(size_t _id) const;
|
||||
/**
|
||||
* @brief get the value of the string element
|
||||
* @param[in] _id Id of the element.
|
||||
* @param[in] _errorValue The return value if an error occured.
|
||||
* @return value of the element, or the _errorValue.
|
||||
*/
|
||||
std::string getStringValue(size_t _id, const std::string& _errorValue) const;
|
||||
/**
|
||||
* @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.
|
||||
* @return nullptr if the element does not exist.
|
||||
*/
|
||||
ememory::SharedPtr<ejson::internal::Array> getArray(size_t _id);
|
||||
//! @previous
|
||||
const ememory::SharedPtr<const ejson::internal::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.
|
||||
*/
|
||||
ememory::SharedPtr<ejson::internal::Null> getNull(size_t _id);
|
||||
//! @previous
|
||||
const ememory::SharedPtr<const ejson::internal::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.
|
||||
*/
|
||||
ememory::SharedPtr<ejson::internal::Number> getNumber(size_t _id);
|
||||
//! @previous
|
||||
const ememory::SharedPtr<const ejson::internal::Number> getNumber(size_t _id) const;
|
||||
/**
|
||||
* @brief get the value of the Number element
|
||||
* @param[in] _id Id of the element.
|
||||
* @param[in] _errorValue The return value if an error occured.
|
||||
* @return value of the element, or the _errorValue.
|
||||
*/
|
||||
double getNumberValue(size_t _id, double _errorValue) const;
|
||||
/**
|
||||
* @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.
|
||||
* @return nullptr if the element does not exist.
|
||||
*/
|
||||
ememory::SharedPtr<ejson::internal::Boolean> getBoolean(size_t _id);
|
||||
//! @previous
|
||||
const ememory::SharedPtr<const ejson::internal::Boolean> getBoolean(size_t _id) const;
|
||||
/**
|
||||
* @brief get the value of the Boolean element
|
||||
* @param[in] _id Id of the element.
|
||||
* @param[in] _errorValue The return value if an error occured.
|
||||
* @return value of the element, or the _errorValue.
|
||||
*/
|
||||
bool getBooleanValue(size_t _id, bool _errorValue) const;
|
||||
/**
|
||||
* @brief add an element on the array.
|
||||
* @param[in] _element element to add.
|
||||
@ -140,35 +51,16 @@ namespace ejson {
|
||||
*/
|
||||
bool add(ememory::SharedPtr<ejson::internal::Value> _element);
|
||||
/**
|
||||
* @brief add a string element in the Object (automatic creation)
|
||||
* @param[in] _value string value to add
|
||||
* @return false if an error occured
|
||||
* @brief Remove Value with his Id
|
||||
* @param[in] _id Id of the element.
|
||||
*/
|
||||
bool addString(const std::string& _value);
|
||||
/**
|
||||
* @brief add a "null" element in the Object (automatic creation)
|
||||
* @return false if an error occured
|
||||
*/
|
||||
bool addNull();
|
||||
/**
|
||||
* @brief add a boolean element in the Object (automatic creation)
|
||||
* @param[in] _value boolean value to add
|
||||
* @return false if an error occured
|
||||
*/
|
||||
bool addBoolean(bool _value);
|
||||
/**
|
||||
* @brief add a double element in the Object (automatic creation)
|
||||
* @param[in] _value double value to add
|
||||
* @return false if an error occured
|
||||
*/
|
||||
bool addNumber(double _value);
|
||||
|
||||
public: // herited function :
|
||||
virtual bool iParse(const std::string& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::internal::Document& _doc);
|
||||
virtual bool iGenerate(std::string& _data, size_t _indent) const;
|
||||
virtual void clear();
|
||||
virtual bool transfertIn(ememory::SharedPtr<ejson::internal::Value> _obj);
|
||||
virtual ememory::SharedPtr<ejson::internal::Value> clone() const;
|
||||
void remove(size_t _id);
|
||||
public:
|
||||
bool iParse(const std::string& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::internal::Document& _doc) override;
|
||||
bool iGenerate(std::string& _data, size_t _indent) const override;
|
||||
void clear() override;
|
||||
bool transfertIn(ememory::SharedPtr<ejson::internal::Value> _obj) override;
|
||||
ememory::SharedPtr<ejson::internal::Value> clone() const override;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,18 @@ ememory::SharedPtr<ejson::internal::Boolean> ejson::internal::Boolean::create(bo
|
||||
return ememory::SharedPtr<ejson::internal::Boolean>(new ejson::internal::Boolean(_value));
|
||||
}
|
||||
|
||||
ejson::internal::Boolean::Boolean(bool _value) :
|
||||
m_value(_value) {
|
||||
m_type = ejson::valueType::boolean;
|
||||
}
|
||||
|
||||
void ejson::internal::Boolean::set(bool _value) {
|
||||
m_value = _value;
|
||||
}
|
||||
|
||||
bool ejson::internal::Boolean::get() const {
|
||||
return m_value;
|
||||
}
|
||||
|
||||
bool ejson::internal::Boolean::iParse(const std::string& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::internal::Document& _doc) {
|
||||
EJSON_PARSE_ELEMENT("start parse : 'Boolean' ");
|
||||
@ -59,11 +71,11 @@ bool ejson::internal::Boolean::transfertIn(ememory::SharedPtr<ejson::internal::V
|
||||
EJSON_ERROR("Request transfer on an NULL pointer");
|
||||
return false;
|
||||
}
|
||||
ememory::SharedPtr<ejson::internal::Boolean> other = _obj->toBoolean();
|
||||
if (other == nullptr) {
|
||||
if (_obj->getType() != ejson::valueType::boolean) {
|
||||
EJSON_ERROR("Request transfer on an element that is not an Boolean");
|
||||
return false;
|
||||
}
|
||||
ememory::SharedPtr<ejson::internal::Boolean> other = std::static_pointer_cast<ejson::internal::Boolean>(_obj);
|
||||
// remove destination elements
|
||||
other->m_value = m_value;
|
||||
m_value = false;
|
||||
|
@ -17,18 +17,9 @@ namespace ejson {
|
||||
/**
|
||||
* @brief basic element of a xml structure
|
||||
*/
|
||||
Boolean(bool _value=false) :
|
||||
m_value(_value) {
|
||||
m_type = ejson::valueType::boolean;
|
||||
};
|
||||
Boolean(bool _value=false);
|
||||
public:
|
||||
static ememory::SharedPtr<Boolean> create(bool _value=false);
|
||||
/**
|
||||
* @brief destructor
|
||||
*/
|
||||
virtual ~Boolean() {
|
||||
|
||||
};
|
||||
protected:
|
||||
bool m_value; //!< value of the node
|
||||
public:
|
||||
@ -36,21 +27,17 @@ namespace ejson {
|
||||
* @brief set the value of the node.
|
||||
* @param[in] _value New value of the node.
|
||||
*/
|
||||
void set(bool _value) {
|
||||
m_value = _value;
|
||||
};
|
||||
void set(bool _value);
|
||||
/**
|
||||
* @brief get the current element Value.
|
||||
* @return the reference of the string value.
|
||||
*/
|
||||
bool get() const {
|
||||
return m_value;
|
||||
};
|
||||
public: // herited function :
|
||||
virtual bool iParse(const std::string& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::internal::Document& _doc);
|
||||
virtual bool iGenerate(std::string& _data, size_t _indent) const;
|
||||
virtual bool transfertIn(ememory::SharedPtr<ejson::internal::Value> _obj);
|
||||
virtual ememory::SharedPtr<ejson::internal::Value> clone() const;
|
||||
bool get() const;
|
||||
public:
|
||||
bool iParse(const std::string& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::internal::Document& _doc) override;
|
||||
bool iGenerate(std::string& _data, size_t _indent) const override;
|
||||
bool transfertIn(ememory::SharedPtr<ejson::internal::Value> _obj) override;
|
||||
ememory::SharedPtr<ejson::internal::Value> clone() const override;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -29,10 +29,6 @@ ejson::internal::Document::Document() :
|
||||
m_type = ejson::valueType::document;
|
||||
}
|
||||
|
||||
ejson::internal::Document::~Document() {
|
||||
|
||||
}
|
||||
|
||||
bool ejson::internal::Document::iGenerate(std::string& _data, size_t _indent) const {
|
||||
ejson::internal::Object::iGenerate(_data, _indent+1);
|
||||
_data += "\n";
|
||||
|
@ -23,10 +23,6 @@ namespace ejson {
|
||||
*/
|
||||
Document();
|
||||
static ememory::SharedPtr<Document> create();
|
||||
/**
|
||||
* @brief Destructor
|
||||
*/
|
||||
virtual ~Document();
|
||||
public:
|
||||
/**
|
||||
* @brief parse a string that contain an XML
|
||||
@ -71,9 +67,9 @@ namespace ejson {
|
||||
|
||||
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::internal::Document& _doc);
|
||||
virtual bool iGenerate(std::string& _data, size_t _indent) const;
|
||||
public:
|
||||
bool iParse(const std::string& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::internal::Document& _doc) override;
|
||||
bool iGenerate(std::string& _data, size_t _indent) const override;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,9 @@ ememory::SharedPtr<ejson::internal::Null> ejson::internal::Null::create() {
|
||||
return ememory::SharedPtr<ejson::internal::Null>(new ejson::internal::Null());
|
||||
}
|
||||
|
||||
ejson::internal::Null::Null() {
|
||||
m_type = ejson::valueType::null;
|
||||
}
|
||||
|
||||
bool ejson::internal::Null::iParse(const std::string& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::internal::Document& _doc) {
|
||||
EJSON_PARSE_ELEMENT("start parse : 'Null' ");
|
||||
@ -45,8 +48,7 @@ bool ejson::internal::Null::transfertIn(ememory::SharedPtr<ejson::internal::Valu
|
||||
EJSON_ERROR("Request transfer on an nullptr pointer");
|
||||
return false;
|
||||
}
|
||||
ememory::SharedPtr<ejson::internal::Null> other = _obj->toNull();
|
||||
if (other == nullptr) {
|
||||
if (_obj->getType() == ejson::valueType::null) {
|
||||
EJSON_ERROR("Request transfer on an element that is not an Null");
|
||||
return false;
|
||||
}
|
||||
|
@ -17,20 +17,14 @@ namespace ejson {
|
||||
/**
|
||||
* @brief basic element of a xml structure
|
||||
*/
|
||||
Null() {
|
||||
m_type = ejson::valueType::null;
|
||||
};
|
||||
Null();
|
||||
public:
|
||||
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::internal::Document& _doc);
|
||||
virtual bool iGenerate(std::string& _data, size_t _indent) const;
|
||||
virtual bool transfertIn(ememory::SharedPtr<ejson::internal::Value> _obj);
|
||||
virtual ememory::SharedPtr<ejson::internal::Value> clone() const;
|
||||
public:
|
||||
bool iParse(const std::string& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::internal::Document& _doc) override;
|
||||
bool iGenerate(std::string& _data, size_t _indent) const override;
|
||||
bool transfertIn(ememory::SharedPtr<ejson::internal::Value> _obj) override;
|
||||
ememory::SharedPtr<ejson::internal::Value> clone() const override;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,11 @@ ememory::SharedPtr<ejson::internal::Number> ejson::internal::Number::create(doub
|
||||
return ememory::SharedPtr<ejson::internal::Number>(new ejson::internal::Number(_value));
|
||||
}
|
||||
|
||||
ejson::internal::Number::Number(double _value) :
|
||||
m_value(_value) {
|
||||
m_type = ejson::valueType::number;
|
||||
}
|
||||
|
||||
bool ejson::internal::Number::iParse(const std::string& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::internal::Document& _doc) {
|
||||
EJSON_PARSE_ELEMENT("start parse : 'Number' ");
|
||||
std::string tmpVal;
|
||||
@ -55,11 +60,11 @@ bool ejson::internal::Number::transfertIn(ememory::SharedPtr<ejson::internal::Va
|
||||
EJSON_ERROR("Request transfer on an nullptr pointer");
|
||||
return false;
|
||||
}
|
||||
ememory::SharedPtr<ejson::internal::Number> other = _obj->toNumber();
|
||||
if (other == nullptr) {
|
||||
if (_obj->getType() != ejson::valueType::number) {
|
||||
EJSON_ERROR("Request transfer on an element that is not an Number");
|
||||
return false;
|
||||
}
|
||||
ememory::SharedPtr<ejson::internal::Number> other = std::static_pointer_cast<ejson::internal::Number>(_obj);
|
||||
// remove destination elements
|
||||
other->m_value = m_value;
|
||||
m_value = 0;
|
||||
@ -75,4 +80,10 @@ ememory::SharedPtr<ejson::internal::Value> ejson::internal::Number::clone() cons
|
||||
return output;
|
||||
}
|
||||
|
||||
void ejson::internal::Number::set(double _value) {
|
||||
m_value = _value;
|
||||
}
|
||||
|
||||
double ejson::internal::Number::get() const {
|
||||
return m_value;
|
||||
}
|
||||
|
@ -17,16 +17,9 @@ namespace ejson {
|
||||
/**
|
||||
* @brief basic element of a xml structure
|
||||
*/
|
||||
Number(double _value=0.0) :
|
||||
m_value(_value) {
|
||||
m_type = ejson::valueType::number;
|
||||
};
|
||||
Number(double _value=0.0);
|
||||
public:
|
||||
static ememory::SharedPtr<Number> create(double _value=0.0);
|
||||
/**
|
||||
* @brief destructor
|
||||
*/
|
||||
virtual ~Number() { };
|
||||
protected:
|
||||
double m_value; //!< value of the node
|
||||
public:
|
||||
@ -34,35 +27,17 @@ namespace ejson {
|
||||
* @brief set the value of the node.
|
||||
* @param[in] _value New value of the node.
|
||||
*/
|
||||
void set(double _value) {
|
||||
m_value = _value;
|
||||
};
|
||||
void set(double _value);
|
||||
/**
|
||||
* @brief Get the current element Value.
|
||||
* @return The double number registered
|
||||
*/
|
||||
double get() const {
|
||||
return m_value;
|
||||
};
|
||||
/**
|
||||
* @brief Get the current element Value.
|
||||
* @return The 32 bit integer number registered
|
||||
*/
|
||||
int32_t getInt32() const {
|
||||
return (int32_t)m_value;
|
||||
};
|
||||
/**
|
||||
* @brief Get the current element Value.
|
||||
* @return The 64 bit integer number registered
|
||||
*/
|
||||
int64_t getInt64() const {
|
||||
return (int64_t)m_value;
|
||||
};
|
||||
public: // herited function :
|
||||
virtual bool iParse(const std::string& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::internal::Document& _doc);
|
||||
virtual bool iGenerate(std::string& _data, size_t _indent) const;
|
||||
virtual bool transfertIn(ememory::SharedPtr<ejson::internal::Value> _obj);
|
||||
virtual ememory::SharedPtr<ejson::internal::Value> clone() const;
|
||||
double get() const;
|
||||
public:
|
||||
bool iParse(const std::string& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::internal::Document& _doc) override;
|
||||
bool iGenerate(std::string& _data, size_t _indent) const override;
|
||||
bool transfertIn(ememory::SharedPtr<ejson::internal::Value> _obj) override;
|
||||
ememory::SharedPtr<ejson::internal::Value> clone() const override;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -222,26 +222,25 @@ bool ejson::internal::Object::iGenerate(std::string& _data, size_t _indent) cons
|
||||
oneLine=false;
|
||||
} else {
|
||||
for (int32_t iii=0; iii<m_value.size() ; iii++) {
|
||||
ememory::SharedPtr<ejson::internal::Value> tmp = m_value[iii];
|
||||
ememory::SharedPtr<const ejson::internal::Value> tmp = m_value[iii];
|
||||
if (tmp == nullptr) {
|
||||
continue;
|
||||
}
|
||||
if (tmp->isObject() == true) {
|
||||
if ( tmp->getType() == ejson::valueType::object
|
||||
|| tmp->getType() == ejson::valueType::document) {
|
||||
oneLine=false;
|
||||
break;
|
||||
}
|
||||
if (tmp->isArray() == true) {
|
||||
if (tmp->getType() == ejson::valueType::array) {
|
||||
oneLine=false;
|
||||
break;
|
||||
}
|
||||
if (tmp->isString() == true) {
|
||||
ememory::SharedPtr<ejson::internal::String> tmp2 = tmp->toString();
|
||||
if (tmp2 != nullptr) {
|
||||
if( tmp2->get().size()>25
|
||||
|| m_value.getKey(iii).size()>25) {
|
||||
oneLine=false;
|
||||
break;
|
||||
}
|
||||
if (tmp->getType() == ejson::valueType::string) {
|
||||
ememory::SharedPtr<const ejson::internal::String> tmp2 = std::static_pointer_cast<const ejson::internal::String>(tmp);
|
||||
if( tmp2->get().size()>25
|
||||
|| m_value.getKey(iii).size()>25) {
|
||||
oneLine=false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -279,150 +278,40 @@ bool ejson::internal::Object::exist(const std::string& _name) const {
|
||||
return m_value.exist(_name);
|
||||
}
|
||||
|
||||
std::vector<std::string> ejson::internal::Object::getKeys() const {
|
||||
return m_value.getKeys();
|
||||
}
|
||||
|
||||
size_t ejson::internal::Object::size() const {
|
||||
return m_value.size();
|
||||
}
|
||||
|
||||
ememory::SharedPtr<ejson::internal::Value> ejson::internal::Object::get(size_t _id) {
|
||||
return m_value[_id];
|
||||
}
|
||||
|
||||
const ememory::SharedPtr<const ejson::internal::Value> ejson::internal::Object::get(size_t _id) const{
|
||||
return m_value[_id];
|
||||
}
|
||||
|
||||
ememory::SharedPtr<ejson::internal::Value> ejson::internal::Object::get(const std::string& _name) {
|
||||
if (false == m_value.exist(_name)) {
|
||||
if (m_value.exist(_name) == false) {
|
||||
return ememory::SharedPtr<ejson::internal::Value>();
|
||||
}
|
||||
return m_value[_name];
|
||||
}
|
||||
|
||||
const ememory::SharedPtr<const ejson::internal::Value> ejson::internal::Object::get(const std::string& _name) const {
|
||||
if (false == m_value.exist(_name)) {
|
||||
if (m_value.exist(_name) == false) {
|
||||
return ememory::SharedPtr<const ejson::internal::Value>();
|
||||
}
|
||||
return m_value[_name];
|
||||
}
|
||||
|
||||
ememory::SharedPtr<ejson::internal::Object> ejson::internal::Object::getObject(const std::string& _name) {
|
||||
ememory::SharedPtr<ejson::internal::Value> tmp = get(_name);
|
||||
if (tmp == nullptr) {
|
||||
return ememory::SharedPtr<ejson::internal::Object>();
|
||||
}
|
||||
return std::dynamic_pointer_cast<ejson::internal::Object>(tmp);
|
||||
std::string ejson::internal::Object::getKey(size_t _id) const {
|
||||
return m_value.getKey(_id);
|
||||
}
|
||||
|
||||
const ememory::SharedPtr<const ejson::internal::Object> ejson::internal::Object::getObject(const std::string& _name) const {
|
||||
const ememory::SharedPtr<const ejson::internal::Value> tmp = get(_name);
|
||||
if (tmp == nullptr) {
|
||||
return ememory::SharedPtr<const ejson::internal::Object>();
|
||||
}
|
||||
return std::dynamic_pointer_cast<const ejson::internal::Object>(tmp);
|
||||
}
|
||||
|
||||
ememory::SharedPtr<ejson::internal::Array> ejson::internal::Object::getArray(const std::string& _name) {
|
||||
ememory::SharedPtr<ejson::internal::Value> tmp = get(_name);
|
||||
if (tmp == nullptr) {
|
||||
return ememory::SharedPtr<ejson::internal::Array>();
|
||||
}
|
||||
return std::dynamic_pointer_cast<ejson::internal::Array>(tmp);
|
||||
}
|
||||
|
||||
const ememory::SharedPtr<const ejson::internal::Array> ejson::internal::Object::getArray(const std::string& _name) const {
|
||||
const ememory::SharedPtr<const ejson::internal::Value> tmp = get(_name);
|
||||
if (tmp == nullptr) {
|
||||
return ememory::SharedPtr<const ejson::internal::Array>();
|
||||
}
|
||||
return std::dynamic_pointer_cast<const ejson::internal::Array>(tmp);
|
||||
}
|
||||
|
||||
ememory::SharedPtr<ejson::internal::Null> ejson::internal::Object::getNull(const std::string& _name) {
|
||||
ememory::SharedPtr<ejson::internal::Value> tmp = get(_name);
|
||||
if (tmp == nullptr) {
|
||||
return ememory::SharedPtr<ejson::internal::Null>();
|
||||
}
|
||||
return std::dynamic_pointer_cast<ejson::internal::Null>(tmp);
|
||||
}
|
||||
|
||||
const ememory::SharedPtr<const ejson::internal::Null> ejson::internal::Object::getNull(const std::string& _name) const {
|
||||
const ememory::SharedPtr<const ejson::internal::Value> tmp = get(_name);
|
||||
if (tmp == nullptr) {
|
||||
return ememory::SharedPtr<const ejson::internal::Null>();
|
||||
}
|
||||
return std::dynamic_pointer_cast<const ejson::internal::Null>(tmp);
|
||||
}
|
||||
|
||||
ememory::SharedPtr<ejson::internal::String> ejson::internal::Object::getString(const std::string& _name) {
|
||||
ememory::SharedPtr<ejson::internal::Value> tmp = get(_name);
|
||||
if (tmp == nullptr) {
|
||||
return ememory::SharedPtr<ejson::internal::String>();
|
||||
}
|
||||
return std::dynamic_pointer_cast<ejson::internal::String>(tmp);
|
||||
}
|
||||
|
||||
const ememory::SharedPtr<const ejson::internal::String> ejson::internal::Object::getString(const std::string& _name) const {
|
||||
const ememory::SharedPtr<const ejson::internal::Value> tmp = get(_name);
|
||||
if (tmp == nullptr) {
|
||||
return ememory::SharedPtr<const ejson::internal::String>();
|
||||
}
|
||||
return std::dynamic_pointer_cast<const ejson::internal::String>(tmp);
|
||||
}
|
||||
|
||||
const std::string& ejson::internal::Object::getStringValue(const std::string& _name) const {
|
||||
static const std::string errorString("");
|
||||
const ememory::SharedPtr<const ejson::internal::String> tmpp = getString(_name);
|
||||
if (tmpp == nullptr) {
|
||||
return errorString;
|
||||
}
|
||||
return tmpp->get();
|
||||
}
|
||||
|
||||
std::string ejson::internal::Object::getStringValue(const std::string& _name, const std::string& _errorValue) const {
|
||||
const ememory::SharedPtr<const ejson::internal::String> tmpp = getString(_name);
|
||||
if (tmpp == nullptr) {
|
||||
return _errorValue;
|
||||
}
|
||||
return tmpp->get();
|
||||
}
|
||||
|
||||
ememory::SharedPtr<ejson::internal::Boolean> ejson::internal::Object::getBoolean(const std::string& _name) {
|
||||
ememory::SharedPtr<ejson::internal::Value> tmp = get(_name);
|
||||
if (tmp == nullptr) {
|
||||
return ememory::SharedPtr<ejson::internal::Boolean>();
|
||||
}
|
||||
return tmp->toBoolean();
|
||||
}
|
||||
|
||||
const ememory::SharedPtr<const ejson::internal::Boolean> ejson::internal::Object::getBoolean(const std::string& _name) const {
|
||||
const ememory::SharedPtr<const ejson::internal::Value> tmp = get(_name);
|
||||
if (tmp == nullptr) {
|
||||
return ememory::SharedPtr<const ejson::internal::Boolean>();
|
||||
}
|
||||
return tmp->toBoolean();
|
||||
}
|
||||
|
||||
bool ejson::internal::Object::getBooleanValue(const std::string& _name, bool _errorValue) const {
|
||||
const ememory::SharedPtr<const ejson::internal::Boolean> tmpp = getBoolean(_name);
|
||||
if (tmpp == nullptr) {
|
||||
return _errorValue;
|
||||
}
|
||||
return tmpp->get();
|
||||
}
|
||||
|
||||
ememory::SharedPtr<ejson::internal::Number> ejson::internal::Object::getNumber(const std::string& _name) {
|
||||
ememory::SharedPtr<ejson::internal::Value> tmp = get(_name);
|
||||
if (tmp == nullptr) {
|
||||
return ememory::SharedPtr<ejson::internal::Number>();
|
||||
}
|
||||
return tmp->toNumber();
|
||||
}
|
||||
|
||||
const ememory::SharedPtr<const ejson::internal::Number> ejson::internal::Object::getNumber(const std::string& _name) const {
|
||||
const ememory::SharedPtr<const ejson::internal::Value> tmp = get(_name);
|
||||
if (tmp == nullptr) {
|
||||
return ememory::SharedPtr<const ejson::internal::Number>();
|
||||
}
|
||||
return tmp->toNumber();
|
||||
}
|
||||
|
||||
double ejson::internal::Object::getNumberValue(const std::string& _name, double _errorValue) const {
|
||||
const ememory::SharedPtr<const ejson::internal::Number> tmpp = getNumber(_name);
|
||||
if (tmpp == nullptr) {
|
||||
return _errorValue;
|
||||
}
|
||||
return tmpp->get();
|
||||
}
|
||||
|
||||
|
||||
bool ejson::internal::Object::add(const std::string& _name, ememory::SharedPtr<ejson::internal::Value> _value) {
|
||||
if (_value == nullptr) {
|
||||
return false;
|
||||
@ -438,20 +327,12 @@ bool ejson::internal::Object::add(const std::string& _name, ememory::SharedPtr<e
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ejson::internal::Object::addString(const std::string& _name, const std::string& _value) {
|
||||
return add(_name, ejson::internal::String::create(_value));
|
||||
void ejson::internal::Object::remove(const std::string& _name) {
|
||||
m_value.remove(_name);
|
||||
}
|
||||
|
||||
bool ejson::internal::Object::addNull(const std::string& _name) {
|
||||
return add(_name, ejson::internal::Null::create());
|
||||
}
|
||||
|
||||
bool ejson::internal::Object::addBoolean(const std::string& _name, bool _value) {
|
||||
return add(_name, ejson::internal::Boolean::create(_value));
|
||||
}
|
||||
|
||||
bool ejson::internal::Object::addNumber(const std::string& _name, double _value) {
|
||||
return add(_name, ejson::internal::Number::create(_value));
|
||||
void ejson::internal::Object::remove(size_t _id) {
|
||||
m_value.remove(getKey(_id));
|
||||
}
|
||||
|
||||
bool ejson::internal::Object::transfertIn(ememory::SharedPtr<ejson::internal::Value> _obj) {
|
||||
@ -459,11 +340,12 @@ bool ejson::internal::Object::transfertIn(ememory::SharedPtr<ejson::internal::Va
|
||||
EJSON_ERROR("Request transfer on an nullptr pointer");
|
||||
return false;
|
||||
}
|
||||
ememory::SharedPtr<ejson::internal::Object> other = _obj->toObject();
|
||||
if (other == nullptr) {
|
||||
if ( _obj->getType() != ejson::valueType::object
|
||||
&& _obj->getType() != ejson::valueType::document) {
|
||||
EJSON_ERROR("Request transfer on an element that is not an object");
|
||||
return false;
|
||||
}
|
||||
ememory::SharedPtr<ejson::internal::Object> other = std::static_pointer_cast<ejson::internal::Object>(_obj);
|
||||
// remove destination elements
|
||||
other->clear();
|
||||
// Copy to the destination
|
||||
|
@ -25,10 +25,6 @@ namespace ejson {
|
||||
public:
|
||||
static ememory::SharedPtr<Object> create();
|
||||
static ememory::SharedPtr<Object> create(const std::string& _data);
|
||||
/**
|
||||
* @brief destructor
|
||||
*/
|
||||
virtual ~Object() { };
|
||||
protected:
|
||||
etk::Hash<ememory::SharedPtr<ejson::internal::Value> > m_value; //!< value of the node (for element this is the name, for text it is the inside text ...)
|
||||
public:
|
||||
@ -46,140 +42,35 @@ namespace ejson {
|
||||
ememory::SharedPtr<ejson::internal::Value> get(const std::string& _name);
|
||||
//! @previous
|
||||
const ememory::SharedPtr<const ejson::internal::Value> get(const std::string& _name) const;
|
||||
//! @previous
|
||||
ememory::SharedPtr<ejson::internal::Value> operator[] (const std::string& _name) {
|
||||
return get(_name);
|
||||
}
|
||||
//! @previous
|
||||
const ememory::SharedPtr<const ejson::internal::Value> operator[] (const std::string& _name) const {
|
||||
return get(_name);
|
||||
}
|
||||
public:
|
||||
/**
|
||||
* @brief Get all the element name (keys).
|
||||
* @return a vector of all name (key).
|
||||
*/
|
||||
std::vector<std::string> getKeys() const {
|
||||
return m_value.getKeys();
|
||||
}
|
||||
std::vector<std::string> getKeys() const;
|
||||
/**
|
||||
* @brief get the number of sub element in the current one
|
||||
* @return the Number of stored element
|
||||
*/
|
||||
size_t size() const {
|
||||
return m_value.size();
|
||||
};
|
||||
size_t size() const;
|
||||
/**
|
||||
* @brief get the pointer on an element reference with his ID.
|
||||
* @param[in] _id Id of the element.
|
||||
* @return nullptr if the element does not exist.
|
||||
*/
|
||||
ememory::SharedPtr<ejson::internal::Value> get(size_t _id) {
|
||||
return m_value[_id];
|
||||
};
|
||||
//! @previous
|
||||
const ememory::SharedPtr<const ejson::internal::Value> get(size_t _id) const{
|
||||
return m_value[_id];
|
||||
};
|
||||
//! @previous
|
||||
ememory::SharedPtr<ejson::internal::Value> operator[] (size_t _id) {
|
||||
return m_value[_id];
|
||||
}
|
||||
//! @previous
|
||||
const ememory::SharedPtr<const ejson::internal::Value> operator[] (size_t _id) const {
|
||||
return m_value[_id];
|
||||
}
|
||||
ememory::SharedPtr<ejson::internal::Value> get(size_t _id);
|
||||
/**
|
||||
* @brief get the pointer on an element reference with his ID.
|
||||
* @param[in] _id Id of the element.
|
||||
* @return nullptr if the element does not exist.
|
||||
*/
|
||||
const ememory::SharedPtr<const ejson::internal::Value> get(size_t _id) const;
|
||||
/**
|
||||
* @brief Get the element name (key).
|
||||
* @param[in] _id Id of the element.
|
||||
* @return The name (key).
|
||||
*/
|
||||
std::string getKey(size_t _id) const {
|
||||
return m_value.getKey(_id);
|
||||
}
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
ememory::SharedPtr<ejson::internal::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::internal::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
|
||||
*/
|
||||
ememory::SharedPtr<ejson::internal::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::internal::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
|
||||
*/
|
||||
ememory::SharedPtr<ejson::internal::Null> getNull(const std::string& _name);
|
||||
//! @previous
|
||||
const ememory::SharedPtr<const ejson::internal::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
|
||||
*/
|
||||
ememory::SharedPtr<ejson::internal::String> getString(const std::string& _name);
|
||||
//! @previous
|
||||
const ememory::SharedPtr<const ejson::internal::String> getString(const std::string& _name) const;
|
||||
/**
|
||||
* @brief get the sub string value of the requested element
|
||||
* @param[in] _name name of the object
|
||||
* @return Value of the string or an error string (empty)
|
||||
*/
|
||||
const std::string& getStringValue(const std::string& _name) const;
|
||||
/**
|
||||
* @brief get the sub string value of the requested element (with error return value)
|
||||
* @param[in] _name name of the object
|
||||
* @param[in] _errorValue The return value if the element does not exist.
|
||||
* @return Value of the string or an error string (empty)
|
||||
*/
|
||||
std::string getStringValue(const std::string& _name, const std::string& _errorValue) const;
|
||||
/**
|
||||
* @brief get the sub element with his name (Casted as Boolean 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
|
||||
*/
|
||||
ememory::SharedPtr<ejson::internal::Boolean> getBoolean(const std::string& _name);
|
||||
//! @previous
|
||||
const ememory::SharedPtr<const ejson::internal::Boolean> getBoolean(const std::string& _name) const;
|
||||
/**
|
||||
* @brief get the sub boolean value of the requested element.
|
||||
* @param[in] _name name of the object.
|
||||
* @param[in] _errorValue The return value if the element does not exist.
|
||||
* @return Value of the Boolean or the _errorValue;
|
||||
*/
|
||||
bool getBooleanValue(const std::string& _name, bool _errorValue=false) const;
|
||||
/**
|
||||
* @brief get the sub element with his name (Casted as Number 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
|
||||
*/
|
||||
ememory::SharedPtr<ejson::internal::Number> getNumber(const std::string& _name);
|
||||
//! @previous
|
||||
const ememory::SharedPtr<const ejson::internal::Number> getNumber(const std::string& _name) const;
|
||||
/**
|
||||
* @brief get the sub Number value of the requested element.
|
||||
* @param[in] _name name of the object.
|
||||
* @param[in] _errorValue The return value if the element does not exist.
|
||||
* @return Value of the Number or the _errorValue;
|
||||
*/
|
||||
double getNumberValue(const std::string& _name, double _errorValue=0.0) const;
|
||||
std::string getKey(size_t _id) const;
|
||||
public:
|
||||
/**
|
||||
* @brief add an element in the Object
|
||||
@ -189,40 +80,25 @@ namespace ejson {
|
||||
*/
|
||||
bool add(const std::string& _name, ememory::SharedPtr<ejson::internal::Value> _value);
|
||||
/**
|
||||
* @brief add a string element in the Object (automatic creation)
|
||||
* @param[in] _name name of the object
|
||||
* @param[in] _value string value to add
|
||||
* @return false if an error occured
|
||||
* @brief Remove Value with his name
|
||||
* @param[in] _name Name of the object
|
||||
*/
|
||||
bool addString(const std::string& _name, const std::string& _value);
|
||||
void remove(const std::string& _name);
|
||||
/**
|
||||
* @brief add a "null" element in the Object (automatic creation)
|
||||
* @param[in] _name name of the object
|
||||
* @return false if an error occured
|
||||
* @brief Remove Value with his id
|
||||
* @param[in] _id Id of the element.
|
||||
*/
|
||||
bool addNull(const std::string& _name);
|
||||
/**
|
||||
* @brief add a boolean element in the Object (automatic creation)
|
||||
* @param[in] _name name of the object
|
||||
* @param[in] _value boolean value to add
|
||||
* @return false if an error occured
|
||||
*/
|
||||
bool addBoolean(const std::string& _name, bool _value);
|
||||
/**
|
||||
* @brief add a double element in the Object (automatic creation)
|
||||
* @param[in] _name name of the object
|
||||
* @param[in] _value double value to add
|
||||
* @return false if an error occured
|
||||
*/
|
||||
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::internal::Document& _doc);
|
||||
virtual bool iGenerate(std::string& _data, size_t _indent) const;
|
||||
virtual void clear();
|
||||
virtual bool transfertIn(ememory::SharedPtr<ejson::internal::Value> _obj);
|
||||
virtual bool cloneIn(const ememory::SharedPtr<ejson::internal::Object>& _obj) const;
|
||||
virtual ememory::SharedPtr<ejson::internal::Value> clone() const;
|
||||
virtual ememory::SharedPtr<ejson::internal::Object> cloneObj() const;
|
||||
void remove(size_t _id);
|
||||
public:
|
||||
bool iParse(const std::string& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::internal::Document& _doc) override;
|
||||
bool iGenerate(std::string& _data, size_t _indent) const override;
|
||||
void clear() override;
|
||||
bool transfertIn(ememory::SharedPtr<ejson::internal::Value> _obj) override;
|
||||
ememory::SharedPtr<ejson::internal::Value> clone() const override;
|
||||
|
||||
|
||||
bool cloneIn(const ememory::SharedPtr<ejson::internal::Object>& _obj) const;
|
||||
ememory::SharedPtr<ejson::internal::Object> cloneObj() const;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,19 @@ ememory::SharedPtr<ejson::internal::String> ejson::internal::String::create(cons
|
||||
return ememory::SharedPtr<ejson::internal::String>(new ejson::internal::String(_value));
|
||||
}
|
||||
|
||||
ejson::internal::String::String(const std::string& _value) :
|
||||
m_value(_value) {
|
||||
m_type = ejson::valueType::string;
|
||||
}
|
||||
|
||||
void ejson::internal::String::set(const std::string& _value) {
|
||||
m_value = _value;
|
||||
}
|
||||
|
||||
const std::string& ejson::internal::String::get() const {
|
||||
return m_value;
|
||||
}
|
||||
|
||||
bool ejson::internal::String::iParse(const std::string& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::internal::Document& _doc) {
|
||||
EJSON_PARSE_ELEMENT("start parse : 'String' ");
|
||||
char end = _data[_pos];
|
||||
@ -53,11 +66,11 @@ bool ejson::internal::String::transfertIn(ememory::SharedPtr<ejson::internal::Va
|
||||
EJSON_ERROR("Request transfer on an nullptr pointer");
|
||||
return false;
|
||||
}
|
||||
ememory::SharedPtr<ejson::internal::String> other = _obj->toString();
|
||||
if (other == nullptr) {
|
||||
if (_obj->getType() != ejson::valueType::string) {
|
||||
EJSON_ERROR("Request transfer on an element that is not an String");
|
||||
return false;
|
||||
}
|
||||
ememory::SharedPtr<ejson::internal::String> other = std::static_pointer_cast<ejson::internal::String>(_obj);
|
||||
other->m_value = m_value;
|
||||
m_value = "";
|
||||
return true;
|
||||
|
@ -17,16 +17,9 @@ namespace ejson {
|
||||
/**
|
||||
* @brief basic element of a xml structure
|
||||
*/
|
||||
String(const std::string& _value="") :
|
||||
m_value(_value) {
|
||||
m_type = ejson::valueType::string;
|
||||
};
|
||||
String(const std::string& _value="");
|
||||
public:
|
||||
static ememory::SharedPtr<String> create(const std::string& _value="");
|
||||
/**
|
||||
* @brief destructor
|
||||
*/
|
||||
virtual ~String() { };
|
||||
protected:
|
||||
std::string m_value; //!< value of the node (for element this is the name, for text it is the inside text ...)
|
||||
public:
|
||||
@ -34,21 +27,17 @@ namespace ejson {
|
||||
* @brief set the 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);
|
||||
/**
|
||||
* @brief get the current element Value.
|
||||
* @return the reference of the string value.
|
||||
*/
|
||||
const std::string& get() const {
|
||||
return m_value;
|
||||
};
|
||||
public: // herited function :
|
||||
virtual bool iParse(const std::string& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::internal::Document& _doc);
|
||||
virtual bool iGenerate(std::string& _data, size_t _indent) const;
|
||||
virtual bool transfertIn(ememory::SharedPtr<ejson::internal::Value> _obj);
|
||||
virtual ememory::SharedPtr<ejson::internal::Value> clone() const;
|
||||
const std::string& get() const;
|
||||
public:
|
||||
virtual bool iParse(const std::string& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::internal::Document& _doc) override;
|
||||
virtual bool iGenerate(std::string& _data, size_t _indent) const override;
|
||||
virtual bool transfertIn(ememory::SharedPtr<ejson::internal::Value> _obj) override;
|
||||
virtual ememory::SharedPtr<ejson::internal::Value> clone() const override;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -111,91 +111,12 @@ bool ejson::internal::Value::checkNumber(char32_t _val) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
ememory::SharedPtr<ejson::internal::Value> ejson::internal::Value::toValue() {
|
||||
return shared_from_this();
|
||||
};
|
||||
const ememory::SharedPtr<const ejson::internal::Value> ejson::internal::Value::toValue() const {
|
||||
return shared_from_this();
|
||||
};
|
||||
ememory::SharedPtr<ejson::internal::Document> ejson::internal::Value::toDocument() {
|
||||
return std::dynamic_pointer_cast<ejson::internal::Document>(shared_from_this());
|
||||
};
|
||||
const ememory::SharedPtr<const ejson::internal::Document> ejson::internal::Value::toDocument() const {
|
||||
return std::dynamic_pointer_cast<const ejson::internal::Document>(shared_from_this());
|
||||
};
|
||||
ememory::SharedPtr<ejson::internal::Array> ejson::internal::Value::toArray() {
|
||||
return std::dynamic_pointer_cast<ejson::internal::Array>(shared_from_this());
|
||||
};
|
||||
const ememory::SharedPtr<const ejson::internal::Array> ejson::internal::Value::toArray() const{
|
||||
return std::dynamic_pointer_cast<const ejson::internal::Array>(shared_from_this());
|
||||
};
|
||||
ememory::SharedPtr<ejson::internal::Object> ejson::internal::Value::toObject() {
|
||||
return std::dynamic_pointer_cast<ejson::internal::Object>(shared_from_this());
|
||||
};
|
||||
const ememory::SharedPtr<const ejson::internal::Object> ejson::internal::Value::toObject() const{
|
||||
return std::dynamic_pointer_cast<const ejson::internal::Object>(shared_from_this());
|
||||
};
|
||||
ememory::SharedPtr<ejson::internal::String> ejson::internal::Value::toString() {
|
||||
return std::dynamic_pointer_cast<ejson::internal::String>(shared_from_this());
|
||||
};
|
||||
const ememory::SharedPtr<const ejson::internal::String> ejson::internal::Value::toString() const{
|
||||
return std::dynamic_pointer_cast<const ejson::internal::String>(shared_from_this());
|
||||
};
|
||||
ememory::SharedPtr<ejson::internal::Number> ejson::internal::Value::toNumber() {
|
||||
return std::dynamic_pointer_cast<ejson::internal::Number>(shared_from_this());
|
||||
};
|
||||
const ememory::SharedPtr<const ejson::internal::Number> ejson::internal::Value::toNumber() const{
|
||||
return std::dynamic_pointer_cast<const ejson::internal::Number>(shared_from_this());
|
||||
};
|
||||
ememory::SharedPtr<ejson::internal::Boolean> ejson::internal::Value::toBoolean() {
|
||||
return std::dynamic_pointer_cast<ejson::internal::Boolean>(shared_from_this());
|
||||
};
|
||||
const ememory::SharedPtr<const ejson::internal::Boolean> ejson::internal::Value::toBoolean() const{
|
||||
return std::dynamic_pointer_cast<const ejson::internal::Boolean>(shared_from_this());
|
||||
};
|
||||
ememory::SharedPtr<ejson::internal::Null> ejson::internal::Value::toNull() {
|
||||
return std::dynamic_pointer_cast<ejson::internal::Null>(shared_from_this());
|
||||
};
|
||||
const ememory::SharedPtr<const ejson::internal::Null> ejson::internal::Value::toNull() const{
|
||||
return std::dynamic_pointer_cast<const ejson::internal::Null>(shared_from_this());
|
||||
};
|
||||
|
||||
void ejson::internal::Value::display() const {
|
||||
std::string tmpp;
|
||||
iGenerate(tmpp, 0);
|
||||
EJSON_INFO("Generated JSON : \n" << tmpp);
|
||||
}
|
||||
|
||||
|
||||
bool ejson::internal::Value::isDocument() const {
|
||||
return toDocument() != nullptr;
|
||||
}
|
||||
|
||||
bool ejson::internal::Value::isArray() const {
|
||||
return toArray() != nullptr;
|
||||
}
|
||||
|
||||
bool ejson::internal::Value::isObject() const {
|
||||
return toObject() != nullptr;
|
||||
}
|
||||
|
||||
bool ejson::internal::Value::isString() const {
|
||||
return toString() != nullptr;
|
||||
}
|
||||
|
||||
bool ejson::internal::Value::isNumber() const {
|
||||
return toNumber() != nullptr;
|
||||
}
|
||||
|
||||
bool ejson::internal::Value::isBoolean() const {
|
||||
return toBoolean() != nullptr;
|
||||
}
|
||||
|
||||
bool ejson::internal::Value::isNull() const {
|
||||
return toNull() != nullptr;
|
||||
}
|
||||
|
||||
|
||||
void ejson::internal::Value::clear() {
|
||||
|
||||
}
|
||||
|
@ -64,18 +64,22 @@ namespace ejson {
|
||||
* @brief parse the Current node [pure VIRUAL]
|
||||
* @param[in] _data data string to parse.
|
||||
* @param[in,out] _pos position in the string to start parse, return the position end of parsing.
|
||||
* @param[in] _caseSensitive Request a parsion of element that is not case sensitive (all element is in low case)
|
||||
* @param[in,out] file parsing position (line x col x)
|
||||
* @param[in,out] _filePos Position in the file (in X/Y)
|
||||
* @param[in,out] _doc Reference on the main document
|
||||
* @return false if an error occured.
|
||||
*/
|
||||
virtual bool iParse(const std::string& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::internal::Document& _doc) = 0;
|
||||
virtual bool iParse(const std::string& _data,
|
||||
size_t& _pos,
|
||||
ejson::FilePos& _filePos,
|
||||
ejson::internal::Document& _doc) = 0;
|
||||
/**
|
||||
* @brief generate a string with the tree of the xml
|
||||
* @param[in,out] _data string where to add the elements
|
||||
* @param[in] current indentation of the file
|
||||
* @param[in] _indent current indentation of the file
|
||||
* @return false if an error occured.
|
||||
*/
|
||||
virtual bool iGenerate(std::string& _data, size_t _indent) const = 0;
|
||||
virtual bool iGenerate(std::string& _data,
|
||||
size_t _indent) const = 0;
|
||||
/**
|
||||
* @brief Display the Document on console
|
||||
*/
|
||||
@ -94,13 +98,17 @@ namespace ejson {
|
||||
*/
|
||||
void drawElementParsed(char32_t _val, const ejson::FilePos& _filePos) const;
|
||||
/**
|
||||
* @brief check if an name (for object named) (not : !"#$%&'()*+,/;<=>?@[\]^`{|}~ \n\t\r).
|
||||
* @brief check if an name (for object named) (not : !"#$%&'()*+,/;<=>?@[\]^`{|}~ \\n\\t\\r).
|
||||
* @param[in] _val Value to check the conformity.
|
||||
* @return true The element char is considerable as a string
|
||||
* @return false The element char is NOT considerable as a string
|
||||
*/
|
||||
bool checkString(char32_t _val) const;
|
||||
/**
|
||||
* @brief check if an number -+.0123456789e).
|
||||
* @param[in] _val Value to check the conformity.
|
||||
* @return true The element char is considerable as a number
|
||||
* @return false The element char is NOT considerable as a number
|
||||
*/
|
||||
bool checkNumber(char32_t _val) const;
|
||||
/**
|
||||
@ -112,123 +120,6 @@ namespace ejson {
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
ememory::SharedPtr<ejson::internal::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::internal::Value> toValue() const;
|
||||
/**
|
||||
* @brief Cast the element in a Document if it is possible.
|
||||
* @return pointer on the class or nullptr.
|
||||
*/
|
||||
ememory::SharedPtr<ejson::internal::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::internal::Document> toDocument() const;
|
||||
/**
|
||||
* @brief Cast the element in a Array if it is possible.
|
||||
* @return pointer on the class or nullptr.
|
||||
*/
|
||||
ememory::SharedPtr<ejson::internal::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::internal::Array> toArray() const;
|
||||
/**
|
||||
* @brief Cast the element in a Object if it is possible.
|
||||
* @return pointer on the class or nullptr.
|
||||
*/
|
||||
ememory::SharedPtr<ejson::internal::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::internal::Object> toObject() const;
|
||||
/**
|
||||
* @brief Cast the element in a String if it is possible.
|
||||
* @return pointer on the class or nullptr.
|
||||
*/
|
||||
ememory::SharedPtr<ejson::internal::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::internal::String> toString() const;
|
||||
/**
|
||||
* @brief Cast the element in a Number if it is possible.
|
||||
* @return pointer on the class or nullptr.
|
||||
*/
|
||||
ememory::SharedPtr<ejson::internal::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::internal::Number> toNumber() const;
|
||||
/**
|
||||
* @brief Cast the element in a Boolean if it is possible.
|
||||
* @return pointer on the class or nullptr.
|
||||
*/
|
||||
ememory::SharedPtr<ejson::internal::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::internal::Boolean> toBoolean() const;
|
||||
/**
|
||||
* @brief Cast the element in a Null if it is possible.
|
||||
* @return pointer on the class or nullptr.
|
||||
*/
|
||||
ememory::SharedPtr<ejson::internal::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::internal::Null> toNull() const;
|
||||
|
||||
/**
|
||||
* @brief check if the node is a ejson::internal::Document
|
||||
* @return true if the node is a ejson::internal::Document
|
||||
*/
|
||||
bool isDocument() const;
|
||||
/**
|
||||
* @brief check if the node is a ejson::internal::Array
|
||||
* @return true if the node is a ejson::internal::Array
|
||||
*/
|
||||
bool isArray() const;
|
||||
/**
|
||||
* @brief check if the node is a ejson::internal::Object
|
||||
* @return true if the node is a ejson::internal::Object
|
||||
*/
|
||||
bool isObject() const;
|
||||
/**
|
||||
* @brief check if the node is a ejson::internal::String
|
||||
* @return true if the node is a ejson::internal::String
|
||||
*/
|
||||
bool isString() const;
|
||||
/**
|
||||
* @brief check if the node is a ejson::internal::Number
|
||||
* @return true if the node is a ejson::internal::Number
|
||||
*/
|
||||
bool isNumber() const;
|
||||
/**
|
||||
* @brief check if the node is a ejson::internal::Boolean
|
||||
* @return true if the node is a ejson::internal::Boolean
|
||||
*/
|
||||
bool isBoolean() const;
|
||||
/**
|
||||
* @brief check if the node is a ejson::internal::Null
|
||||
* @return true if the node is a ejson::internal::Null
|
||||
*/
|
||||
bool isNull() const;
|
||||
|
||||
/**
|
||||
* @brief clear the Node
|
||||
*/
|
||||
@ -248,6 +139,7 @@ namespace ejson {
|
||||
protected:
|
||||
/**
|
||||
* @brief check if the current element is white or not : '\\t' '\\n' '\\r' ' '
|
||||
* @param[in] _val Char value to check
|
||||
* @return tue if it is white char
|
||||
*/
|
||||
static bool isWhiteChar(char32_t _val);
|
||||
|
@ -20,12 +20,26 @@ namespace ejson {
|
||||
EJSON_BASE_T& m_data; //!< Reference on the ejson::Element
|
||||
size_t m_id; //!< Id of the element that we are parsing
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor of the generic object class
|
||||
* @param[in] _obj Reference on the object to go threw
|
||||
* @param[in] _pos Position in the object
|
||||
*/
|
||||
iterator(EJSON_BASE_T& _obj, size_t _pos);
|
||||
/**
|
||||
* @brief Const constructor of the generic const object class
|
||||
* @param[in] _obj Reference on the object to go threw
|
||||
* @param[in] _pos Position in the object
|
||||
*/
|
||||
iterator(const EJSON_BASE_T& _obj, size_t _pos);
|
||||
/**
|
||||
* @brief Copy iterator
|
||||
* @param[in] _obj Iterator to copy
|
||||
*/
|
||||
iterator(const iterator& _obj);
|
||||
/**
|
||||
* @brief Operator+= Addition value
|
||||
* @param[in] _val Value to addition
|
||||
* @param[in] _obj Value to addition
|
||||
* @return Local reference of the iterator additionned
|
||||
*/
|
||||
iterator& operator= (const iterator& _obj);
|
||||
@ -97,6 +111,11 @@ namespace ejson {
|
||||
* @return Const reference on the value.
|
||||
*/
|
||||
ejson::Value operator *() noexcept;
|
||||
/**
|
||||
* @brief Get ID of an element
|
||||
* @return Position in the Element
|
||||
*/
|
||||
size_t getId() const noexcept;
|
||||
/**
|
||||
* @brief Get Key of an element
|
||||
* @return Key of the Element
|
||||
|
@ -89,12 +89,12 @@ static void writeAll() {
|
||||
|
||||
// remove the object named "F"
|
||||
//! [ejson_sample_write_rm_object]
|
||||
//doc.remove("F");
|
||||
doc.remove("F");
|
||||
//! [ejson_sample_write_rm_object]
|
||||
|
||||
// Remove element 2 in the array
|
||||
//! [ejson_sample_write_rm_array]
|
||||
//array.remove(2);
|
||||
array.remove(2);
|
||||
//! [ejson_sample_write_rm_array]
|
||||
doc.display();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user