Compare commits

...

19 Commits

Author SHA1 Message Date
cce332f060 [RELEASE] Release v1.0.0 2021-02-16 21:42:58 +01:00
9598490012 [DEBUG] update new API of lutin log 2019-05-03 10:18:22 +02:00
871da9506a [DEV] update new etk Uri API 2018-10-23 22:19:31 +02:00
7fe6b15b23 [SAMPLE] update new URI 2018-10-09 23:03:07 +02:00
f327765a04 [DEV] integrate the new interface of URI and file 2018-09-24 23:26:06 +02:00
f7a78efba4 [DEV] update new insterface IO of etk 2018-09-17 21:33:07 +02:00
6af072cdfe [DEV] update etk null 2018-06-19 22:13:47 +02:00
8e12c92ba0 [DEV] update nullptr in null (specific etk) 2018-06-19 22:15:52 +02:00
ec7f6cc1f1 [DEBUG] correct buid of tutorial 2017-11-07 10:16:10 +01:00
627cc3ab7b [DEV] update to the new ETK allocator wrapper 2017-10-21 19:05:21 +02:00
f2f692c128 [DEBUG] correct [] acces on Object 2017-09-26 15:46:29 +02:00
9f5b164097 [DEBUG] continue removing STL 2017-09-17 15:23:44 +02:00
b91410fef3 [DEBUG] update to the new interface etk 2017-09-12 14:11:21 +02:00
830d651907 [DEV] remove STL 2017-09-07 23:38:26 +02:00
626c4327e1 [DEV] continue removing STL 2017-08-29 01:23:23 +02:00
3006c24262 [DEV] continue removing stl 2017-08-28 00:03:43 +02:00
132d1a4921 Change licence APACHE-2 to MPL-2 ==> force source redistribution and permit static link 2017-01-05 21:28:23 +01:00
6ed77119d4 [DOC] Add sample of safe store 2017-01-04 22:22:25 +01:00
389f1788a9 [DEV] update dev tag version 2016-10-24 22:25:37 +02:00
64 changed files with 1083 additions and 689 deletions

373
LICENSE Normal file
View File

@ -0,0 +1,373 @@
Mozilla Public License Version 2.0
==================================
1. Definitions
--------------
1.1. "Contributor"
means each individual or legal entity that creates, contributes to
the creation of, or owns Covered Software.
1.2. "Contributor Version"
means the combination of the Contributions of others (if any) used
by a Contributor and that particular Contributor's Contribution.
1.3. "Contribution"
means Covered Software of a particular Contributor.
1.4. "Covered Software"
means Source Code Form to which the initial Contributor has attached
the notice in Exhibit A, the Executable Form of such Source Code
Form, and Modifications of such Source Code Form, in each case
including portions thereof.
1.5. "Incompatible With Secondary Licenses"
means
(a) that the initial Contributor has attached the notice described
in Exhibit B to the Covered Software; or
(b) that the Covered Software was made available under the terms of
version 1.1 or earlier of the License, but not also under the
terms of a Secondary License.
1.6. "Executable Form"
means any form of the work other than Source Code Form.
1.7. "Larger Work"
means a work that combines Covered Software with other material, in
a separate file or files, that is not Covered Software.
1.8. "License"
means this document.
1.9. "Licensable"
means having the right to grant, to the maximum extent possible,
whether at the time of the initial grant or subsequently, any and
all of the rights conveyed by this License.
1.10. "Modifications"
means any of the following:
(a) any file in Source Code Form that results from an addition to,
deletion from, or modification of the contents of Covered
Software; or
(b) any new file in Source Code Form that contains any Covered
Software.
1.11. "Patent Claims" of a Contributor
means any patent claim(s), including without limitation, method,
process, and apparatus claims, in any patent Licensable by such
Contributor that would be infringed, but for the grant of the
License, by the making, using, selling, offering for sale, having
made, import, or transfer of either its Contributions or its
Contributor Version.
1.12. "Secondary License"
means either the GNU General Public License, Version 2.0, the GNU
Lesser General Public License, Version 2.1, the GNU Affero General
Public License, Version 3.0, or any later versions of those
licenses.
1.13. "Source Code Form"
means the form of the work preferred for making modifications.
1.14. "You" (or "Your")
means an individual or a legal entity exercising rights under this
License. For legal entities, "You" includes any entity that
controls, is controlled by, or is under common control with You. For
purposes of this definition, "control" means (a) the power, direct
or indirect, to cause the direction or management of such entity,
whether by contract or otherwise, or (b) ownership of more than
fifty percent (50%) of the outstanding shares or beneficial
ownership of such entity.
2. License Grants and Conditions
--------------------------------
2.1. Grants
Each Contributor hereby grants You a world-wide, royalty-free,
non-exclusive license:
(a) under intellectual property rights (other than patent or trademark)
Licensable by such Contributor to use, reproduce, make available,
modify, display, perform, distribute, and otherwise exploit its
Contributions, either on an unmodified basis, with Modifications, or
as part of a Larger Work; and
(b) under Patent Claims of such Contributor to make, use, sell, offer
for sale, have made, import, and otherwise transfer either its
Contributions or its Contributor Version.
2.2. Effective Date
The licenses granted in Section 2.1 with respect to any Contribution
become effective for each Contribution on the date the Contributor first
distributes such Contribution.
2.3. Limitations on Grant Scope
The licenses granted in this Section 2 are the only rights granted under
this License. No additional rights or licenses will be implied from the
distribution or licensing of Covered Software under this License.
Notwithstanding Section 2.1(b) above, no patent license is granted by a
Contributor:
(a) for any code that a Contributor has removed from Covered Software;
or
(b) for infringements caused by: (i) Your and any other third party's
modifications of Covered Software, or (ii) the combination of its
Contributions with other software (except as part of its Contributor
Version); or
(c) under Patent Claims infringed by Covered Software in the absence of
its Contributions.
This License does not grant any rights in the trademarks, service marks,
or logos of any Contributor (except as may be necessary to comply with
the notice requirements in Section 3.4).
2.4. Subsequent Licenses
No Contributor makes additional grants as a result of Your choice to
distribute the Covered Software under a subsequent version of this
License (see Section 10.2) or under the terms of a Secondary License (if
permitted under the terms of Section 3.3).
2.5. Representation
Each Contributor represents that the Contributor believes its
Contributions are its original creation(s) or it has sufficient rights
to grant the rights to its Contributions conveyed by this License.
2.6. Fair Use
This License is not intended to limit any rights You have under
applicable copyright doctrines of fair use, fair dealing, or other
equivalents.
2.7. Conditions
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
in Section 2.1.
3. Responsibilities
-------------------
3.1. Distribution of Source Form
All distribution of Covered Software in Source Code Form, including any
Modifications that You create or to which You contribute, must be under
the terms of this License. You must inform recipients that the Source
Code Form of the Covered Software is governed by the terms of this
License, and how they can obtain a copy of this License. You may not
attempt to alter or restrict the recipients' rights in the Source Code
Form.
3.2. Distribution of Executable Form
If You distribute Covered Software in Executable Form then:
(a) such Covered Software must also be made available in Source Code
Form, as described in Section 3.1, and You must inform recipients of
the Executable Form how they can obtain a copy of such Source Code
Form by reasonable means in a timely manner, at a charge no more
than the cost of distribution to the recipient; and
(b) You may distribute such Executable Form under the terms of this
License, or sublicense it under different terms, provided that the
license for the Executable Form does not attempt to limit or alter
the recipients' rights in the Source Code Form under this License.
3.3. Distribution of a Larger Work
You may create and distribute a Larger Work under terms of Your choice,
provided that You also comply with the requirements of this License for
the Covered Software. If the Larger Work is a combination of Covered
Software with a work governed by one or more Secondary Licenses, and the
Covered Software is not Incompatible With Secondary Licenses, this
License permits You to additionally distribute such Covered Software
under the terms of such Secondary License(s), so that the recipient of
the Larger Work may, at their option, further distribute the Covered
Software under the terms of either this License or such Secondary
License(s).
3.4. Notices
You may not remove or alter the substance of any license notices
(including copyright notices, patent notices, disclaimers of warranty,
or limitations of liability) contained within the Source Code Form of
the Covered Software, except that You may alter any license notices to
the extent required to remedy known factual inaccuracies.
3.5. Application of Additional Terms
You may choose to offer, and to charge a fee for, warranty, support,
indemnity or liability obligations to one or more recipients of Covered
Software. However, You may do so only on Your own behalf, and not on
behalf of any Contributor. You must make it absolutely clear that any
such warranty, support, indemnity, or liability obligation is offered by
You alone, and You hereby agree to indemnify every Contributor for any
liability incurred by such Contributor as a result of warranty, support,
indemnity or liability terms You offer. You may include additional
disclaimers of warranty and limitations of liability specific to any
jurisdiction.
4. Inability to Comply Due to Statute or Regulation
---------------------------------------------------
If it is impossible for You to comply with any of the terms of this
License with respect to some or all of the Covered Software due to
statute, judicial order, or regulation then You must: (a) comply with
the terms of this License to the maximum extent possible; and (b)
describe the limitations and the code they affect. Such description must
be placed in a text file included with all distributions of the Covered
Software under this License. Except to the extent prohibited by statute
or regulation, such description must be sufficiently detailed for a
recipient of ordinary skill to be able to understand it.
5. Termination
--------------
5.1. The rights granted under this License will terminate automatically
if You fail to comply with any of its terms. However, if You become
compliant, then the rights granted under this License from a particular
Contributor are reinstated (a) provisionally, unless and until such
Contributor explicitly and finally terminates Your grants, and (b) on an
ongoing basis, if such Contributor fails to notify You of the
non-compliance by some reasonable means prior to 60 days after You have
come back into compliance. Moreover, Your grants from a particular
Contributor are reinstated on an ongoing basis if such Contributor
notifies You of the non-compliance by some reasonable means, this is the
first time You have received notice of non-compliance with this License
from such Contributor, and You become compliant prior to 30 days after
Your receipt of the notice.
5.2. If You initiate litigation against any entity by asserting a patent
infringement claim (excluding declaratory judgment actions,
counter-claims, and cross-claims) alleging that a Contributor Version
directly or indirectly infringes any patent, then the rights granted to
You by any and all Contributors for the Covered Software under Section
2.1 of this License shall terminate.
5.3. In the event of termination under Sections 5.1 or 5.2 above, all
end user license agreements (excluding distributors and resellers) which
have been validly granted by You or Your distributors under this License
prior to termination shall survive termination.
************************************************************************
* *
* 6. Disclaimer of Warranty *
* ------------------------- *
* *
* Covered Software is provided under this License on an "as is" *
* basis, without warranty of any kind, either expressed, implied, or *
* statutory, including, without limitation, warranties that the *
* Covered Software is free of defects, merchantable, fit for a *
* particular purpose or non-infringing. The entire risk as to the *
* quality and performance of the Covered Software is with You. *
* Should any Covered Software prove defective in any respect, You *
* (not any Contributor) assume the cost of any necessary servicing, *
* repair, or correction. This disclaimer of warranty constitutes an *
* essential part of this License. No use of any Covered Software is *
* authorized under this License except under this disclaimer. *
* *
************************************************************************
************************************************************************
* *
* 7. Limitation of Liability *
* -------------------------- *
* *
* Under no circumstances and under no legal theory, whether tort *
* (including negligence), contract, or otherwise, shall any *
* Contributor, or anyone who distributes Covered Software as *
* permitted above, be liable to You for any direct, indirect, *
* special, incidental, or consequential damages of any character *
* including, without limitation, damages for lost profits, loss of *
* goodwill, work stoppage, computer failure or malfunction, or any *
* and all other commercial damages or losses, even if such party *
* shall have been informed of the possibility of such damages. This *
* limitation of liability shall not apply to liability for death or *
* personal injury resulting from such party's negligence to the *
* extent applicable law prohibits such limitation. Some *
* jurisdictions do not allow the exclusion or limitation of *
* incidental or consequential damages, so this exclusion and *
* limitation may not apply to You. *
* *
************************************************************************
8. Litigation
-------------
Any litigation relating to this License may be brought only in the
courts of a jurisdiction where the defendant maintains its principal
place of business and such litigation shall be governed by laws of that
jurisdiction, without reference to its conflict-of-law provisions.
Nothing in this Section shall prevent a party's ability to bring
cross-claims or counter-claims.
9. Miscellaneous
----------------
This License represents the complete agreement concerning the subject
matter hereof. If any provision of this License is held to be
unenforceable, such provision shall be reformed only to the extent
necessary to make it enforceable. Any law or regulation which provides
that the language of a contract shall be construed against the drafter
shall not be used to construe this License against a Contributor.
10. Versions of the License
---------------------------
10.1. New Versions
Mozilla Foundation is the license steward. Except as provided in Section
10.3, no one other than the license steward has the right to modify or
publish new versions of this License. Each version will be given a
distinguishing version number.
10.2. Effect of New Versions
You may distribute the Covered Software under the terms of the version
of the License under which You originally received the Covered Software,
or under the terms of any subsequent version published by the license
steward.
10.3. Modified Versions
If you create software not governed by this License, and you want to
create a new license for such software, you may create and use a
modified version of this License if you rename the license and remove
any references to the name of the license steward (except to note that
such modified license differs from this License).
10.4. Distributing Source Code Form that is Incompatible With Secondary
Licenses
If You choose to distribute Source Code Form that is Incompatible With
Secondary Licenses under the terms of this version of the License, the
notice described in Exhibit B of this License must be attached.
Exhibit A - Source Code Form License Notice
-------------------------------------------
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
If it is not possible or desirable to put the notice in a particular
file, then You may include the notice in a location (such as a LICENSE
file in a relevant directory) where a recipient would be likely to look
for such a notice.
You may add additional accurate notices of copyright ownership.
Exhibit B - "Incompatible With Secondary Licenses" Notice
---------------------------------------------------------
This Source Code Form is "Incompatible With Secondary Licenses", as
defined by the Mozilla Public License, v. 2.0.

View File

@ -60,15 +60,15 @@ Compile software:
lutin -C -P ejson-test
License (APACHE v2.0)
License (MPL v2.0)
=====================
Copyright ejson Edouard DUPIN
Licensed under the Apache License, Version 2.0 (the "License");
Licensed under the Mozilla Public License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
https://www.mozilla.org/MPL/2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,

View File

@ -53,16 +53,16 @@ Are there any licensing restrictions? {#ejson_mainpage_license_restri
EJSON is **FREE software** and _all sub-library are FREE and staticly linkable !!!_
License (APACHE-2.0) {#ejson_mainpage_license}
====================
License (MPL v2.0) {#ejson_mainpage_license}
==================
Copyright EJSON Edouard DUPIN
Licensed under the Apache License, Version 2.0 (the "License");
Licensed under the Mozilla Public License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
<http://www.apache.org/licenses/LICENSE-2.0>
<https://www.mozilla.org/MPL/2.0>
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,

View File

@ -21,7 +21,7 @@ File to read: "read.json"
Reading a file is done like this:
@snippet read.cpp ejson_sample_read_file
The file naming is manage by @ref etk::FSNode that provide "DATA:" start string for internal application asset. You can use external path like "./plop/file.json" too.
The file naming is manage by @ref etk::FSNode that provide "DATA:///" start string for internal application asset. You can use external path like "./plop/file.json" too.
Read an JSON Stream {#ejson_tutorial_read_stream}
@ -59,8 +59,11 @@ Access to a boolean in an Object:
Access to a Number in an Object:
---------------------------------
By default a number is a double (herited from the js internal property)
@snippet read.cpp ejson_sample_read_get_number
But it is possible to read large number directly in 64 bits mode (better for entier number, no round generated.)
@snippet read.cpp ejson_sample_read_get_number_64_bits
Access to a Array in an Object:
---------------------------------

View File

@ -18,6 +18,8 @@ Write an JSON file {#ejson_tutorial_write_file}
Write an json tree is done like:
@snippet write.cpp ejson_sample_write_file
When you acces on the fileSystem, it is hard to have atoimic access, then the best way to not corupt your previous file (chash when writing the new) is to store the file in a second one and move the file at the corretc position. This is all done in the single commmand:
@snippet write.cpp ejson_sample_write_file_safe_mode
Write an JSON Stream {#ejson_tutorial_write_stream}
===================

View File

@ -1,7 +1,7 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#include <ejson/Array.hpp>
#include <ejson/debug.hpp>
@ -13,12 +13,12 @@
ejson::Array::Array(ememory::SharedPtr<ejson::internal::Value> _internalValue) :
ejson::Value(_internalValue) {
if (m_data == nullptr) {
if (m_data == null) {
return;
}
if (m_data->getType() != ejson::valueType::array) {
if (m_data->getType() != ejson::valueType::Array) {
// try to set wrong type inside ... ==> remove it ...
m_data = nullptr;
m_data = null;
}
}
@ -38,48 +38,48 @@ ejson::Array& ejson::Array::operator= (const ejson::Array& _obj) {
}
size_t ejson::Array::size() const {
if (m_data == nullptr) {
EJSON_DEBUG("Can not size (nullptr) ...");
if (m_data == null) {
EJSON_DEBUG("Can not size (null) ...");
return 0;
}
return static_cast<const ejson::internal::Array*>(m_data.get())->size();
}
ejson::Value ejson::Array::operator[] (size_t _id) {
if (m_data == nullptr) {
EJSON_DEBUG("Can not get (nullptr) ...");
return ejson::Value(nullptr);
if (m_data == null) {
EJSON_DEBUG("Can not get (null) ...");
return ejson::Value(null);
}
return ejson::Value(static_cast<ejson::internal::Array*>(m_data.get())->get(_id));
}
const ejson::Value ejson::Array::operator[] (size_t _id) const {
if (m_data == nullptr) {
EJSON_DEBUG("Can not get (nullptr) ...");
return ejson::Value(nullptr);;
if (m_data == null) {
EJSON_DEBUG("Can not get (null) ...");
return ejson::Value(null);;
}
return ejson::Value(static_cast<const ejson::internal::Array*>(m_data.get())->get(_id));
}
bool ejson::Array::add(const ejson::Value& _element) {
if (m_data == nullptr) {
EJSON_DEBUG("Can not add (nullptr) ...");
if (m_data == null) {
EJSON_DEBUG("Can not add (null) ...");
return false;
}
return static_cast<ejson::internal::Array*>(m_data.get())->add(_element.m_data);
}
void ejson::Array::remove(size_t _id) {
if (m_data == nullptr) {
EJSON_DEBUG("Can not remove (nullptr) ...");
if (m_data == null) {
EJSON_DEBUG("Can not remove (null) ...");
return;
}
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_DEBUG("Can not remove (nullptr) ...");
if (m_data == null) {
EJSON_DEBUG("Can not remove (null) ...");
return _it;
}
static_cast<ejson::internal::Array*>(m_data.get())->remove(_it.getId());
@ -110,7 +110,7 @@ template class ejson::iterator<ejson::Array>;
// Not implemented ==> force link error ...
/*
template<>
std::string ejson::iterator<ejson::Array>::getKey() const noexcept {
etk::String ejson::iterator<ejson::Array>::getKey() const noexcept {
return m_data.getKey(m_id);
}
*/

View File

@ -1,7 +1,7 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#pragma once
@ -44,13 +44,13 @@ namespace ejson {
/**
* @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.
* @return null if the element does not exist.
*/
ejson::Value operator[] (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.
* @return null if the element does not exist.
*/
const ejson::Value operator[] (size_t _id) const;
/**

View File

@ -1,7 +1,7 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#include <ejson/Boolean.hpp>
@ -11,12 +11,12 @@
ejson::Boolean::Boolean(ememory::SharedPtr<ejson::internal::Value> _internalValue) :
ejson::Value(_internalValue) {
if (m_data == nullptr) {
if (m_data == null) {
return;
}
if (m_data->getType() != ejson::valueType::boolean) {
if (m_data->getType() != ejson::valueType::Boolean) {
// try to set wrong type inside ... ==> remove it ...
m_data = nullptr;
m_data = null;
}
}
@ -36,16 +36,16 @@ ejson::Boolean& ejson::Boolean::operator= (const ejson::Boolean& _obj) {
}
void ejson::Boolean::set(bool _value) {
if (m_data == nullptr) {
EJSON_DEBUG("Can not set (nullptr) ...");
if (m_data == null) {
EJSON_DEBUG("Can not set (null) ...");
return;
}
static_cast<ejson::internal::Boolean*>(m_data.get())->set(_value);
}
bool ejson::Boolean::get(bool _errorValue) const {
if (m_data == nullptr) {
EJSON_DEBUG("Can not get (nullptr) ...");
if (m_data == null) {
EJSON_DEBUG("Can not get (null) ...");
return _errorValue;
}
return static_cast<const ejson::internal::Boolean*>(m_data.get())->get();

View File

@ -1,7 +1,7 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#pragma once

View File

@ -1,21 +1,22 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#include <ejson/Document.hpp>
#include <ejson/debug.hpp>
#include <ejson/internal/Document.hpp>
#include <etk/os/FSNode.hpp>
#include <etk/path/fileSystem.hpp>
#include <etk/uri/uri.hpp>
ejson::Document::Document(ememory::SharedPtr<ejson::internal::Value> _internalValue) :
ejson::Object(_internalValue) {
if (m_data == nullptr) {
if (m_data == null) {
return;
}
if (m_data->getType() != ejson::valueType::document) {
if (m_data->getType() != ejson::valueType::Document) {
// try to set wrong type inside ... ==> remove it ...
m_data = nullptr;
m_data = null;
}
}
@ -34,69 +35,102 @@ ejson::Document& ejson::Document::operator= (const ejson::Document& _obj) {
return *this;
}
bool ejson::Document::parse(const std::string& _data) {
if (m_data == nullptr) {
EJSON_DEBUG("Can not parse (nullptr) ...");
bool ejson::Document::parse(const etk::String& _data) {
if (m_data == null) {
EJSON_DEBUG("Can not parse (null) ...");
return false;
}
return static_cast<ejson::internal::Document*>(m_data.get())->parse(_data);
}
bool ejson::Document::generate(std::string& _data) {
if (m_data == nullptr) {
EJSON_DEBUG("Can not generate (nullptr) ...");
bool ejson::Document::generate(etk::String& _data) {
if (m_data == null) {
EJSON_DEBUG("Can not generate (null) ...");
return false;
}
return static_cast<ejson::internal::Document*>(m_data.get())->generate(_data);
}
bool ejson::Document::load(const std::string& _file) {
if (m_data == nullptr) {
EJSON_DEBUG("Can not load (nullptr) ...");
bool ejson::Document::load(const etk::Path& _path) {
if (m_data == null) {
EJSON_DEBUG("Can not load (null) ...");
return false;
}
return static_cast<ejson::internal::Document*>(m_data.get())->load(_file);
return static_cast<ejson::internal::Document*>(m_data.get())->load(_path);
}
bool ejson::Document::store(const std::string& _file) {
if (m_data == nullptr) {
EJSON_DEBUG("Can not store (nullptr) ...");
bool ejson::Document::load(const etk::Uri& _uri) {
if (m_data == null) {
EJSON_DEBUG("Can not load (null) ...");
return false;
}
return static_cast<ejson::internal::Document*>(m_data.get())->store(_file);
return static_cast<ejson::internal::Document*>(m_data.get())->load(_uri);
}
bool ejson::Document::storeSafe(const std::string& _file) {
if (m_data == nullptr) {
EJSON_DEBUG("Can not store (nullptr) ...");
bool ejson::Document::store(const etk::Path& _path) {
if (m_data == null) {
EJSON_DEBUG("Can not store (null) ...");
return false;
}
bool done = static_cast<ejson::internal::Document*>(m_data.get())->store(_file+".tmp");
return static_cast<ejson::internal::Document*>(m_data.get())->store(_path);
}
bool ejson::Document::store(const etk::Uri& _uri) {
if (m_data == null) {
EJSON_DEBUG("Can not store (null) ...");
return false;
}
return static_cast<ejson::internal::Document*>(m_data.get())->store(_uri);
}
bool ejson::Document::storeSafe(const etk::Path& _path) {
if (m_data == null) {
EJSON_DEBUG("Can not store (null) ...");
return false;
}
bool done = static_cast<ejson::internal::Document*>(m_data.get())->store(_path+".tmp");
if (done == false) {
return false;
}
return etk::FSNodeMove(_file+".tmp", _file);
return etk::path::move(_path+".tmp", _path);
}
bool ejson::Document::storeSafe(const etk::Uri& _uri) {
if (m_data == null) {
EJSON_DEBUG("Can not store (null) ...");
return false;
}
if (etk::uri::canMove(_uri) == false) {
return static_cast<ejson::internal::Document*>(m_data.get())->store(_uri);
}
etk::Uri uriTmp = _uri;
uriTmp.setPath(uriTmp.getPath() + ".tmp");
bool done = static_cast<ejson::internal::Document*>(m_data.get())->store(uriTmp);
if (done == false) {
return false;
}
return etk::uri::move(uriTmp, _uri);
}
void ejson::Document::setDisplayError(bool _value){
if (m_data == nullptr) {
EJSON_DEBUG("Can not setDisplayError (nullptr) ...");
if (m_data == null) {
EJSON_DEBUG("Can not setDisplayError (null) ...");
return;
}
static_cast<ejson::internal::Document*>(m_data.get())->setDisplayError(_value);
}
bool ejson::Document::getDisplayError() {
if (m_data == nullptr) {
EJSON_DEBUG("Can not getDisplayError (nullptr) ...");
if (m_data == null) {
EJSON_DEBUG("Can not getDisplayError (null) ...");
return false;
}
return static_cast<ejson::internal::Document*>(m_data.get())->getDisplayError();
}
void ejson::Document::displayError() {
if (m_data == nullptr) {
EJSON_DEBUG("Can not displayError (nullptr) ...");
if (m_data == null) {
EJSON_DEBUG("Can not displayError (null) ...");
return;
}
static_cast<ejson::internal::Document*>(m_data.get())->displayError();

View File

@ -1,16 +1,17 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#pragma once
#include <ejson/Value.hpp>
#include <vector>
#include <etk/Vector.hpp>
#include <etk/types.hpp>
#include <ejson/String.hpp>
#include <ejson/Array.hpp>
#include <ejson/Object.hpp>
#include <etk/uri/Uri.hpp>
namespace ejson {
/**
@ -44,35 +45,41 @@ namespace ejson {
* @return false : An error occured
* @return true : Parsing is OK
*/
bool parse(const std::string& _data);
bool parse(const etk::String& _data);
/**
* @brief generate a string that contain the created Json
* @param[out] _data Data where the Json is stored
* @return false : An error occured
* @return true : Parsing is OK
*/
bool generate(std::string& _data);
bool generate(etk::String& _data);
/**
* @brief Load the file that might contain the Json
* @param[in] _file Filename of the Json (compatible with etk FSNode naming)
* @param[in] _path/_uri Path/URI of the json
* @return false : An error occured
* @return true : Parsing is OK
*/
bool load(const std::string& _file);
bool load(const etk::Path& _path);
/// @previous
bool load(const etk::Uri& _uri);
/**
* @brief Store the Json in the file
* @param[in] _file Filename of the Json (compatible with etk FSNode naming)
* @param[in] _path/_uri Path/URI of the json
* @return false : An error occured
* @return true : Parsing is OK
*/
bool store(const std::string& _file);
bool store(const etk::Path& _path);
/// @previous
bool store(const etk::Uri& _uri);
/**
* @brief Store the Json in the file (safe mode mean that the file is store in a second file xxx.tmp and moved in the file xxx (only one mode to be really safe with filesystem ...)
* @param[in] _file Filename of the Json (compatible with etk FSNode naming)
* @param[in] _path/_uri Path/URI of the json
* @return false : An error occured
* @return true : Parsing is OK
*/
bool storeSafe(const std::string& _file);
bool storeSafe(const etk::Path& _path);
/// @previous
bool storeSafe(const etk::Uri& _uri);
/**
* @brief Set the display of the error when detected.
* @param[in] _value true: display error, false not display error (get it at end)

View File

@ -1,7 +1,7 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#include <ejson/FilePos.hpp>
@ -83,7 +83,7 @@ size_t ejson::FilePos::getLine() const {
return m_line;
}
std::ostream& ejson::operator <<(std::ostream& _os, const ejson::FilePos& _obj) {
etk::Stream& ejson::operator <<(etk::Stream& _os, const ejson::FilePos& _obj) {
_os << "(l=";
_os << _obj.getLine();
_os << ",c=";

View File

@ -1,11 +1,12 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <etk/Stream.hpp>
namespace ejson {
/**
@ -87,7 +88,7 @@ namespace ejson {
size_t getLine() const;
};
//! @not-in-doc
std::ostream& operator <<(std::ostream& _os, const FilePos& _obj);
etk::Stream& operator <<(etk::Stream& _os, const FilePos& _obj);
}

View File

@ -1,7 +1,7 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#include <ejson/Null.hpp>
#include <ejson/debug.hpp>
@ -9,12 +9,12 @@
ejson::Null::Null(ememory::SharedPtr<ejson::internal::Value> _internalValue) :
ejson::Value(_internalValue) {
if (m_data == nullptr) {
if (m_data == null) {
return;
}
if (m_data->getType() != ejson::valueType::null) {
if (m_data->getType() != ejson::valueType::Null) {
// try to set wrong type inside ... ==> remove it ...
m_data = nullptr;
m_data = null;
}
}

View File

@ -1,7 +1,7 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#pragma once

View File

@ -1,7 +1,7 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#include <ejson/Number.hpp>
#include <ejson/debug.hpp>
@ -10,12 +10,12 @@
ejson::Number::Number(ememory::SharedPtr<ejson::internal::Value> _internalValue) :
ejson::Value(_internalValue) {
if (m_data == nullptr) {
if (m_data == null) {
return;
}
if (m_data->getType() != ejson::valueType::number) {
if (m_data->getType() != ejson::valueType::Number) {
// try to set wrong type inside ... ==> remove it ...
m_data = nullptr;
m_data = null;
}
}
@ -35,56 +35,56 @@ ejson::Number& ejson::Number::operator= (const ejson::Number& _obj) {
}
void ejson::Number::set(double _value) {
if (m_data == nullptr) {
EJSON_DEBUG("Can not set (nullptr) ...");
if (m_data == null) {
EJSON_DEBUG("Can not set (null) ...");
return;
}
static_cast<ejson::internal::Number*>(m_data.get())->set(_value);
}
void ejson::Number::set(uint64_t _value) {
if (m_data == nullptr) {
EJSON_DEBUG("Can not set (nullptr) ...");
if (m_data == null) {
EJSON_DEBUG("Can not set (null) ...");
return;
}
static_cast<ejson::internal::Number*>(m_data.get())->set(_value);
}
void ejson::Number::set(int64_t _value) {
if (m_data == nullptr) {
EJSON_DEBUG("Can not set (nullptr) ...");
if (m_data == null) {
EJSON_DEBUG("Can not set (null) ...");
return;
}
static_cast<ejson::internal::Number*>(m_data.get())->set(_value);
}
double ejson::Number::get(double _errorValue) const {
if (m_data == nullptr) {
EJSON_DEBUG("Can not get (nullptr) ...");
if (m_data == null) {
EJSON_DEBUG("Can not get (null) ...");
return _errorValue;
}
return static_cast<const ejson::internal::Number*>(m_data.get())->get();
}
uint64_t ejson::Number::getU64(uint64_t _errorValue) const {
if (m_data == nullptr) {
EJSON_DEBUG("Can not get (nullptr) ...");
if (m_data == null) {
EJSON_DEBUG("Can not get (null) ...");
return _errorValue;
}
return static_cast<const ejson::internal::Number*>(m_data.get())->getU64();
}
int64_t ejson::Number::getI64(int64_t _errorValue) const {
if (m_data == nullptr) {
EJSON_DEBUG("Can not get (nullptr) ...");
if (m_data == null) {
EJSON_DEBUG("Can not get (null) ...");
return _errorValue;
}
return static_cast<const ejson::internal::Number*>(m_data.get())->getI64();
}
ejson::internal::Number::type ejson::Number::getType() const {
if (m_data == nullptr) {
EJSON_DEBUG("Can not get (nullptr) ...");
if (m_data == null) {
EJSON_DEBUG("Can not get (null) ...");
return ejson::internal::Number::type::tDouble;
}
return static_cast<const ejson::internal::Number*>(m_data.get())->getType();

View File

@ -1,7 +1,7 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#pragma once

View File

@ -1,7 +1,7 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#include <ejson/Object.hpp>
#include <ejson/debug.hpp>
@ -10,13 +10,13 @@
ejson::Object::Object(ememory::SharedPtr<ejson::internal::Value> _internalValue) :
ejson::Value(_internalValue) {
if (m_data == nullptr) {
if (m_data == null) {
return;
}
if ( m_data->getType() != ejson::valueType::object
&& m_data->getType() != ejson::valueType::document) {
if ( m_data->getType() != ejson::valueType::Object
&& m_data->getType() != ejson::valueType::Document) {
// try to set wrong type inside ... ==> remove it ...
m_data = nullptr;
m_data = null;
}
}
@ -31,7 +31,7 @@ ejson::Object::Object() :
m_data = ejson::internal::Object::create();
}
ejson::Object::Object(const std::string& _data) :
ejson::Object::Object(const etk::String& _data) :
ejson::Value() {
m_data = ejson::internal::Object::create(_data);
}
@ -41,97 +41,97 @@ ejson::Object& ejson::Object::operator= (const ejson::Object& _obj) {
return *this;
}
bool ejson::Object::valueExist(const std::string& _name) const {
if (m_data == nullptr) {
EJSON_DEBUG("Can not exist (nullptr) ...");
bool ejson::Object::valueExist(const etk::String& _name) const {
if (m_data == null) {
EJSON_DEBUG("Can not exist (null) ...");
return false;
}
return static_cast<const ejson::internal::Object*>(m_data.get())->exist(_name);
}
ejson::Value ejson::Object::operator[] (const std::string& _name) {
if (m_data == nullptr) {
EJSON_DEBUG("Can not operator[] (nullptr) ...");
return ejson::Value(nullptr);
ejson::Value ejson::Object::operator[] (const etk::String& _name) {
if (m_data == null) {
EJSON_DEBUG("Can not operator[] (null) ...");
return ejson::Value(null);
}
return ejson::Value(static_cast<ejson::internal::Object*>(m_data.get())->get(_name));
}
const ejson::Value ejson::Object::operator[] (const std::string& _name) const {
if (m_data == nullptr) {
EJSON_DEBUG("Can not operator[] (nullptr) ...");
return ejson::Value(nullptr);
const ejson::Value ejson::Object::operator[] (const etk::String& _name) const {
if (m_data == null) {
EJSON_DEBUG("Can not operator[] (null) ...");
return ejson::Value(null);
}
return ejson::Value(static_cast<const ejson::internal::Object*>(m_data.get())->get(_name));
}
std::vector<std::string> ejson::Object::getKeys() const {
if (m_data == nullptr) {
EJSON_DEBUG("Can not getKeys (nullptr) ...");
return std::vector<std::string>();
etk::Vector<etk::String> ejson::Object::getKeys() const {
if (m_data == null) {
EJSON_DEBUG("Can not getKeys (null) ...");
return etk::Vector<etk::String>();
}
return static_cast<const ejson::internal::Object*>(m_data.get())->getKeys();
}
size_t ejson::Object::size() const {
if (m_data == nullptr) {
EJSON_DEBUG("Can not size (nullptr) ...");
if (m_data == null) {
EJSON_DEBUG("Can not size (null) ...");
return 0;
}
return static_cast<const ejson::internal::Object*>(m_data.get())->size();
}
ejson::Value ejson::Object::operator[] (size_t _id) {
if (m_data == nullptr) {
EJSON_DEBUG("Can not operator[] (nullptr) ...");
return ejson::Value(nullptr);
if (m_data == null) {
EJSON_DEBUG("Can not operator[] (null) ...");
return ejson::Value(null);
}
return ejson::Value(static_cast<ejson::internal::Object*>(m_data.get())->get(_id));
}
const ejson::Value ejson::Object::operator[] (size_t _id) const {
if (m_data == nullptr) {
EJSON_DEBUG("Can not operator[] (nullptr) ...");
return ejson::Value(nullptr);
if (m_data == null) {
EJSON_DEBUG("Can not operator[] (null) ...");
return ejson::Value(null);
}
return ejson::Value(static_cast<const ejson::internal::Object*>(m_data.get())->get(_id));
}
std::string ejson::Object::getKey(size_t _id) const {
if (m_data == nullptr) {
EJSON_DEBUG("Can not getKey (nullptr) ...");
etk::String ejson::Object::getKey(size_t _id) const {
if (m_data == null) {
EJSON_DEBUG("Can not getKey (null) ...");
return "";
}
return static_cast<const ejson::internal::Object*>(m_data.get())->getKey(_id);
}
bool ejson::Object::add(const std::string& _name, const ejson::Value& _value) {
if (m_data == nullptr) {
EJSON_DEBUG("Can not add (nullptr) ...");
bool ejson::Object::add(const etk::String& _name, const ejson::Value& _value) {
if (m_data == null) {
EJSON_DEBUG("Can not add (null) ...");
return false;
}
return static_cast<ejson::internal::Object*>(m_data.get())->add(_name, _value.m_data);
}
void ejson::Object::remove(const std::string& _name) {
if (m_data == nullptr) {
EJSON_DEBUG("Can not remove (nullptr) ...");
void ejson::Object::remove(const etk::String& _name) {
if (m_data == null) {
EJSON_DEBUG("Can not remove (null) ...");
return;
}
static_cast<ejson::internal::Object*>(m_data.get())->remove(_name);
}
void ejson::Object::remove(size_t _id) {
if (m_data == nullptr) {
EJSON_DEBUG("Can not remove (nullptr) ...");
if (m_data == null) {
EJSON_DEBUG("Can not remove (null) ...");
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_DEBUG("Can not remove (nullptr) ...");
if (m_data == null) {
EJSON_DEBUG("Can not remove (null) ...");
return _it;
}
static_cast<ejson::internal::Object*>(m_data.get())->remove(_it.getId());
@ -160,7 +160,7 @@ const ejson::Object::iterator ejson::Object::end() const {
template class ejson::iterator<ejson::Object>;
namespace ejson {
template<>
std::string iterator<ejson::Object>::getKey() const noexcept {
etk::String iterator<ejson::Object>::getKey() const noexcept {
return m_data.getKey(m_id);
}
}

View File

@ -1,13 +1,12 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <etk/Hash.hpp>
#include <algorithm>
#include <etk/Map.hpp>
#include <ejson/Value.hpp>
#include <ejson/iterator.hpp>
@ -35,7 +34,7 @@ namespace ejson {
* @brief Constructor
* @param[in] _data string data to parse
*/
Object(const std::string& _data);
Object(const etk::String& _data);
/**
* @brief Copy constructor
* @param[in] _obj Object to copy
@ -49,25 +48,25 @@ namespace ejson {
* @param[in] _name Name of the object.
* @return The existance of the element.
*/
bool valueExist(const std::string& _name) const;
bool valueExist(const etk::String& _name) const;
/**
* @brief Cet the sub element with his name (no cast check)
* @param[in] _name Name of the object
* @return Value on the element requested or a value that does not exist @ref ejson::Value::exist.
*/
ejson::Value operator[] (const std::string& _name);
ejson::Value operator[] (const etk::String& _name);
/**
* @brief Get the const sub element with his name (no cast check)
* @param[in] _name Name of the object
* @return const Value on the element requested or a value that does not exist @ref ejson::Value::exist.
*/
const ejson::Value operator[] (const std::string& _name) const;
const ejson::Value operator[] (const etk::String& _name) const;
public:
/**
* @brief Get all the element name (keys).
* @return a vector of all name (key).
*/
std::vector<std::string> getKeys() const;
etk::Vector<etk::String> getKeys() const;
/**
* @brief get the number of sub element in the current one
* @return the Number of stored element
@ -90,7 +89,7 @@ namespace ejson {
* @param[in] _id Id of the element.
* @return The name (key).
*/
std::string getKey(size_t _id) const;
etk::String getKey(size_t _id) const;
public:
/**
* @brief add an element in the Object
@ -98,12 +97,12 @@ namespace ejson {
* @param[in] _value Element to add
* @return false if an error occured
*/
bool add(const std::string& _name, const ejson::Value& _value);
bool add(const etk::String& _name, const ejson::Value& _value);
/**
* @brief Remove Value with his name
* @param[in] _name Name of the object
*/
void remove(const std::string& _name);
void remove(const etk::String& _name);
/**
* @brief Remove Value with his id
* @param[in] _id Id of the element.

View File

@ -1,7 +1,7 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#include <ejson/String.hpp>
#include <ejson/debug.hpp>
@ -9,12 +9,12 @@
ejson::String::String(ememory::SharedPtr<ejson::internal::Value> _internalValue) :
ejson::Value(_internalValue) {
if (m_data == nullptr) {
if (m_data == null) {
return;
}
if (m_data->getType() != ejson::valueType::string) {
if (m_data->getType() != ejson::valueType::String) {
// try to set wrong type inside ... ==> remove it ...
m_data = nullptr;
m_data = null;
}
}
@ -23,7 +23,7 @@ ejson::String::String(const ejson::String& _obj) :
}
ejson::String::String(const std::string& _value) :
ejson::String::String(const etk::String& _value) :
ejson::Value() {
m_data = ejson::internal::String::create(_value);
}
@ -33,17 +33,17 @@ ejson::String& ejson::String::operator= (const ejson::String& _obj) {
return *this;
}
void ejson::String::set(const std::string& _value) {
if (m_data == nullptr) {
EJSON_DEBUG("Can not set (nullptr) ...");
void ejson::String::set(const etk::String& _value) {
if (m_data == null) {
EJSON_DEBUG("Can not set (null) ...");
return;
}
static_cast<ejson::internal::String*>(m_data.get())->set(_value);
}
std::string ejson::String::get(const std::string& _errorValue) const {
if (m_data == nullptr) {
EJSON_DEBUG("Can not get (nullptr) ...");
etk::String ejson::String::get(const etk::String& _errorValue) const {
if (m_data == null) {
EJSON_DEBUG("Can not get (null) ...");
return _errorValue;
}
return static_cast<const ejson::internal::String*>(m_data.get())->get();

View File

@ -1,7 +1,7 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#pragma once
@ -28,7 +28,7 @@ namespace ejson {
* @brief Constructor
* @param[in] _value String value to set
*/
String(const std::string& _value="");
String(const etk::String& _value="");
/**
* @brief Copy constructor
* @param[in] _obj Object to copy
@ -40,13 +40,13 @@ namespace ejson {
* @brief set the value of the node.
* @param[in] _value New value of the node.
*/
void set(const std::string& _value);
void set(const etk::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.
*/
std::string get(const std::string& _errorValue="") const;
etk::String get(const etk::String& _errorValue="") const;
};
}

View File

@ -1,7 +1,7 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#include <ejson/Value.hpp>
@ -10,12 +10,12 @@
#include <ejson/Document.hpp>
ejson::Value ejson::empty() {
return ejson::Value(ememory::SharedPtr<ejson::internal::Value>(nullptr));
return ejson::Value(ememory::SharedPtr<ejson::internal::Value>(null));
}
std::ostream& ejson::operator <<(std::ostream& _os, const ejson::Value& _obj) {
etk::Stream& ejson::operator <<(etk::Stream& _os, const ejson::Value& _obj) {
_os << "{";
_os << "Value JSON: " << _obj.getType();
/*
@ -28,34 +28,34 @@ std::ostream& ejson::operator <<(std::ostream& _os, const ejson::Value& _obj) {
}
enum ejson::valueType ejson::Value::getType() const {
if (m_data == nullptr) {
if (m_data == null) {
EJSON_DEBUG("Can not get type ...");
return ejson::valueType::unknow;
return ejson::valueType::Unknow;
}
return m_data->getType();
}
bool ejson::Value::exist() const {
if (m_data == nullptr) {
if (m_data == null) {
return false;
}
return true;
}
std::string ejson::Value::generateHumanString() const {
std::string out;
if (m_data == nullptr) {
EJSON_DEBUG("Can not remove (nullptr) ...");
etk::String ejson::Value::generateHumanString() const {
etk::String out;
if (m_data == null) {
EJSON_DEBUG("Can not remove (null) ...");
return out;
}
static_cast<const ejson::internal::Value*>(m_data.get())->iGenerate(out, 0);
return out;
}
std::string ejson::Value::generateMachineString() const {
std::string out;
if (m_data == nullptr) {
EJSON_DEBUG("Can not remove (nullptr) ...");
etk::String ejson::Value::generateMachineString() const {
etk::String out;
if (m_data == null) {
EJSON_DEBUG("Can not remove (null) ...");
return out;
}
static_cast<const ejson::internal::Value*>(m_data.get())->iMachineGenerate(out);
@ -64,7 +64,7 @@ std::string ejson::Value::generateMachineString() const {
/*
ejson::FilePos ejson::Value::getPos() const {
if (m_data == nullptr) {
if (m_data == null) {
return ejson::FilePos(0,0);
}
return m_data->getPos();
@ -77,7 +77,7 @@ ejson::Value::Value(const ememory::SharedPtr<ejson::internal::Value>& _internalV
}
ejson::Value::Value() :
m_data(nullptr) {
m_data(null) {
}
@ -131,8 +131,8 @@ const ejson::Null ejson::Value::toNull() const{
}
void ejson::Value::display() const {
if (m_data == nullptr) {
EJSON_DEBUG("Can not Display (nullptr) ...");
if (m_data == null) {
EJSON_DEBUG("Can not Display (null) ...");
return;
}
return m_data->display();
@ -140,75 +140,75 @@ void ejson::Value::display() const {
bool ejson::Value::isDocument() const {
if (m_data == nullptr) {
if (m_data == null) {
return false;
}
enum ejson::valueType type = m_data->getType();
return type == ejson::valueType::document;
return type == ejson::valueType::Document;
}
bool ejson::Value::isArray() const {
if (m_data == nullptr) {
if (m_data == null) {
return false;
}
return m_data->getType() == ejson::valueType::array;
return m_data->getType() == ejson::valueType::Array;
}
bool ejson::Value::isObject() const {
if (m_data == nullptr) {
if (m_data == null) {
return false;
}
return m_data->getType() == ejson::valueType::object;
return m_data->getType() == ejson::valueType::Object;
}
bool ejson::Value::isString() const {
if (m_data == nullptr) {
if (m_data == null) {
return false;
}
return m_data->getType() == ejson::valueType::string;
return m_data->getType() == ejson::valueType::String;
}
bool ejson::Value::isNumber() const {
if (m_data == nullptr) {
if (m_data == null) {
return false;
}
return m_data->getType() == ejson::valueType::number;
return m_data->getType() == ejson::valueType::Number;
}
bool ejson::Value::isBoolean() const {
if (m_data == nullptr) {
if (m_data == null) {
return false;
}
return m_data->getType() == ejson::valueType::boolean;
return m_data->getType() == ejson::valueType::Boolean;
}
bool ejson::Value::isNull() const {
if (m_data == nullptr) {
if (m_data == null) {
return false;
}
return m_data->getType() == ejson::valueType::null;
return m_data->getType() == ejson::valueType::Null;
}
void ejson::Value::clear() {
if (m_data == nullptr) {
EJSON_DEBUG("Can not Clear (nullptr) ...");
if (m_data == null) {
EJSON_DEBUG("Can not Clear (null) ...");
return;
}
return m_data->clear();
}
bool ejson::Value::transfertIn(ejson::Value& _obj) {
if (m_data == nullptr) {
EJSON_DEBUG("Can not transfert In (nullptr) ...");
if (m_data == null) {
EJSON_DEBUG("Can not transfert In (null) ...");
return false;
}
return m_data->transfertIn(_obj.m_data);
}
ejson::Value ejson::Value::clone() const {
if (m_data == nullptr) {
EJSON_DEBUG("Can not transfert In (nullptr) ...");
if (m_data == null) {
EJSON_DEBUG("Can not transfert In (null) ...");
return ejson::Value(m_data);
}
return ejson::Value(m_data->clone());

View File

@ -1,7 +1,7 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#pragma once
@ -67,72 +67,72 @@ namespace ejson {
bool exist() const;
/**
* @brief Cast the element in a Document if it is possible.
* @return pointer on the class or nullptr.
* @return pointer on the class or null.
*/
ejson::Document toDocument();
/**
* @brief Cast the element in a Document if it is possible.
* @return CONST pointer on the class or nullptr.
* @return CONST pointer on the class or null.
*/
const ejson::Document toDocument() const;
/**
* @brief Cast the element in a Array if it is possible.
* @return pointer on the class or nullptr.
* @return pointer on the class or null.
*/
ejson::Array toArray();
/**
* @brief Cast the element in a Array if it is possible.
* @return CONST pointer on the class or nullptr.
* @return CONST pointer on the class or null.
*/
const ejson::Array toArray() const;
/**
* @brief Cast the element in a Object if it is possible.
* @return pointer on the class or nullptr.
* @return pointer on the class or null.
*/
ejson::Object toObject();
/**
* @brief Cast the element in a Object if it is possible.
* @return CONST pointer on the class or nullptr.
* @return CONST pointer on the class or null.
*/
const ejson::Object toObject() const;
/**
* @brief Cast the element in a String if it is possible.
* @return pointer on the class or nullptr.
* @return pointer on the class or null.
*/
ejson::String toString();
/**
* @brief Cast the element in a String if it is possible.
* @return CONST pointer on the class or nullptr.
* @return CONST pointer on the class or null.
*/
const ejson::String toString() const;
/**
* @brief Cast the element in a Number if it is possible.
* @return pointer on the class or nullptr.
* @return pointer on the class or null.
*/
ejson::Number toNumber();
/**
* @brief Cast the element in a Number if it is possible.
* @return CONST pointer on the class or nullptr.
* @return CONST pointer on the class or null.
*/
const ejson::Number toNumber() const;
/**
* @brief Cast the element in a Boolean if it is possible.
* @return pointer on the class or nullptr.
* @return pointer on the class or null.
*/
ejson::Boolean toBoolean();
/**
* @brief Cast the element in a Boolean if it is possible.
* @return CONST pointer on the class or nullptr.
* @return CONST pointer on the class or null.
*/
const ejson::Boolean toBoolean() const;
/**
* @brief Cast the element in a Null if it is possible.
* @return pointer on the class or nullptr.
* @return pointer on the class or null.
*/
ejson::Null toNull();
/**
* @brief Cast the element in a Null if it is possible.
* @return CONST pointer on the class or nullptr.
* @return CONST pointer on the class or null.
*/
const ejson::Null toNull() const;
@ -184,7 +184,7 @@ namespace ejson {
bool transfertIn(ejson::Value& _obj);
/**
* @brief Copy the curent node and all the child in the curent one.
* @return nullptr in an error occured, the pointer on the element otherwise
* @return null in an error occured, the pointer on the element otherwise
*/
ejson::Value clone() const;
public:
@ -192,15 +192,15 @@ namespace ejson {
* @brief generate a string that contain the created JSON
* @return generated data
*/
std::string generateHumanString() const;
etk::String generateHumanString() const;
/**
* @brief generate a string that contain the created JSON
* @return generated data
*/
std::string generateMachineString() const;
etk::String generateMachineString() const;
};
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const ejson::Value& _obj);
etk::Stream& operator <<(etk::Stream& _os, const ejson::Value& _obj);
/**
* @brief create an empty Value (that does not exist ...
* @return empty value (not usable)

View File

@ -1,7 +1,7 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#include <ejson/debug.hpp>

View File

@ -1,7 +1,7 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#pragma once

View File

@ -1,7 +1,7 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#include <ejson/iterator.hpp>
@ -9,28 +9,28 @@ template<class EJSON_BASE_T>
ejson::iterator<EJSON_BASE_T>::iterator(EJSON_BASE_T& _obj, size_t _pos) :
m_data(_obj),
m_id(_pos) {
m_id = std::avg(size_t(0), m_id, m_data.size());
m_id = etk::avg(size_t(0), m_id, m_data.size());
}
template<class EJSON_BASE_T>
ejson::iterator<EJSON_BASE_T>::iterator(const EJSON_BASE_T& _obj, size_t _pos) :
m_data(const_cast<EJSON_BASE_T&>(_obj)),
m_id(_pos) {
m_id = std::avg(size_t(0), m_id, m_data.size());
m_id = etk::avg(size_t(0), m_id, m_data.size());
}
template<class EJSON_BASE_T>
ejson::iterator<EJSON_BASE_T>::iterator(const ejson::iterator<EJSON_BASE_T>& _obj) :
m_data(_obj.m_data),
m_id(_obj.m_id) {
m_id = std::avg(size_t(0), m_id, m_data.size());
m_id = etk::avg(size_t(0), m_id, m_data.size());
}
template<class EJSON_BASE_T>
ejson::iterator<EJSON_BASE_T>& ejson::iterator<EJSON_BASE_T>::operator= (const ejson::iterator<EJSON_BASE_T>& _obj) {
m_data = _obj.m_data;
m_id = _obj.m_id;
m_id = std::avg(size_t(0), m_id, m_data.size());
m_id = etk::avg(size_t(0), m_id, m_data.size());
return *this;
}
@ -38,7 +38,7 @@ template<class EJSON_BASE_T>
ejson::iterator<EJSON_BASE_T>& ejson::iterator<EJSON_BASE_T>::operator+= (int32_t _val) {
int64_t val = m_id;
val += _val;
m_id = std::avg(int64_t(0), val, int64_t(m_data.size()));
m_id = etk::avg(int64_t(0), val, int64_t(m_data.size()));
return *this;
}
@ -53,7 +53,7 @@ template<class EJSON_BASE_T>
ejson::iterator<EJSON_BASE_T>& ejson::iterator<EJSON_BASE_T>::operator-= (int32_t _val) {
int64_t val = m_id;
val -= _val;
m_id = std::avg(int64_t(0), val, int64_t(m_data.size()));
m_id = etk::avg(int64_t(0), val, int64_t(m_data.size()));
return *this;
}
@ -68,7 +68,7 @@ template<class EJSON_BASE_T>
ejson::iterator<EJSON_BASE_T>& ejson::iterator<EJSON_BASE_T>::operator++() {
int64_t val = m_id;
++val;
m_id = std::avg(int64_t(0), val, int64_t(m_data.size()));
m_id = etk::avg(int64_t(0), val, int64_t(m_data.size()));
return *this;
}
@ -83,7 +83,7 @@ template<class EJSON_BASE_T>
ejson::iterator<EJSON_BASE_T>& ejson::iterator<EJSON_BASE_T>::operator--() {
int64_t val = m_id;
--val;
m_id = std::avg(int64_t(0), val, int64_t(m_data.size()));
m_id = etk::avg(int64_t(0), val, int64_t(m_data.size()));
return *this;
}

View File

@ -1,7 +1,7 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#pragma once

View File

@ -1,7 +1,7 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
@ -15,14 +15,14 @@
#include <ejson/debug.hpp>
ememory::SharedPtr<ejson::internal::Array> ejson::internal::Array::create() {
return ememory::SharedPtr<ejson::internal::Array>(new ejson::internal::Array());
return ememory::SharedPtr<ejson::internal::Array>(ETK_NEW(ejson::internal::Array));
}
void ejson::internal::Array::clear() {
m_value.clear();
}
bool ejson::internal::Array::iParse(const std::string& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::internal::Document& _doc) {
bool ejson::internal::Array::iParse(const etk::String& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::internal::Document& _doc) {
EJSON_PARSE_ELEMENT("start parse : 'Object' ");
for (size_t iii=_pos+1; iii<_data.size(); iii++) {
_filePos.check(_data[iii]);
@ -51,36 +51,36 @@ bool ejson::internal::Array::iParse(const std::string& _data, size_t& _pos, ejso
// find an object:
EJSON_PARSE_ELEMENT("find Object");
ememory::SharedPtr<ejson::internal::Object> tmpElement = ejson::internal::Object::create();
if (tmpElement == nullptr) {
if (tmpElement == null) {
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in object");
_pos=iii;
return false;
}
tmpElement->iParse(_data, iii, _filePos, _doc);
m_value.push_back(tmpElement);
m_value.pushBack(tmpElement);
} else if ( _data[iii] == '"'
|| _data[iii] == '\'') {
// find a string:
EJSON_PARSE_ELEMENT("find String quoted");
ememory::SharedPtr<ejson::internal::String> tmpElement = ejson::internal::String::create();
if (tmpElement == nullptr) {
if (tmpElement == null) {
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in String");
_pos=iii;
return false;
}
tmpElement->iParse(_data, iii, _filePos, _doc);
m_value.push_back(tmpElement);
m_value.pushBack(tmpElement);
} else if (_data[iii] == '[') {
// find a list:
EJSON_PARSE_ELEMENT("find List");
ememory::SharedPtr<ejson::internal::Array> tmpElement = ejson::internal::Array::create();
if (tmpElement == nullptr) {
if (tmpElement == null) {
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in Array");
_pos=iii;
return false;
}
tmpElement->iParse(_data, iii, _filePos, _doc);
m_value.push_back(tmpElement);
m_value.pushBack(tmpElement);
} else if ( ( _data[iii] == 'f'
&& iii+4 < _data.size()
&& _data[iii+1] == 'a'
@ -95,13 +95,13 @@ bool ejson::internal::Array::iParse(const std::string& _data, size_t& _pos, ejso
// find boolean:
EJSON_PARSE_ELEMENT("find Boolean");
ememory::SharedPtr<ejson::internal::Boolean> tmpElement = ejson::internal::Boolean::create();
if (tmpElement == nullptr) {
if (tmpElement == null) {
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in Boolean");
_pos=iii;
return false;
}
tmpElement->iParse(_data, iii, _filePos, _doc);
m_value.push_back(tmpElement);
m_value.pushBack(tmpElement);
} else if ( _data[iii] == 'n'
&& iii+3 < _data.size()
&& _data[iii+1] == 'u'
@ -110,24 +110,24 @@ bool ejson::internal::Array::iParse(const std::string& _data, size_t& _pos, ejso
// find null:
EJSON_PARSE_ELEMENT("find Null");
ememory::SharedPtr<ejson::internal::Null> tmpElement = ejson::internal::Null::create();
if (tmpElement == nullptr) {
if (tmpElement == null) {
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in Boolean");
_pos = iii;
return false;
}
tmpElement->iParse(_data, iii, _filePos, _doc);
m_value.push_back(tmpElement);
m_value.pushBack(tmpElement);
} else if (checkNumber(_data[iii]) == true) {
// find number:
EJSON_PARSE_ELEMENT("find Number");
ememory::SharedPtr<ejson::internal::Number> tmpElement = ejson::internal::Number::create();
if (tmpElement == nullptr) {
if (tmpElement == null) {
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in Boolean");
_pos=iii;
return false;
}
tmpElement->iParse(_data, iii, _filePos, _doc);
m_value.push_back(tmpElement);
m_value.pushBack(tmpElement);
} else if (_data[iii] == ',') {
// find Separator : Restart cycle ...
// TODO : check if element are separated with ','
@ -139,7 +139,7 @@ bool ejson::internal::Array::iParse(const std::string& _data, size_t& _pos, ejso
return false;
} else {
// find an error ....
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, std::string("Find '") + _data[iii] + "' with no element in the element...");
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, etk::String("Find '") + _data[iii] + "' with no element in the element...");
// move the curent index
_pos = iii+1;
return false;
@ -150,26 +150,26 @@ bool ejson::internal::Array::iParse(const std::string& _data, size_t& _pos, ejso
}
bool ejson::internal::Array::iGenerate(std::string& _data, size_t _indent) const {
bool ejson::internal::Array::iGenerate(etk::String& _data, size_t _indent) const {
bool oneLine=true;
if (m_value.size()>3) {
oneLine=false;
} else {
for (size_t iii=0; iii<m_value.size() ; iii++) {
const ememory::SharedPtr<ejson::internal::Value> tmp = m_value[iii];
if (tmp == nullptr) {
if (tmp == null) {
continue;
}
if ( tmp->getType() == ejson::valueType::object
|| tmp->getType() == ejson::valueType::document) {
if ( tmp->getType() == ejson::valueType::Object
|| tmp->getType() == ejson::valueType::Document) {
oneLine=false;
break;
}
if (tmp->getType() == ejson::valueType::array) {
if (tmp->getType() == ejson::valueType::Array) {
oneLine=false;
break;
}
if (tmp->getType() == ejson::valueType::string) {
if (tmp->getType() == ejson::valueType::String) {
const ememory::SharedPtr<ejson::internal::String> tmp2 = ememory::staticPointerCast<ejson::internal::String>(tmp);
if(tmp2->get().size()>40) {
oneLine=false;
@ -187,7 +187,7 @@ bool ejson::internal::Array::iGenerate(std::string& _data, size_t _indent) const
if (false == oneLine) {
addIndent(_data, _indent);
}
if (m_value[iii] != nullptr) {
if (m_value[iii] != null) {
m_value[iii]->iGenerate(_data, _indent+1);
if (iii<m_value.size()-1) {
_data += ",";
@ -206,11 +206,11 @@ bool ejson::internal::Array::iGenerate(std::string& _data, size_t _indent) const
return true;
}
void ejson::internal::Array::iMachineGenerate(std::string& _data) const {
void ejson::internal::Array::iMachineGenerate(etk::String& _data) const {
_data += "[";
bool needComa = false;
for (size_t iii=0; iii<m_value.size() ; iii++) {
if (m_value[iii] == nullptr) {
if (m_value[iii] == null) {
continue;
}
if (needComa == true) {
@ -235,11 +235,11 @@ const ememory::SharedPtr<ejson::internal::Value> ejson::internal::Array::get(siz
}
bool ejson::internal::Array::add(ememory::SharedPtr<ejson::internal::Value> _element) {
if (_element == nullptr) {
EJSON_ERROR("Request add on an nullptr pointer");
if (_element == null) {
EJSON_ERROR("Request add on an null pointer");
return false;
}
m_value.push_back(_element);
m_value.pushBack(_element);
return true;
}
@ -252,11 +252,11 @@ void ejson::internal::Array::remove(size_t _id) {
bool ejson::internal::Array::transfertIn(ememory::SharedPtr<ejson::internal::Value> _obj) {
if (_obj == nullptr) {
EJSON_ERROR("Request transfer on an nullptr pointer");
if (_obj == null) {
EJSON_ERROR("Request transfer on an null pointer");
return false;
}
if (_obj->getType() != ejson::valueType::array) {
if (_obj->getType() != ejson::valueType::Array) {
EJSON_ERROR("Request transfer on an element that is not an Array");
return false;
}
@ -273,13 +273,13 @@ bool ejson::internal::Array::transfertIn(ememory::SharedPtr<ejson::internal::Val
// TODO : Manage error ...
ememory::SharedPtr<ejson::internal::Value> ejson::internal::Array::clone() const {
ememory::SharedPtr<ejson::internal::Array> output = ejson::internal::Array::create();
if (output == nullptr) {
if (output == null) {
EJSON_ERROR("Allocation error ...");
return ememory::SharedPtr<ejson::internal::Value>();
}
for (size_t iii=0; iii<m_value.size(); ++iii) {
ememory::SharedPtr<const ejson::internal::Value> val = m_value[iii];
if (val == nullptr) {
if (val == null) {
continue;
}
output->add(val->clone());

View File

@ -1,7 +1,7 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#pragma once
@ -19,7 +19,7 @@ namespace ejson {
* @brief basic element of a xml structure
*/
Array() {
m_type = ejson::valueType::array;
m_type = ejson::valueType::Array;
}
public:
/**
@ -28,7 +28,7 @@ namespace ejson {
*/
static ememory::SharedPtr<Array> create();
private:
std::vector<ememory::SharedPtr<ejson::internal::Value> > m_value; //!< vector of sub elements
etk::Vector<ememory::SharedPtr<ejson::internal::Value> > m_value; //!< vector of sub elements
public:
/**
* @brief get the number of sub element in the current one
@ -38,13 +38,13 @@ namespace ejson {
/**
* @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.
* @return null if the element does not exist.
*/
ememory::SharedPtr<ejson::internal::Value> get(size_t _id);
/**
* @brief get the const pointer on an element reference with his ID.
* @param[in] _id Id of the element.
* @return nullptr if the element does not exist.
* @return null if the element does not exist.
*/
const ememory::SharedPtr<ejson::internal::Value> get(size_t _id) const;
/**
@ -59,9 +59,9 @@ namespace ejson {
*/
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 iMachineGenerate(std::string& _data) const override;
bool iParse(const etk::String& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::internal::Document& _doc) override;
bool iGenerate(etk::String& _data, size_t _indent) const override;
void iMachineGenerate(etk::String& _data) const override;
void clear() override;
bool transfertIn(ememory::SharedPtr<ejson::internal::Value> _obj) override;
ememory::SharedPtr<ejson::internal::Value> clone() const override;

View File

@ -1,7 +1,7 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#include <ejson/internal/Boolean.hpp>
@ -9,12 +9,12 @@
#include <ejson/internal/Document.hpp>
ememory::SharedPtr<ejson::internal::Boolean> ejson::internal::Boolean::create(bool _value) {
return ememory::SharedPtr<ejson::internal::Boolean>(new ejson::internal::Boolean(_value));
return ememory::SharedPtr<ejson::internal::Boolean>(ETK_NEW(ejson::internal::Boolean, _value));
}
ejson::internal::Boolean::Boolean(bool _value) :
m_value(_value) {
m_type = ejson::valueType::boolean;
m_type = ejson::valueType::Boolean;
}
void ejson::internal::Boolean::set(bool _value) {
@ -25,7 +25,7 @@ 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) {
bool ejson::internal::Boolean::iParse(const etk::String& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::internal::Document& _doc) {
EJSON_PARSE_ELEMENT("start parse : 'Boolean' ");
m_value=false;
if( _data[_pos] == 't'
@ -54,7 +54,7 @@ bool ejson::internal::Boolean::iParse(const std::string& _data, size_t& _pos, ej
}
bool ejson::internal::Boolean::iGenerate(std::string& _data, size_t _indent) const {
bool ejson::internal::Boolean::iGenerate(etk::String& _data, size_t _indent) const {
if (m_value == true) {
_data += "true";
} else {
@ -63,7 +63,7 @@ bool ejson::internal::Boolean::iGenerate(std::string& _data, size_t _indent) con
return true;
}
void ejson::internal::Boolean::iMachineGenerate(std::string& _data) const {
void ejson::internal::Boolean::iMachineGenerate(etk::String& _data) const {
if (m_value == true) {
_data += "true";
} else {
@ -73,11 +73,11 @@ void ejson::internal::Boolean::iMachineGenerate(std::string& _data) const {
bool ejson::internal::Boolean::transfertIn(ememory::SharedPtr<ejson::internal::Value> _obj) {
if (_obj == nullptr) {
if (_obj == null) {
EJSON_ERROR("Request transfer on an NULL pointer");
return false;
}
if (_obj->getType() != ejson::valueType::boolean) {
if (_obj->getType() != ejson::valueType::Boolean) {
EJSON_ERROR("Request transfer on an element that is not an Boolean");
return false;
}
@ -90,7 +90,7 @@ bool ejson::internal::Boolean::transfertIn(ememory::SharedPtr<ejson::internal::V
ememory::SharedPtr<ejson::internal::Value> ejson::internal::Boolean::clone() const {
ememory::SharedPtr<ejson::internal::Boolean> output = ejson::internal::Boolean::create(m_value);
if (output == nullptr) {
if (output == null) {
EJSON_ERROR("Allocation error ...");
return ememory::SharedPtr<ejson::internal::Value>();
}

View File

@ -1,7 +1,7 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#pragma once
@ -41,9 +41,9 @@ namespace ejson {
*/
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;
void iMachineGenerate(std::string& _data) const override;
bool iParse(const etk::String& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::internal::Document& _doc) override;
bool iGenerate(etk::String& _data, size_t _indent) const override;
void iMachineGenerate(etk::String& _data) const override;
bool transfertIn(ememory::SharedPtr<ejson::internal::Value> _obj) override;
ememory::SharedPtr<ejson::internal::Value> clone() const override;
};

View File

@ -1,12 +1,11 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#include <ejson/internal/Document.hpp>
#include <ejson/debug.hpp>
#include <etk/os/FSNode.hpp>
#include <ejson/internal/Object.hpp>
#include <ejson/internal/Array.hpp>
@ -14,9 +13,11 @@
#include <ejson/internal/Null.hpp>
#include <ejson/internal/Number.hpp>
#include <ejson/internal/Boolean.hpp>
#include <etk/path/fileSystem.hpp>
#include <etk/uri/uri.hpp>
ememory::SharedPtr<ejson::internal::Document> ejson::internal::Document::create() {
return ememory::SharedPtr<ejson::internal::Document>(new ejson::internal::Document());
return ememory::SharedPtr<ejson::internal::Document>(ETK_NEW(ejson::internal::Document));
}
ejson::internal::Document::Document() :
@ -24,16 +25,16 @@ ejson::internal::Document::Document() :
m_comment(""),
m_Line(""),
m_filePos(0,0) {
m_type = ejson::valueType::document;
m_type = ejson::valueType::Document;
}
bool ejson::internal::Document::iGenerate(std::string& _data, size_t _indent) const {
bool ejson::internal::Document::iGenerate(etk::String& _data, size_t _indent) const {
ejson::internal::Object::iGenerate(_data, _indent+1);
_data += "\n";
return true;
}
bool ejson::internal::Document::parse(const std::string& _data) {
bool ejson::internal::Document::parse(const etk::String& _data) {
EJSON_VERBOSE("Start parsing document (type: string) size=" << _data.size());
clear();
ejson::FilePos filePos(1,0);
@ -41,67 +42,57 @@ bool ejson::internal::Document::parse(const std::string& _data) {
return iParse(_data, parsePos, filePos, *this);
}
bool ejson::internal::Document::generate(std::string& _data) {
bool ejson::internal::Document::generate(etk::String& _data) {
_data = "";
return iGenerate(_data,0);
}
bool ejson::internal::Document::load(const std::string& _file) {
// Start loading the XML :
EJSON_VERBOSE("open file (xml) \"" << _file << "\"");
bool ejson::internal::Document::load(const etk::Uri& _uri) {
// Start loading the json :
EJSON_VERBOSE("open file (json) " << _uri);
clear();
etk::FSNode tmpFile(_file);
if (false == tmpFile.exist()) {
EJSON_ERROR("File Does not exist : " << _file);
auto fileIo = etk::uri::get(_uri);
if (fileIo == null) {
EJSON_ERROR("File Does not exist : " << _uri);
return false;
}
int64_t fileSize = tmpFile.fileSize();
if (0 == fileSize) {
EJSON_ERROR("This file is empty : " << _file);
if (fileIo->open(etk::io::OpenMode::Read) == false) {
EJSON_ERROR("Can not open (r) the file : " << _uri);
return false;
}
if (false == tmpFile.fileOpenRead()) {
EJSON_ERROR("Can not open (r) the file : " << _file);
return false;
}
// allocate data
std::vector<char> fileBuffer;
fileBuffer.resize(fileSize+5, 0);
// load data from the file :
tmpFile.fileRead(&fileBuffer[0], 1, fileSize);
// load data from the file:
etk::String tmpDataUnicode = fileIo->readAllString();
// close the file:
tmpFile.fileClose();
std::string tmpDataUnicode(&fileBuffer[0]);
fileIo->close();
// parse the data :
bool ret = parse(tmpDataUnicode);
//Display();
return ret;
}
bool ejson::internal::Document::store(const std::string& _file) {
std::string createData;
if (false == generate(createData)) {
EJSON_ERROR("Error while creating the XML : " << _file);
bool ejson::internal::Document::store(const etk::Uri& _uri) {
etk::String createData;
if (generate(createData) == false) {
EJSON_ERROR("Error while creating the JSON : " << _uri);
return false;
}
etk::FSNode tmpFile(_file);
if (false == tmpFile.fileOpenWrite()) {
EJSON_ERROR("Can not open (w) the file : " << _file);
auto fileIo = etk::uri::get(_uri);
if (fileIo == null) {
EJSON_ERROR("Can not create the uri: " << _uri);
return false;
}
if (tmpFile.fileWrite((char*)createData.c_str(), sizeof(char), createData.size()) != (int32_t)createData.size()) {
EJSON_ERROR("Error while writing output XML file : " << _file);
tmpFile.fileClose();
if (fileIo->open(etk::io::OpenMode::Write) == false) {
EJSON_ERROR("Can not open (r) the file : " << _uri);
return false;
}
tmpFile.fileClose();
fileIo->writeAll(createData);
fileIo->close();
return true;
}
static std::string createPosPointer(const std::string& _line, size_t _pos) {
std::string out;
static etk::String createPosPointer(const etk::String& _line, size_t _pos) {
etk::String out;
size_t iii;
for (iii=0; iii<_pos && iii<_line.size(); iii++) {
if (_line[iii] == '\t') {
@ -117,7 +108,7 @@ static std::string createPosPointer(const std::string& _line, size_t _pos) {
return out;
}
bool ejson::internal::Document::iParse(const std::string& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::internal::Document& _doc) {
bool ejson::internal::Document::iParse(const etk::String& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::internal::Document& _doc) {
EJSON_PARSE_ELEMENT("start parse : 'Document' ");
bool haveMainNode=false;
bool nodeParsed=false;
@ -192,10 +183,10 @@ void ejson::internal::Document::displayError() {
#endif
}
void ejson::internal::Document::createError(const std::string& _data,
void ejson::internal::Document::createError(const etk::String& _data,
size_t _pos,
const ejson::FilePos& _filePos,
const std::string& _comment) {
const etk::String& _comment) {
m_comment = _comment;
m_Line = etk::extract_line(_data, _pos);
m_filePos = _filePos;

View File

@ -1,16 +1,17 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#pragma once
#include <ejson/internal/Value.hpp>
#include <vector>
#include <etk/Vector.hpp>
#include <etk/types.hpp>
#include <ejson/internal/String.hpp>
#include <ejson/internal/Array.hpp>
#include <ejson/internal/Object.hpp>
#include <etk/uri/Uri.hpp>
namespace ejson {
namespace internal {
@ -30,37 +31,37 @@ namespace ejson {
static ememory::SharedPtr<Document> create();
public:
/**
* @brief parse a string that contain an XML
* @brief parse a string that contain an json
* @param[in] _data Data to parse
* @return false : An error occured
* @return true : Parsing is OK
*/
bool parse(const std::string& _data);
bool parse(const etk::String& _data);
/**
* @brief generate a string that contain the created XML
* @param[out] _data Data where the xml is stored
* @brief generate a string that contain the created json
* @param[out] _data Data where the json is stored
* @return false : An error occured
* @return true : Parsing is OK
*/
bool generate(std::string& _data);
bool generate(etk::String& _data);
/**
* @brief Load the file that might contain the xml
* @param[in] _file Filename of the xml (compatible with etk FSNode naming)
* @brief Load the file that might contain the json
* @param[in] _uri URI of the json
* @return false : An error occured
* @return true : Parsing is OK
*/
bool load(const std::string& _file);
bool load(const etk::Uri& _uri);
/**
* @brief Store the Xml in the file
* @param[in] _file Filename of the xml (compatible with etk FSNode naming)
* @brief Store the json in the file
* @param[in] _uri URI of the json
* @return false : An error occured
* @return true : Parsing is OK
*/
bool store(const std::string& _file);
bool store(const etk::Uri& _uri);
private:
bool m_writeErrorWhenDetexted; //!< Flag to know if we need to display error when they are detected
std::string m_comment; //!< Error comment
std::string m_Line; //!< Line with the error
etk::String m_comment; //!< Error comment
etk::String m_Line; //!< Line with the error
ejson::FilePos m_filePos; //!< Position in the file of the error
public:
/**
@ -85,16 +86,16 @@ namespace ejson {
* @param[in] _filePos Position in x/y in the file
* @param[in] _comment Help coment
*/
void createError(const std::string& _data,
void createError(const etk::String& _data,
size_t _pos,
const ejson::FilePos& _filePos,
const std::string& _comment);
const etk::String& _comment);
public:
bool iParse(const std::string& _data,
bool iParse(const etk::String& _data,
size_t& _pos,
ejson::FilePos& _filePos,
ejson::internal::Document& _doc) override;
bool iGenerate(std::string& _data, size_t _indent) const override;
bool iGenerate(etk::String& _data, size_t _indent) const override;
};
}
}

View File

@ -1,7 +1,7 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#include <ejson/internal/Null.hpp>
@ -9,14 +9,14 @@
#include <ejson/internal/Document.hpp>
ememory::SharedPtr<ejson::internal::Null> ejson::internal::Null::create() {
return ememory::SharedPtr<ejson::internal::Null>(new ejson::internal::Null());
return ememory::SharedPtr<ejson::internal::Null>(ETK_NEW(ejson::internal::Null));
}
ejson::internal::Null::Null() {
m_type = ejson::valueType::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) {
bool ejson::internal::Null::iParse(const etk::String& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::internal::Document& _doc) {
EJSON_PARSE_ELEMENT("start parse : 'Null' ");
if (_pos+3 >= _data.size()){
EJSON_CREATE_ERROR(_doc, _data, _pos, _filePos, "can not parse null !!! ");
@ -35,22 +35,22 @@ bool ejson::internal::Null::iParse(const std::string& _data, size_t& _pos, ejson
}
bool ejson::internal::Null::iGenerate(std::string& _data, size_t _indent) const {
bool ejson::internal::Null::iGenerate(etk::String& _data, size_t _indent) const {
_data += "null";
return true;
}
void ejson::internal::Null::iMachineGenerate(std::string& _data) const {
void ejson::internal::Null::iMachineGenerate(etk::String& _data) const {
_data += "null";
}
bool ejson::internal::Null::transfertIn(ememory::SharedPtr<ejson::internal::Value> _obj) {
if (_obj == nullptr) {
EJSON_ERROR("Request transfer on an nullptr pointer");
if (_obj == null) {
EJSON_ERROR("Request transfer on an null pointer");
return false;
}
if (_obj->getType() == ejson::valueType::null) {
if (_obj->getType() == ejson::valueType::Null) {
EJSON_ERROR("Request transfer on an element that is not an Null");
return false;
}
@ -59,7 +59,7 @@ bool ejson::internal::Null::transfertIn(ememory::SharedPtr<ejson::internal::Valu
ememory::SharedPtr<ejson::internal::Value> ejson::internal::Null::clone() const {
ememory::SharedPtr<ejson::internal::Null> output = ejson::internal::Null::create();
if (output == nullptr) {
if (output == null) {
EJSON_ERROR("Allocation error ...");
return ememory::SharedPtr<ejson::internal::Value>();
}

View File

@ -1,7 +1,7 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#pragma once
@ -26,9 +26,9 @@ namespace ejson {
*/
static ememory::SharedPtr<Null> create();
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 iMachineGenerate(std::string& _data) const override;
bool iParse(const etk::String& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::internal::Document& _doc) override;
bool iGenerate(etk::String& _data, size_t _indent) const override;
void iMachineGenerate(etk::String& _data) const override;
bool transfertIn(ememory::SharedPtr<ejson::internal::Value> _obj) override;
ememory::SharedPtr<ejson::internal::Value> clone() const override;
};

View File

@ -1,7 +1,7 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
@ -10,36 +10,36 @@
#include <ejson/internal/Document.hpp>
ememory::SharedPtr<ejson::internal::Number> ejson::internal::Number::create(double _value) {
return ememory::SharedPtr<ejson::internal::Number>(new ejson::internal::Number(_value));
return ememory::SharedPtr<ejson::internal::Number>(ETK_NEW(ejson::internal::Number, _value));
}
ememory::SharedPtr<ejson::internal::Number> ejson::internal::Number::create(uint64_t _value) {
return ememory::SharedPtr<ejson::internal::Number>(new ejson::internal::Number(_value));
return ememory::SharedPtr<ejson::internal::Number>(ETK_NEW(ejson::internal::Number, _value));
}
ememory::SharedPtr<ejson::internal::Number> ejson::internal::Number::create(int64_t _value) {
return ememory::SharedPtr<ejson::internal::Number>(new ejson::internal::Number(_value));
return ememory::SharedPtr<ejson::internal::Number>(ETK_NEW(ejson::internal::Number, _value));
}
ejson::internal::Number::Number(double _value) :
m_typeNumber(ejson::internal::Number::type::tDouble),
m_value(_value) {
m_type = ejson::valueType::number;
m_type = ejson::valueType::Number;
}
ejson::internal::Number::Number(uint64_t _value) :
m_typeNumber(ejson::internal::Number::type::tUint),
m_valueU64(_value) {
m_type = ejson::valueType::number;
m_type = ejson::valueType::Number;
}
ejson::internal::Number::Number(int64_t _value) :
m_typeNumber(ejson::internal::Number::type::tInt),
m_valueI64(_value) {
m_type = ejson::valueType::number;
m_type = ejson::valueType::Number;
}
bool ejson::internal::Number::iParse(const std::string& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::internal::Document& _doc) {
bool ejson::internal::Number::iParse(const etk::String& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::internal::Document& _doc) {
EJSON_PARSE_ELEMENT("start parse : 'Number' ");
std::string tmpVal;
etk::String tmpVal;
bool isDouble = false;
for (size_t iii=_pos; iii<_data.size(); iii++) {
_filePos.check(_data[iii]);
@ -76,51 +76,51 @@ bool ejson::internal::Number::iParse(const std::string& _data, size_t& _pos, ejs
return false;
}
bool ejson::internal::Number::iGenerate(std::string& _data, size_t _indent) const {
bool ejson::internal::Number::iGenerate(etk::String& _data, size_t _indent) const {
if (m_typeNumber == ejson::internal::Number::type::tDouble) {
// special thing to remove .000000 at the end of perfect number ...
int64_t tmpVal = m_value;
if (double(tmpVal) == m_value) {
_data += etk::to_string(tmpVal);
_data += etk::toString(tmpVal);
} else {
_data += etk::to_string(m_value);
_data += etk::toString(m_value);
}
return true;
}
if (m_typeNumber == ejson::internal::Number::type::tInt) {
_data += etk::to_string(m_valueI64);
_data += etk::toString(m_valueI64);
return true;
}
_data += etk::to_string(m_valueU64);
_data += etk::toString(m_valueU64);
return true;
}
void ejson::internal::Number::iMachineGenerate(std::string& _data) const {
void ejson::internal::Number::iMachineGenerate(etk::String& _data) const {
if (m_typeNumber == ejson::internal::Number::type::tDouble) {
// special thing to remove .000000 at the end of perfect number ...
int64_t tmpVal = m_value;
if (double(tmpVal) == m_value) {
_data += etk::to_string(tmpVal);
_data += etk::toString(tmpVal);
} else {
_data += etk::to_string(m_value);
_data += etk::toString(m_value);
}
return;
}
if (m_typeNumber == ejson::internal::Number::type::tInt) {
_data += etk::to_string(m_valueI64);
_data += etk::toString(m_valueI64);
return;
}
_data += etk::to_string(m_valueU64);
_data += etk::toString(m_valueU64);
return;
}
bool ejson::internal::Number::transfertIn(ememory::SharedPtr<ejson::internal::Value> _obj) {
if (_obj == nullptr) {
EJSON_ERROR("Request transfer on an nullptr pointer");
if (_obj == null) {
EJSON_ERROR("Request transfer on an null pointer");
return false;
}
if (_obj->getType() != ejson::valueType::number) {
if (_obj->getType() != ejson::valueType::Number) {
EJSON_ERROR("Request transfer on an element that is not an Number");
return false;
}
@ -156,7 +156,7 @@ ememory::SharedPtr<ejson::internal::Value> ejson::internal::Number::clone() cons
output = ejson::internal::Number::create(m_valueU64);
break;
}
if (output == nullptr) {
if (output == null) {
EJSON_ERROR("Allocation error ...");
return ememory::SharedPtr<ejson::internal::Value>();
}

View File

@ -1,7 +1,7 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#pragma once
@ -80,9 +80,9 @@ namespace ejson {
*/
int64_t getI64() 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;
void iMachineGenerate(std::string& _data) const override;
bool iParse(const etk::String& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::internal::Document& _doc) override;
bool iGenerate(etk::String& _data, size_t _indent) const override;
void iMachineGenerate(etk::String& _data) const override;
bool transfertIn(ememory::SharedPtr<ejson::internal::Value> _obj) override;
ememory::SharedPtr<ejson::internal::Value> clone() const override;
};

View File

@ -1,7 +1,7 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
@ -16,9 +16,9 @@
ememory::SharedPtr<ejson::internal::Object> ejson::internal::Object::create() {
return ememory::SharedPtr<ejson::internal::Object>(new ejson::internal::Object());
return ememory::SharedPtr<ejson::internal::Object>(ETK_NEW(ejson::internal::Object));
}
ememory::SharedPtr<ejson::internal::Object> ejson::internal::Object::create(const std::string& _data) {
ememory::SharedPtr<ejson::internal::Object> ejson::internal::Object::create(const etk::String& _data) {
ejson::internal::Document doc;
doc.parse(_data);
return doc.cloneObj();
@ -36,9 +36,9 @@ enum statusParsing {
parseValue,
};
bool ejson::internal::Object::iParse(const std::string& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::internal::Document& _doc) {
bool ejson::internal::Object::iParse(const etk::String& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::internal::Document& _doc) {
enum statusParsing mode = parseName;
std::string currentName;
etk::String currentName;
EJSON_PARSE_ELEMENT("start parse : 'Object' ");
bool standalone = true;
size_t startPos = _pos+1;
@ -122,7 +122,7 @@ bool ejson::internal::Object::iParse(const std::string& _data, size_t& _pos, ejs
// find an object:
EJSON_PARSE_ELEMENT("find Object");
ememory::SharedPtr<ejson::internal::Object> tmpElement = ejson::internal::Object::create();
if (tmpElement == nullptr) {
if (tmpElement == null) {
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in object");
_pos=iii;
return false;
@ -135,7 +135,7 @@ bool ejson::internal::Object::iParse(const std::string& _data, size_t& _pos, ejs
// find a string:
EJSON_PARSE_ELEMENT("find String quoted");
ememory::SharedPtr<ejson::internal::String> tmpElement = ejson::internal::String::create();
if (tmpElement == nullptr) {
if (tmpElement == null) {
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in String");
_pos=iii;
return false;
@ -147,7 +147,7 @@ bool ejson::internal::Object::iParse(const std::string& _data, size_t& _pos, ejs
// find a list:
EJSON_PARSE_ELEMENT("find List");
ememory::SharedPtr<ejson::internal::Array> tmpElement = ejson::internal::Array::create();
if (tmpElement == nullptr) {
if (tmpElement == null) {
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in Array");
_pos=iii;
return false;
@ -160,7 +160,7 @@ bool ejson::internal::Object::iParse(const std::string& _data, size_t& _pos, ejs
// find boolean:
EJSON_PARSE_ELEMENT("find Boolean");
ememory::SharedPtr<ejson::internal::Boolean> tmpElement = ejson::internal::Boolean::create();
if (tmpElement == nullptr) {
if (tmpElement == null) {
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in Boolean");
_pos=iii;
return false;
@ -172,7 +172,7 @@ bool ejson::internal::Object::iParse(const std::string& _data, size_t& _pos, ejs
// find null:
EJSON_PARSE_ELEMENT("find Null");
ememory::SharedPtr<ejson::internal::Null> tmpElement = ejson::internal::Null::create();
if (tmpElement == nullptr) {
if (tmpElement == null) {
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in Boolean");
_pos=iii;
return false;
@ -184,7 +184,7 @@ bool ejson::internal::Object::iParse(const std::string& _data, size_t& _pos, ejs
// find number:
EJSON_PARSE_ELEMENT("find Number");
ememory::SharedPtr<ejson::internal::Number> tmpElement = ejson::internal::Number::create();
if (tmpElement == nullptr) {
if (tmpElement == null) {
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in Boolean");
_pos=iii;
return false;
@ -198,7 +198,7 @@ bool ejson::internal::Object::iParse(const std::string& _data, size_t& _pos, ejs
currentName = "";
} else {
// find an error ....
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, std::string("Find '") + _data[iii] + "' with no element in the element...");
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, etk::String("Find '") + _data[iii] + "' with no element in the element...");
// move the curent index
_pos = iii+1;
return false;
@ -207,36 +207,36 @@ bool ejson::internal::Object::iParse(const std::string& _data, size_t& _pos, ejs
}
}
_pos = _data.size();
if (false == standalone) {
if (standalone == false) {
return true;
}
return false;
}
bool ejson::internal::Object::iGenerate(std::string& _data, size_t _indent) const {
bool ejson::internal::Object::iGenerate(etk::String& _data, size_t _indent) const {
bool oneLine = true;
if (m_value.size()>3) {
oneLine = false;
} else if (_indent<=1) {
oneLine = false;
} else {
for (int32_t iii=0; iii<m_value.size() ; iii++) {
const ememory::SharedPtr<ejson::internal::Value> tmp = m_value[iii];
if (tmp == nullptr) {
for (size_t iii=0; iii<m_value.size() ; iii++) {
const ememory::SharedPtr<ejson::internal::Value> tmp = m_value.getValue(iii);
if (tmp == null) {
continue;
}
if ( tmp->getType() == ejson::valueType::object
|| tmp->getType() == ejson::valueType::document) {
oneLine=false;
if ( tmp->getType() == ejson::valueType::Object
|| tmp->getType() == ejson::valueType::Document) {
oneLine = false;
break;
}
if (tmp->getType() == ejson::valueType::array) {
oneLine=false;
if (tmp->getType() == ejson::valueType::Array) {
oneLine = false;
break;
}
if (tmp->getType() == ejson::valueType::string) {
if (tmp->getType() == ejson::valueType::String) {
const ememory::SharedPtr<ejson::internal::String> tmp2 = ememory::staticPointerCast<ejson::internal::String>(tmp);
if( tmp2->get().size()>25
|| m_value.getKey(iii).size()>25) {
if( tmp2->get().size() > 25
|| m_value.getKey(iii).size() > 25) {
oneLine=false;
break;
}
@ -248,7 +248,7 @@ bool ejson::internal::Object::iGenerate(std::string& _data, size_t _indent) cons
} else {
_data += "{\n";
}
for (int32_t iii=0; iii<m_value.size(); ++iii) {
for (size_t iii=0; iii<m_value.size(); ++iii) {
if (oneLine == false) {
addIndent(_data, _indent);
}
@ -256,7 +256,7 @@ bool ejson::internal::Object::iGenerate(std::string& _data, size_t _indent) cons
_data += m_value.getKey(iii);
_data += "\": ";
m_value.getValue(iii)->iGenerate(_data, _indent+1);
if (iii<m_value.size()-1) {
if (iii < m_value.size()-1) {
_data += ",";
}
if (oneLine == true) {
@ -272,10 +272,10 @@ bool ejson::internal::Object::iGenerate(std::string& _data, size_t _indent) cons
return true;
}
void ejson::internal::Object::iMachineGenerate(std::string& _data) const {
void ejson::internal::Object::iMachineGenerate(etk::String& _data) const {
_data += "{";
bool needComa = false;
for (int32_t iii=0; iii<m_value.size(); ++iii) {
for (size_t iii=0; iii<m_value.size(); ++iii) {
if (needComa == true) {
_data += ",";
}
@ -288,11 +288,11 @@ void ejson::internal::Object::iMachineGenerate(std::string& _data) const {
_data += "}";
}
bool ejson::internal::Object::exist(const std::string& _name) const {
bool ejson::internal::Object::exist(const etk::String& _name) const {
return m_value.exist(_name);
}
std::vector<std::string> ejson::internal::Object::getKeys() const {
etk::Vector<etk::String> ejson::internal::Object::getKeys() const {
return m_value.getKeys();
}
@ -301,33 +301,33 @@ size_t ejson::internal::Object::size() const {
}
ememory::SharedPtr<ejson::internal::Value> ejson::internal::Object::get(size_t _id) {
return m_value[_id];
return m_value.getValue(_id);
}
const ememory::SharedPtr<ejson::internal::Value> ejson::internal::Object::get(size_t _id) const{
return m_value[_id];
return m_value.getValue(_id);
}
ememory::SharedPtr<ejson::internal::Value> ejson::internal::Object::get(const std::string& _name) {
ememory::SharedPtr<ejson::internal::Value> ejson::internal::Object::get(const etk::String& _name) {
if (m_value.exist(_name) == false) {
return ememory::SharedPtr<ejson::internal::Value>();
}
return m_value[_name];
}
const ememory::SharedPtr<ejson::internal::Value> ejson::internal::Object::get(const std::string& _name) const {
const ememory::SharedPtr<ejson::internal::Value> ejson::internal::Object::get(const etk::String& _name) const {
if (m_value.exist(_name) == false) {
return ememory::SharedPtr<ejson::internal::Value>();
}
return m_value[_name];
}
std::string ejson::internal::Object::getKey(size_t _id) const {
etk::String ejson::internal::Object::getKey(size_t _id) const {
return m_value.getKey(_id);
}
bool ejson::internal::Object::add(const std::string& _name, ememory::SharedPtr<ejson::internal::Value> _value) {
if (_value == nullptr) {
bool ejson::internal::Object::add(const etk::String& _name, ememory::SharedPtr<ejson::internal::Value> _value) {
if (_value == null) {
return false;
}
if (_name.size() == 0) {
@ -341,21 +341,21 @@ bool ejson::internal::Object::add(const std::string& _name, ememory::SharedPtr<e
return true;
}
void ejson::internal::Object::remove(const std::string& _name) {
m_value.remove(_name);
void ejson::internal::Object::remove(const etk::String& _name) {
m_value.erase(_name);
}
void ejson::internal::Object::remove(size_t _id) {
m_value.remove(getKey(_id));
m_value.erase(getKey(_id));
}
bool ejson::internal::Object::transfertIn(ememory::SharedPtr<ejson::internal::Value> _obj) {
if (_obj == nullptr) {
EJSON_ERROR("Request transfer on an nullptr pointer");
if (_obj == null) {
EJSON_ERROR("Request transfer on an null pointer");
return false;
}
if ( _obj->getType() != ejson::valueType::object
&& _obj->getType() != ejson::valueType::document) {
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;
}
@ -370,11 +370,11 @@ bool ejson::internal::Object::transfertIn(ememory::SharedPtr<ejson::internal::Va
}
bool ejson::internal::Object::cloneIn(ememory::SharedPtr<ejson::internal::Object>& _obj) const {
if (_obj == nullptr) {
if (_obj == null) {
return false;
}
_obj->clear();
for (int32_t iii=0; iii<m_value.size(); ++iii) {
for (size_t iii=0; iii<m_value.size(); ++iii) {
_obj->add(m_value.getKey(iii), m_value[iii]->clone());
}
return true;
@ -388,14 +388,14 @@ ememory::SharedPtr<ejson::internal::Value> ejson::internal::Object::clone() cons
ememory::SharedPtr<ejson::internal::Object> ejson::internal::Object::cloneObj() const {
ememory::SharedPtr<ejson::internal::Object> output = ejson::internal::Object::create();
if (output == nullptr) {
if (output == null) {
EJSON_ERROR("Allocation error ...");
return ememory::SharedPtr<ejson::internal::Object>();
}
for (int32_t iii=0; iii<m_value.size(); ++iii) {
for (size_t iii=0; iii<m_value.size(); ++iii) {
ememory::SharedPtr<ejson::internal::Value> val = m_value.getValue(iii);
std::string key = m_value.getKey(iii);
if (val == nullptr) {
etk::String key = m_value.getKey(iii);
if (val == null) {
continue;
}
output->add(key, val->clone());

View File

@ -1,13 +1,12 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <etk/Hash.hpp>
#include <algorithm>
#include <etk/Map.hpp>
#include <ejson/internal/Value.hpp>
namespace ejson {
@ -20,8 +19,9 @@ namespace ejson {
/**
* @brief basic element of a xml structure
*/
Object() {
m_type = ejson::valueType::object;
Object() :
m_value(0, false) { // Force unorder map
m_type = ejson::valueType::Object;
};
public:
/**
@ -34,35 +34,34 @@ namespace ejson {
* @param[in] _data Json stream to parse and interprete
* @return A SharedPtr on the Object value
*/
static ememory::SharedPtr<Object> create(const std::string& _data);
static ememory::SharedPtr<Object> create(const etk::String& _data);
protected:
// TODO : Change this with a generic methode ...
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 ...)
etk::Map<etk::String, 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:
/**
* @brief check if an element exist.
* @param[in] _name name of the object.
* @return The existance of the element.
*/
bool exist(const std::string& _name) const;
bool exist(const etk::String& _name) const;
/**
* @brief get the sub element with his name (no cast check)
* @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
* @return pointer on the element requested or null if it not the corect type or does not existed
*/
ememory::SharedPtr<ejson::internal::Value> get(const std::string& _name);
ememory::SharedPtr<ejson::internal::Value> get(const etk::String& _name);
/**
* @brief get the sub element with his name (no cast check)
* @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
* @return pointer on the element requested or null if it not the corect type or does not existed
*/
const ememory::SharedPtr<ejson::internal::Value> get(const std::string& _name) const;
const ememory::SharedPtr<ejson::internal::Value> get(const etk::String& _name) const;
public:
/**
* @brief Get all the element name (keys).
* @return a vector of all name (key).
*/
std::vector<std::string> getKeys() const;
etk::Vector<etk::String> getKeys() const;
/**
* @brief get the number of sub element in the current one
* @return the Number of stored element
@ -71,13 +70,13 @@ namespace ejson {
/**
* @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.
* @return null if the element does not exist.
*/
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.
* @return null if the element does not exist.
*/
const ememory::SharedPtr<ejson::internal::Value> get(size_t _id) const;
/**
@ -85,7 +84,7 @@ namespace ejson {
* @param[in] _id Id of the element.
* @return The name (key).
*/
std::string getKey(size_t _id) const;
etk::String getKey(size_t _id) const;
public:
/**
* @brief add an element in the Object
@ -93,12 +92,12 @@ namespace ejson {
* @param[in] _value Element to add
* @return false if an error occured
*/
bool add(const std::string& _name, ememory::SharedPtr<ejson::internal::Value> _value);
bool add(const etk::String& _name, ememory::SharedPtr<ejson::internal::Value> _value);
/**
* @brief Remove Value with his name
* @param[in] _name Name of the object
*/
void remove(const std::string& _name);
void remove(const etk::String& _name);
/**
* @brief Remove Value with his id
* @param[in] _id Id of the element.
@ -116,9 +115,9 @@ namespace ejson {
*/
ememory::SharedPtr<ejson::internal::Object> cloneObj() 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;
void iMachineGenerate(std::string& _data) const override;
bool iParse(const etk::String& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::internal::Document& _doc) override;
bool iGenerate(etk::String& _data, size_t _indent) const override;
void iMachineGenerate(etk::String& _data) const override;
void clear() override;
bool transfertIn(ememory::SharedPtr<ejson::internal::Value> _obj) override;
ememory::SharedPtr<ejson::internal::Value> clone() const override;

View File

@ -1,7 +1,7 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
@ -11,24 +11,24 @@
#include <ejson/internal/String.hpp>
#include <ejson/debug.hpp>
ememory::SharedPtr<ejson::internal::String> ejson::internal::String::create(const std::string& _value) {
return ememory::SharedPtr<ejson::internal::String>(new ejson::internal::String(_value));
ememory::SharedPtr<ejson::internal::String> ejson::internal::String::create(const etk::String& _value) {
return ememory::SharedPtr<ejson::internal::String>(ETK_NEW(ejson::internal::String, _value));
}
ejson::internal::String::String(const std::string& _value) :
ejson::internal::String::String(const etk::String& _value) :
m_value(_value) {
m_type = ejson::valueType::string;
m_type = ejson::valueType::String;
}
void ejson::internal::String::set(const std::string& _value) {
void ejson::internal::String::set(const etk::String& _value) {
m_value = _value;
}
const std::string& ejson::internal::String::get() const {
const etk::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) {
bool ejson::internal::String::iParse(const etk::String& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::internal::Document& _doc) {
EJSON_PARSE_ELEMENT("start parse : 'String' ");
char end = _data[_pos];
bool backslashPrevious = false;
@ -67,7 +67,7 @@ bool ejson::internal::String::iParse(const std::string& _data, size_t& _pos, ejs
}
bool ejson::internal::String::iGenerate(std::string& _data, size_t _indent) const {
bool ejson::internal::String::iGenerate(etk::String& _data, size_t _indent) const {
_data += "\"";
for (auto &it: m_value) {
if ( it == '\\'
@ -79,7 +79,7 @@ bool ejson::internal::String::iGenerate(std::string& _data, size_t _indent) cons
_data += "\"";
return true;
}
void ejson::internal::String::iMachineGenerate(std::string& _data) const {
void ejson::internal::String::iMachineGenerate(etk::String& _data) const {
_data += "\"";
for (auto &it: m_value) {
if ( it == '\\'
@ -92,11 +92,11 @@ void ejson::internal::String::iMachineGenerate(std::string& _data) const {
}
bool ejson::internal::String::transfertIn(ememory::SharedPtr<ejson::internal::Value> _obj) {
if (_obj == nullptr) {
EJSON_ERROR("Request transfer on an nullptr pointer");
if (_obj == null) {
EJSON_ERROR("Request transfer on an null pointer");
return false;
}
if (_obj->getType() != ejson::valueType::string) {
if (_obj->getType() != ejson::valueType::String) {
EJSON_ERROR("Request transfer on an element that is not an String");
return false;
}
@ -108,7 +108,7 @@ bool ejson::internal::String::transfertIn(ememory::SharedPtr<ejson::internal::Va
ememory::SharedPtr<ejson::internal::Value> ejson::internal::String::clone() const {
ememory::SharedPtr<ejson::internal::String> output = ejson::internal::String::create(m_value);
if (output == nullptr) {
if (output == null) {
EJSON_ERROR("Allocation error ...");
return ememory::SharedPtr<ejson::internal::Value>();
}

View File

@ -1,7 +1,7 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#pragma once
@ -19,31 +19,31 @@ namespace ejson {
* @brief basic element of a xml structure
* @param[in] _value Value to set on the ejson::Value
*/
String(const std::string& _value="");
String(const etk::String& _value="");
public:
/**
* @brief Create factory on the ejson::internal::String
* @param[in] _value Value to set on the ejson::Value
* @return A SharedPtr on the String value
*/
static ememory::SharedPtr<String> create(const std::string& _value="");
static ememory::SharedPtr<String> create(const etk::String& _value="");
protected:
std::string m_value; //!< value of the node (for element this is the name, for text it is the inside text ...)
etk::String m_value; //!< value of the node (for element this is the name, for text it is the inside text ...)
public:
/**
* @brief set the value of the node.
* @param[in] _value New value of the node.
*/
void set(const std::string& _value);
void set(const etk::String& _value);
/**
* @brief get the current element Value.
* @return the reference of the string value.
*/
const std::string& get() const;
const etk::String& 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;
void iMachineGenerate(std::string& _data) const override;
bool iParse(const etk::String& _data, size_t& _pos, ejson::FilePos& _filePos, ejson::internal::Document& _doc) override;
bool iGenerate(etk::String& _data, size_t _indent) const override;
void iMachineGenerate(etk::String& _data) const override;
bool transfertIn(ememory::SharedPtr<ejson::internal::Value> _obj) override;
ememory::SharedPtr<ejson::internal::Value> clone() const override;
};

View File

@ -1,7 +1,7 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#include <ejson/internal/Value.hpp>
@ -27,7 +27,7 @@ bool ejson::internal::Value::isWhiteChar(char32_t _val) {
return false;
}
void ejson::internal::Value::addIndent(std::string& _data, int32_t _indent) const {
void ejson::internal::Value::addIndent(etk::String& _data, int32_t _indent) const {
if (_indent <= 0) {
return;
}
@ -46,7 +46,7 @@ void ejson::internal::Value::drawElementParsed(char32_t _val, const ejson::FileP
}
}
int32_t ejson::internal::Value::countWhiteChar(const std::string& _data, size_t _pos, ejson::FilePos& _filePos) const {
int32_t ejson::internal::Value::countWhiteChar(const etk::String& _data, size_t _pos, ejson::FilePos& _filePos) const {
_filePos.clear();
size_t white=0;
for (size_t iii=_pos; iii<_data.size(); iii++) {
@ -113,7 +113,7 @@ bool ejson::internal::Value::checkNumber(char32_t _val) const {
}
void ejson::internal::Value::display() const {
std::string tmpp;
etk::String tmpp;
iGenerate(tmpp, 0);
EJSON_INFO("Generated JSON : \n" << tmpp);
}

View File

@ -1,7 +1,7 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#pragma once
@ -53,8 +53,8 @@ namespace ejson {
* @brief basic element of a xml structure
*/
Value() :
m_type(ejson::valueType::unknow) {
m_type = ejson::valueType::value;
m_type(ejson::valueType::Unknow) {
m_type = ejson::valueType::Value;
};
public:
/**
@ -70,7 +70,7 @@ namespace ejson {
* @param[in,out] _doc Reference on the main document
* @return false if an error occured.
*/
virtual bool iParse(const std::string& _data,
virtual bool iParse(const etk::String& _data,
size_t& _pos,
ejson::FilePos& _filePos,
ejson::internal::Document& _doc) = 0;
@ -80,14 +80,14 @@ namespace ejson {
* @param[in] _indent current indentation of the file
* @return false if an error occured.
*/
virtual bool iGenerate(std::string& _data,
virtual bool iGenerate(etk::String& _data,
size_t _indent) const = 0;
/**
* @brief generate a string with the tree of the json (not human readable ==> for computer transfer)
* @param[in,out] _data string where to add the elements
* @return false if an error occured.
*/
virtual void iMachineGenerate(std::string& _data) const = 0;
virtual void iMachineGenerate(etk::String& _data) const = 0;
/**
* @brief Display the Document on console
*/
@ -98,7 +98,7 @@ namespace ejson {
* @param[in,out] _data String where the indentation is done.
* @param[in] _indent Number of tab to add at the string.
*/
void addIndent(std::string& _data, int32_t _indent) const;
void addIndent(etk::String& _data, int32_t _indent) const;
/**
* @brief Display the cuurent element that is curently parse.
* @param[in] _val Char that is parsed.
@ -126,7 +126,7 @@ namespace ejson {
* @param[out] _filePos new poistion of te file to add.
* @return number of white element.
*/
int32_t countWhiteChar(const std::string& _data, size_t _pos, ejson::FilePos& _filePos) const;
int32_t countWhiteChar(const etk::String& _data, size_t _pos, ejson::FilePos& _filePos) const;
public:
/**
* @brief clear the Node
@ -141,7 +141,7 @@ namespace ejson {
virtual bool transfertIn(ememory::SharedPtr<ejson::internal::Value> _obj);
/**
* @brief Copy the curent node and all the child in the curent one.
* @return nullptr in an error occured, the pointer on the element otherwise
* @return null in an error occured, the pointer on the element otherwise
*/
virtual ememory::SharedPtr<ejson::internal::Value> clone() const;
protected:

View File

@ -1,7 +1,7 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#pragma once
@ -118,6 +118,6 @@ namespace ejson {
* @brief Get Key of an element
* @return Key of the Element
*/
std::string getKey() const noexcept;
etk::String getKey() const noexcept;
};
}

View File

@ -1,7 +1,7 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#include <ejson/valueType.hpp>
@ -9,34 +9,34 @@
std::ostream& ejson::operator <<(std::ostream& _os, enum ejson::valueType _obj) {
etk::Stream& ejson::operator <<(etk::Stream& _os, enum ejson::valueType _obj) {
switch (_obj) {
case ejson::valueType::unknow:
_os << "ejson::valueType::unknow";
case ejson::valueType::Unknow:
_os << "ejson::valueType::Unknow";
break;
case ejson::valueType::value:
_os << "ejson::valueType::value";
case ejson::valueType::Value:
_os << "ejson::valueType::Value";
break;
case ejson::valueType::document:
_os << "ejson::valueType::document";
case ejson::valueType::Document:
_os << "ejson::valueType::Document";
break;
case ejson::valueType::array:
_os << "ejson::valueType::array";
case ejson::valueType::Array:
_os << "ejson::valueType::Array";
break;
case ejson::valueType::object:
_os << "ejson::valueType::object";
case ejson::valueType::Object:
_os << "ejson::valueType::Object";
break;
case ejson::valueType::string:
_os << "ejson::valueType::string";
case ejson::valueType::String:
_os << "ejson::valueType::String";
break;
case ejson::valueType::number:
_os << "ejson::valueType::number";
case ejson::valueType::Number:
_os << "ejson::valueType::Number";
break;
case ejson::valueType::null:
_os << "ejson::valueType::null";
case ejson::valueType::Null:
_os << "ejson::valueType::Null";
break;
case ejson::valueType::boolean:
_os << "ejson::valueType::boolean";
case ejson::valueType::Boolean:
_os << "ejson::valueType::Boolean";
break;
}
return _os;

View File

@ -1,28 +1,28 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#pragma once
#include <ostream>
#include <etk/Stream.hpp>
namespace ejson {
/**
* @brief Type of the JSON elements.
*/
enum class valueType {
unknow, //!< might be an error ...
value, //!< might be an error ...
document, //!< all the file main access
array, //!< te element [ ... ]
object, //!< the element { ... }
string, //!< the element "..."
number, //!< The element 1111.2222
null, //!< the element null
boolean, //!< the element true or false
Unknow, //!< might be an error ...
Value, //!< might be an error ...
Document, //!< all the file main access
Array, //!< te element [ ... ]
Object, //!< the element { ... }
String, //!< the element "..."
Number, //!< The element 1111.2222
Null, //!< the element null
Boolean, //!< the element true or false
};
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, enum valueType _obj);
etk::Stream& operator <<(etk::Stream& _os, enum valueType _obj);
}

View File

@ -1,13 +0,0 @@
Copyright ejson Edouard DUPIN
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@ -1,5 +1,5 @@
#!/usr/bin/python
import lutin.debug as debug
import realog.debug as debug
import lutin.tools as tools
def get_type():
@ -12,7 +12,7 @@ def get_desc():
return "e-json sample"
def get_licence():
return "APACHE-2"
return "MPL-2"
def get_compagny_type():
return "com"

View File

@ -1,5 +1,5 @@
#!/usr/bin/python
import lutin.debug as debug
import realog.debug as debug
import lutin.tools as tools
@ -16,7 +16,7 @@ def get_desc():
return "e-json test application"
def get_licence():
return "APACHE-2"
return "MPL-2"
def get_compagny_type():
return "com"
@ -29,11 +29,17 @@ def get_maintainer():
def configure(target, my_module):
my_module.add_src_file([
'test/test.cpp'
'test/test.cpp',
'test/testCommon.cpp',
'test/testDocument.cpp',
'test/testBoolean.cpp',
'test/testNull.cpp',
'test/testNumber.cpp',
'test/testAll.cpp',
])
my_module.add_depend([
'ejson',
'gtest',
'etest',
'test-debug'
])
return True

View File

@ -1,5 +1,5 @@
#!/usr/bin/python
import lutin.debug as debug
import realog.debug as debug
import lutin.tools as tools
@ -10,7 +10,7 @@ def get_desc():
return "Json parser and generator"
def get_licence():
return "APACHE-2"
return "MPL-2"
def get_compagny_type():
return "com"

View File

@ -1,7 +1,7 @@
/** @file
* @author Edouard DUPIN
* @copyright 2016, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#include <test-debug/debug.hpp>
@ -13,7 +13,7 @@ int main(int argc, const char *argv[]) {
// the only one init for etk:
etk::init(argc, argv);
for (int32_t iii=0; iii<argc ; ++iii) {
std::string data = argv[iii];
etk::String data = argv[iii];
if ( data == "-h"
|| data == "--help") {
TEST_PRINT("Help : ");

View File

@ -1,7 +1,7 @@
/** @file
* @author Edouard DUPIN
* @copyright 2016, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#include <test-debug/debug.hpp>
@ -16,7 +16,7 @@ static void readFromFile() {
ejson::Document doc;
//! [ejson_sample_declare_doc]
//! [ejson_sample_read_file]
bool retParse = doc.load("DATA:read.json");
bool retParse = doc.load(etk::Uri("DATA:///read.json"));
//! [ejson_sample_read_file]
TEST_INFO("parse ret = " << retParse);
TEST_INFO("Debug display of the tree:");
@ -27,7 +27,7 @@ static void readFromString1() {
ejson::Document doc;
TEST_INFO("parse");
//! [ejson_sample_read_stream1]
std::string stream = "{"
etk::String stream = "{"
" \"object A\":\"bonjour\","
" \"object B\":null,"
" \"object C\":true,"
@ -51,7 +51,7 @@ static void readFromString2() {
ejson::Document doc;
TEST_INFO("parse");
//! [ejson_sample_read_stream2]
std::string stream = "{"
etk::String stream = "{"
" objectA:'bonjour',"
" objectB:null,"
" objectC:true,"
@ -76,7 +76,7 @@ static void readFromString2() {
static void readFull() {
ejson::Document doc;
TEST_INFO("parse");
bool retParse = doc.load("DATA:read.json");
bool retParse = doc.load(etk::Uri("DATA:///read.json"));
TEST_INFO("parse ret = " << retParse);
TEST_INFO("Debug display of the tree:");
doc.display();
@ -129,22 +129,22 @@ static void readFull() {
for (size_t iii=0; iii<doc.size(); ++iii) {
switch (doc[iii].getType()) {
case ejson::valueType::object:
case ejson::valueType::Object:
TEST_INFO(" Get an Object:" << doc.getKey(iii) );
break;
case ejson::valueType::array:
case ejson::valueType::Array:
TEST_INFO(" Get an Array:" << doc.getKey(iii) );
break;
case ejson::valueType::boolean:
case ejson::valueType::Boolean:
TEST_INFO(" Get an Boolean:" << doc.getKey(iii) );
break;
case ejson::valueType::null:
case ejson::valueType::Null:
TEST_INFO(" Get an Null:" << doc.getKey(iii) );
break;
case ejson::valueType::number:
case ejson::valueType::Number:
TEST_INFO(" Get an Number:" << doc.getKey(iii) );
break;
case ejson::valueType::string:
case ejson::valueType::String:
TEST_INFO(" Get an String:" << doc.getKey(iii) );
break;
default:
@ -169,7 +169,7 @@ static void readFull() {
//! [ejson_sample_read_convert_string]
ejson::String elem = doc["object A"].toString();
// Get the value:
std::string value = elem.get();
etk::String value = elem.get();
//! [ejson_sample_read_convert_string]
TEST_INFO(" String Value:" << value);
}
@ -177,7 +177,7 @@ static void readFull() {
{
// Get the value:
//! [ejson_sample_read_get_string]
std::string value = doc["object A"].toString().get();
etk::String value = doc["object A"].toString().get();
//! [ejson_sample_read_get_string]
TEST_INFO(" String Value:" << value);
}
@ -199,9 +199,12 @@ static void readFull() {
{
// Get the value:
//! [ejson_sample_read_get_number]
double value = doc["object D"].toNumber().get();
double valueDouble = doc["object D"].toNumber().get();
//! [ejson_sample_read_get_number]
TEST_INFO(" Number Value:" << value);
//! [ejson_sample_read_get_number_64_bits]
uint64_t valueUint = doc["object D"].toNumber().getU64();
//! [ejson_sample_read_get_number_64_bits]
TEST_INFO(" Number Value double:" << valueDouble << " int64=" << valueUint);
}
TEST_INFO("Read Array:");

View File

@ -1,7 +1,7 @@
/** @file
* @author Edouard DUPIN
* @copyright 2016, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#pragma once

View File

@ -1,7 +1,7 @@
/** @file
* @author Edouard DUPIN
* @copyright 2016, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#include <test-debug/debug.hpp>
@ -16,8 +16,11 @@ static void writeToFile() {
doc.add("D", ejson::Array());
TEST_INFO("store");
//! [ejson_sample_write_file]
bool retGenerate = doc.store("generate.json");
bool retGenerate = doc.store(etk::Path("generate.json"));
//! [ejson_sample_write_file]
//! [ejson_sample_write_file_safe_mode]
retGenerate = doc.storeSafe(etk::Path("generate.json"));
//! [ejson_sample_write_file_safe_mode]
TEST_INFO("parse ret = " << retGenerate);
TEST_INFO("Debug display of the tree:");
doc.display();
@ -31,7 +34,7 @@ static void writeToString() {
doc.add("D", ejson::Array());
TEST_INFO("generate");
//! [ejson_sample_write_stream]
std::string streamOut;
etk::String streamOut;
bool retGenerate = doc.generate(streamOut);
//! [ejson_sample_write_stream]
TEST_INFO("parse ret = " << retGenerate);

View File

@ -1,7 +1,7 @@
/** @file
* @author Edouard DUPIN
* @copyright 2016, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#pragma once

View File

@ -1,32 +1,24 @@
/**
* @author Edouard DUPIN
*
* @copyright 2014, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#include <vector>
#include <etk/Vector.hpp>
#include <etk/etk.hpp>
#include <etk/types.hpp>
#include <etk/archive/Archive.hpp>
#include <test-debug/debug.hpp>
#include <ejson/ejson.hpp>
#include <gtest/gtest.h>
#include <etk/os/FSNode.hpp>
#include <etest/etest.hpp>
#include "testDocument.hpp"
#include "testBoolean.hpp"
#include "testNull.hpp"
#include "testNumber.hpp"
#include "testAll.hpp"
int main(int argc, const char *argv[]) {
// init Google test :
::testing::InitGoogleTest(&argc, const_cast<char **>(argv));
// init test engine:
etest::init(argc, argv);
// init etk log system and file interface:
etk::init(argc, argv);
// Run all test with gtest
// Run all test with etest
return RUN_ALL_TESTS();
}

View File

@ -1,17 +1,14 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#pragma once
#include "testCommon.hpp"
#include <gtest/gtest.h>
#include <etest/etest.hpp>
TEST(TestAll, testBaseObject) {
std::string base = "{\n"
etk::String base = "{\n"
" \"menu\": {\n"
" \"id\": \"file\",\n"
" \"value\": \"File\",\n"
@ -23,7 +20,7 @@ TEST(TestAll, testBaseObject) {
localTest(base, base, -1);
}
static std::string refOutputAll( "{\n"
static etk::String refOutputAll( "{\n"
" \"menu\": {\n"
" \"id\": \"file\",\n"
" \"value\": \"File\",\n"
@ -105,7 +102,7 @@ TEST(TestAll, testIndentedListWithNoBasicObject) {
TEST(TestAll, testGeneric1) {
std::string base = "{\n"
etk::String base = "{\n"
" \"glossary\": {\n"
" \"title\": \"example glossary\",\n"
" \"GlossDiv\": {\n"
@ -131,7 +128,7 @@ TEST(TestAll, testGeneric1) {
}
TEST(TestAll, testGeneric2) {
std::string base = "{\n"
etk::String base = "{\n"
" \"menu\": {\n"
" \"id\": \"file\",\n"
" \"value\": \"File\",\n"
@ -147,7 +144,7 @@ TEST(TestAll, testGeneric2) {
localTest(base, base, -1);
}
TEST(TestAll, testGeneric3) {
std::string base = "{\n"
etk::String base = "{\n"
" \"widget\": {\n"
" \"debug\": \"on\",\n"
" \"window\": {\n"
@ -180,7 +177,7 @@ TEST(TestAll, testGeneric3) {
TEST(TestAll, testGeneric4) {
std::string base = "{\n"
etk::String base = "{\n"
" \"web-app\": {\n"
" \"servlet\": [\n"
" {\n"
@ -276,7 +273,7 @@ TEST(TestAll, testGeneric4) {
TEST(TestAll, testGeneric5) {
std::string base = "{\n"
etk::String base = "{\n"
" \"menu\": {\n"
" \"header\": \"SVG Viewer\",\n"
" \"items\": [\n"

View File

@ -1,17 +1,14 @@
/**
* @author Edouard DUPIN
*
* @copyright 2014, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#pragma once
#include "testCommon.hpp"
#include <gtest/gtest.h>
#include <etest/etest.hpp>
static std::string refOutputBoolean1("{\n\t\"tmpElement\": true\n}\n");
static etk::String refOutputBoolean1("{\n\t\"tmpElement\": true\n}\n");
TEST(TestBoolean, testBaseTrue) {
localTest(refOutputBoolean1, "{ tmpElement:true }\n", -1);
}
@ -29,7 +26,7 @@ TEST(TestBoolean, testBaseTrue2) {
}
static std::string refOutputBoolean2("{\n\t\"tmpElement\": false\n}\n");
static etk::String refOutputBoolean2("{\n\t\"tmpElement\": false\n}\n");
TEST(TestBoolean, testBaseFalse) {
localTest(refOutputBoolean2, "{ tmpElement:false }\n", -1);
}

54
test/testCommon.cpp Normal file
View File

@ -0,0 +1,54 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include "testCommon.hpp"
#include <test-debug/debug.hpp>
#include <ejson/ejson.hpp>
#include <etest/etest.hpp>
// _errorPos : -1 : no error , 1 : parsing error, 2 generation error, 3 comparaison error ????
void localTest(const etk::String& _ref, const etk::String& _input, int32_t _errorPos) {
ejson::Document doc;
bool retParse = doc.parse(_input);
if (_errorPos == 1) {
EXPECT_EQ(retParse, false);
return;
} else {
EXPECT_EQ(retParse, true);
}
etk::String out("");
bool retGenerate = doc.generate(out);
if (_errorPos == 2) {
EXPECT_EQ(retGenerate, false);
return;
} else {
EXPECT_EQ(retGenerate, true);
}
if (_errorPos == 3) {
EXPECT_NE(_ref, out);
return;
} else {
EXPECT_EQ(_ref, out);
/*
JSON_ERROR("[TEST] {ERROR } different output");
etk::Vector<etk::String> tmpout = etk::split(out, '\n');
etk::Vector<etk::String> tmpref = etk::split(_ref, '\n');
//JSON_ERROR("generate : \n" << out);
//JSON_ERROR("reference : \n" << l_list[iii].m_ref);
for (int32_t jjj=0; jjj<tmpout.size() || jjj<tmpref.size(); ++jjj) {
if (jjj<tmpref.size()) {
TEST_INFO("[" << jjj << "] " << tmpref[jjj] );
}
if (jjj<tmpout.size()) {
if (jjj>=tmpref.size() || tmpref[jjj] != tmpout[jjj]) {
TEST_ERROR("[" << jjj << "] " << tmpout[jjj] );
}
}
}
*/
}
}

View File

@ -1,56 +1,10 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <test-debug/debug.hpp>
#include <ejson/ejson.hpp>
// _errorPos : -1 : no error , 1 : parsing error, 2 generation error, 3 comparaison error ????
static void localTest(const std::string& _ref, const std::string& _input, int32_t _errorPos) {
ejson::Document doc;
bool retParse = doc.parse(_input);
if (_errorPos == 1) {
EXPECT_EQ(retParse, false);
return;
} else {
EXPECT_EQ(retParse, true);
}
std::string out("");
bool retGenerate = doc.generate(out);
if (_errorPos == 2) {
EXPECT_EQ(retGenerate, false);
return;
} else {
EXPECT_EQ(retGenerate, true);
}
if (_errorPos == 3) {
EXPECT_NE(_ref, out);
return;
} else {
EXPECT_EQ(_ref, out);
/*
JSON_ERROR("[TEST] {ERROR } different output");
std::vector<std::string> tmpout = etk::split(out, '\n');
std::vector<std::string> tmpref = etk::split(_ref, '\n');
//JSON_ERROR("generate : \n" << out);
//JSON_ERROR("reference : \n" << l_list[iii].m_ref);
for (int32_t jjj=0; jjj<tmpout.size() || jjj<tmpref.size(); ++jjj) {
if (jjj<tmpref.size()) {
TEST_INFO("[" << jjj << "] " << tmpref[jjj] );
}
if (jjj<tmpout.size()) {
if (jjj>=tmpref.size() || tmpref[jjj] != tmpout[jjj]) {
TEST_ERROR("[" << jjj << "] " << tmpout[jjj] );
}
}
}
*/
}
}
void localTest(const etk::String& _ref, const etk::String& _input, int32_t _errorPos);

View File

@ -1,16 +1,13 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#pragma once
#include "testCommon.hpp"
#include <gtest/gtest.h>
#include <etest/etest.hpp>
static std::string refOutputDocument("{\n}\n");
static etk::String refOutputDocument("{\n}\n");
TEST(TestDocument, testEmptyDoc) {
localTest(refOutputDocument, "{}\n", -1);
}

View File

@ -1,17 +1,14 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#pragma once
#include "testCommon.hpp"
#include <gtest/gtest.h>
#include <etest/etest.hpp>
static std::string refOutputNull("{\n\t\"tmpElement\": null\n}\n");
static etk::String refOutputNull("{\n\t\"tmpElement\": null\n}\n");
TEST(TestNull, testBasicNullElement) {
localTest(refOutputNull, "{ tmpElement:null }\n", -1);
}

View File

@ -1,16 +1,13 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
* @license MPL v2.0 (see license file)
*/
#pragma once
#include "testCommon.hpp"
#include <gtest/gtest.h>
#include <etest/etest.hpp>
static std::string refOutputNumber("{\n\t\"tmpElement\": 956256\n}\n");
static etk::String refOutputNumber("{\n\t\"tmpElement\": 956256\n}\n");
TEST(TestNumber, testBase) {
localTest(refOutputNumber, "{ tmpElement:956256 }\n", -1);
}

View File

@ -1 +1 @@
0.8.0
1.0.0