[DEV] Remove helper function that just create noise on the API
This commit is contained in:
parent
c5b8bbd56c
commit
22b869e2d0
21
doc/read.md
21
doc/read.md
@ -48,33 +48,18 @@ Access to a string in an Object:
|
||||
The generic Way to access to an element is to convert it in the corect type:
|
||||
@snippet read.cpp ejson_sample_read_convert_string
|
||||
|
||||
And after Get the Value:
|
||||
@snippet read.cpp ejson_sample_read_get_string_value
|
||||
|
||||
Commonly you might use like this:
|
||||
@snippet read.cpp ejson_sample_read_get_string_1
|
||||
|
||||
Helper function:
|
||||
@snippet read.cpp ejson_sample_read_get_string_2
|
||||
|
||||
|
||||
@snippet read.cpp ejson_sample_read_get_string
|
||||
|
||||
Access to a boolean in an Object:
|
||||
---------------------------------
|
||||
|
||||
@snippet read.cpp ejson_sample_read_get_boolean_1
|
||||
|
||||
Helper function:
|
||||
@snippet read.cpp ejson_sample_read_get_boolean_2
|
||||
|
||||
@snippet read.cpp ejson_sample_read_get_boolean
|
||||
|
||||
Access to a Number in an Object:
|
||||
---------------------------------
|
||||
|
||||
@snippet read.cpp ejson_sample_read_get_number_1
|
||||
|
||||
Helper function:
|
||||
@snippet read.cpp ejson_sample_read_get_number_2
|
||||
@snippet read.cpp ejson_sample_read_get_number
|
||||
|
||||
|
||||
Access to a Array in an Object:
|
||||
|
12
doc/write.md
12
doc/write.md
@ -29,20 +29,16 @@ Operation on Tree {#ejson_tutorial_write_operat
|
||||
=================
|
||||
|
||||
Add String:
|
||||
@snippet write.cpp ejson_sample_write_add_string_1
|
||||
@snippet write.cpp ejson_sample_write_add_string_2
|
||||
@snippet write.cpp ejson_sample_write_add_string
|
||||
|
||||
Add Null:
|
||||
@snippet write.cpp ejson_sample_write_add_null_1
|
||||
@snippet write.cpp ejson_sample_write_add_null_2
|
||||
@snippet write.cpp ejson_sample_write_add_null
|
||||
|
||||
Add Number:
|
||||
@snippet write.cpp ejson_sample_write_add_number_1
|
||||
@snippet write.cpp ejson_sample_write_add_number_2
|
||||
@snippet write.cpp ejson_sample_write_add_number
|
||||
|
||||
Add Boolean:
|
||||
@snippet write.cpp ejson_sample_write_add_boolean_1
|
||||
@snippet write.cpp ejson_sample_write_add_boolean_1
|
||||
@snippet write.cpp ejson_sample_write_add_boolean
|
||||
|
||||
Add Array with values:
|
||||
@snippet write.cpp ejson_sample_write_add_array
|
||||
|
@ -63,18 +63,6 @@ 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, const std::string& _errorValue) const {
|
||||
return (*this)[_id].toString().get(_errorValue);
|
||||
}
|
||||
|
||||
double ejson::Array::getNumberValue(size_t _id, double _errorValue) const {
|
||||
return (*this)[_id].toNumber().get(_errorValue);
|
||||
}
|
||||
|
||||
bool ejson::Array::getBooleanValue(size_t _id, bool _errorValue) const {
|
||||
return (*this)[_id].toBoolean().get(_errorValue);
|
||||
}
|
||||
|
||||
bool ejson::Array::add(const ejson::Value& _element) {
|
||||
if (m_data == nullptr) {
|
||||
EJSON_ERROR("Can not add (nullptr) ...");
|
||||
@ -101,23 +89,6 @@ ejson::Array::iterator ejson::Array::remove(const ejson::Array::iterator& _it) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool ejson::Array::addString(const std::string& _value) {
|
||||
return add(ejson::String(_value));
|
||||
}
|
||||
|
||||
bool ejson::Array::addNull() {
|
||||
return add(ejson::Null());
|
||||
}
|
||||
|
||||
bool ejson::Array::addBoolean(bool _value) {
|
||||
return add(ejson::Boolean(_value));
|
||||
}
|
||||
|
||||
bool ejson::Array::addNumber(double _value) {
|
||||
return add(ejson::Number(_value));
|
||||
}
|
||||
|
||||
ejson::Array::iterator ejson::Array::begin() {
|
||||
return ejson::Array::iterator(*this, 0);
|
||||
}
|
||||
|
@ -55,56 +55,12 @@ namespace ejson {
|
||||
* @return nullptr if the element does not exist.
|
||||
*/
|
||||
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;
|
||||
/**
|
||||
* @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=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=false) const;
|
||||
/**
|
||||
* @brief add an element on the array.
|
||||
* @param[in] _element element to add.
|
||||
* @return false if an error occured.
|
||||
*/
|
||||
bool add(const ejson::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
|
||||
*/
|
||||
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);
|
||||
/**
|
||||
* @brief Remove Value with his Id
|
||||
* @param[in] _id Id of the element.
|
||||
|
@ -106,18 +106,6 @@ std::string ejson::Object::getKey(size_t _id) const {
|
||||
return static_cast<ejson::internal::Object*>(m_data.get())->getKey(_id);
|
||||
}
|
||||
|
||||
std::string ejson::Object::getStringValue(const std::string& _name, const std::string& _errorValue) const {
|
||||
return (*this)[_name].toString().get(_errorValue);
|
||||
}
|
||||
|
||||
bool ejson::Object::getBooleanValue(const std::string& _name, bool _errorValue) const {
|
||||
return (*this)[_name].toBoolean().get(_errorValue);
|
||||
}
|
||||
|
||||
double ejson::Object::getNumberValue(const std::string& _name, double _errorValue) const {
|
||||
return (*this)[_name].toNumber().get(_errorValue);
|
||||
}
|
||||
|
||||
bool ejson::Object::add(const std::string& _name, const ejson::Value& _value) {
|
||||
if (m_data == nullptr) {
|
||||
EJSON_ERROR("Can not add (nullptr) ...");
|
||||
@ -126,22 +114,6 @@ bool ejson::Object::add(const std::string& _name, const ejson::Value& _value) {
|
||||
return static_cast<ejson::internal::Object*>(m_data.get())->add(_name, _value.m_data);
|
||||
}
|
||||
|
||||
bool ejson::Object::addString(const std::string& _name, const std::string& _value) {
|
||||
return add(_name, ejson::String(_value));
|
||||
}
|
||||
|
||||
bool ejson::Object::addNull(const std::string& _name) {
|
||||
return add(_name, ejson::Null());
|
||||
}
|
||||
|
||||
bool ejson::Object::addBoolean(const std::string& _name, bool _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 remove (nullptr) ...");
|
||||
|
@ -93,27 +93,6 @@ namespace ejson {
|
||||
* @return The name (key).
|
||||
*/
|
||||
std::string getKey(size_t _id) 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 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 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;
|
||||
public:
|
||||
/**
|
||||
* @brief add an element in the Object
|
||||
@ -122,33 +101,6 @@ namespace ejson {
|
||||
* @return false if an error occured
|
||||
*/
|
||||
bool add(const std::string& _name, const ejson::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
|
||||
*/
|
||||
bool addString(const std::string& _name, const std::string& _value);
|
||||
/**
|
||||
* @brief add a "null" element in the Object (automatic creation)
|
||||
* @param[in] _name name of the object
|
||||
* @return false if an error occured
|
||||
*/
|
||||
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);
|
||||
/**
|
||||
* @brief Remove Value with his name
|
||||
* @param[in] _name Name of the object
|
||||
|
@ -159,7 +159,9 @@ static void readFull() {
|
||||
ejson::Value element = doc["object C"];
|
||||
//! [ejson_sample_read_get_element]
|
||||
//! [ejson_sample_read_check_element]
|
||||
|
||||
if (element.exist() == false) {
|
||||
TEST_ERROR("The element does not exist");
|
||||
}
|
||||
//! [ejson_sample_read_check_element]
|
||||
|
||||
TEST_INFO("Read String:");
|
||||
@ -167,27 +169,17 @@ static void readFull() {
|
||||
// you can simply change the type of the exml value if you know what it is:
|
||||
//! [ejson_sample_read_convert_string]
|
||||
ejson::String elem = doc["object A"].toString();
|
||||
//! [ejson_sample_read_convert_string]
|
||||
// Get the value:
|
||||
//! [ejson_sample_read_get_string_value]
|
||||
std::string value = elem.get();
|
||||
//! [ejson_sample_read_get_string_value]
|
||||
//! [ejson_sample_read_convert_string]
|
||||
TEST_INFO(" String Value:" << value);
|
||||
}
|
||||
// or simply:
|
||||
{
|
||||
// Get the value:
|
||||
//! [ejson_sample_read_get_string_1]
|
||||
//! [ejson_sample_read_get_string]
|
||||
std::string value = doc["object A"].toString().get();
|
||||
//! [ejson_sample_read_get_string_1]
|
||||
TEST_INFO(" String Value:" << value);
|
||||
}
|
||||
// helper function:
|
||||
{
|
||||
// Get the value:
|
||||
//! [ejson_sample_read_get_string_2]
|
||||
std::string value = doc.getStringValue("object A");
|
||||
//! [ejson_sample_read_get_string_2]
|
||||
//! [ejson_sample_read_get_string]
|
||||
TEST_INFO(" String Value:" << value);
|
||||
}
|
||||
|
||||
@ -196,17 +188,9 @@ static void readFull() {
|
||||
// Get a Boolean value:
|
||||
{
|
||||
// Get the value:
|
||||
//! [ejson_sample_read_get_boolean_1]
|
||||
//! [ejson_sample_read_get_boolean]
|
||||
bool value = doc["object C"].toBoolean().get();
|
||||
//! [ejson_sample_read_get_boolean_1]
|
||||
TEST_INFO(" Boolean Value:" << value);
|
||||
}
|
||||
// helper function:
|
||||
{
|
||||
// Get the value:
|
||||
//! [ejson_sample_read_get_boolean_2]
|
||||
bool value = doc.getBooleanValue("object C");
|
||||
//! [ejson_sample_read_get_boolean_2]
|
||||
//! [ejson_sample_read_get_boolean]
|
||||
TEST_INFO(" Boolean Value:" << value);
|
||||
}
|
||||
|
||||
@ -215,17 +199,9 @@ static void readFull() {
|
||||
// Get a number value:
|
||||
{
|
||||
// Get the value:
|
||||
//! [ejson_sample_read_get_number_1]
|
||||
//! [ejson_sample_read_get_number]
|
||||
double value = doc["object D"].toNumber().get();
|
||||
//! [ejson_sample_read_get_number_1]
|
||||
TEST_INFO(" Number Value:" << value);
|
||||
}
|
||||
// helper function:
|
||||
{
|
||||
// Get the value:
|
||||
//! [ejson_sample_read_get_number_2]
|
||||
double value = doc.getNumberValue("object D");
|
||||
//! [ejson_sample_read_get_number_2]
|
||||
//! [ejson_sample_read_get_number]
|
||||
TEST_INFO(" Number Value:" << value);
|
||||
}
|
||||
|
||||
|
@ -43,33 +43,21 @@ static void writeToString() {
|
||||
static void writeAll() {
|
||||
ejson::Document doc;
|
||||
|
||||
//! [ejson_sample_write_add_string_1]
|
||||
//! [ejson_sample_write_add_string]
|
||||
doc.add("A", ejson::String("2.5"));
|
||||
//! [ejson_sample_write_add_string_1]
|
||||
//! [ejson_sample_write_add_string_2]
|
||||
doc.addString("Aa", "lkjlkjlkj");
|
||||
//! [ejson_sample_write_add_string_2]
|
||||
//! [ejson_sample_write_add_string]
|
||||
|
||||
//! [ejson_sample_write_add_null_1]
|
||||
//! [ejson_sample_write_add_null]
|
||||
doc.add("B", ejson::Null());
|
||||
//! [ejson_sample_write_add_null_1]
|
||||
//! [ejson_sample_write_add_null_2]
|
||||
doc.addNull("Bb");
|
||||
//! [ejson_sample_write_add_null_2]
|
||||
//! [ejson_sample_write_add_null]
|
||||
|
||||
//! [ejson_sample_write_add_number_1]
|
||||
//! [ejson_sample_write_add_number]
|
||||
doc.add("C", ejson::Number(2010));
|
||||
//! [ejson_sample_write_add_number_1]
|
||||
//! [ejson_sample_write_add_number_2]
|
||||
doc.addNumber("Cc", 5161.2);
|
||||
//! [ejson_sample_write_add_number_2]
|
||||
//! [ejson_sample_write_add_number]
|
||||
|
||||
//! [ejson_sample_write_add_boolean_1]
|
||||
//! [ejson_sample_write_add_boolean]
|
||||
doc.add("D", ejson::Boolean(false));
|
||||
//! [ejson_sample_write_add_boolean_1]
|
||||
//! [ejson_sample_write_add_boolean_2]
|
||||
doc.addBoolean("Dd", true);
|
||||
//! [ejson_sample_write_add_boolean_2]
|
||||
//! [ejson_sample_write_add_boolean]
|
||||
|
||||
//! [ejson_sample_write_add_array]
|
||||
ejson::Array array;
|
||||
|
Loading…
x
Reference in New Issue
Block a user