22 #ifndef JSONOBJECT_H_INCLUDED 23 #define JSONOBJECT_H_INCLUDED 89 typedef std::unique_ptr<Object>
Child;
109 std::unique_ptr<Node> make(std::string
const&
specifier) {
110 return std::make_unique<Node>(
specifier);
126 children.push_back(std::move(child));
135 Child c = std::move(child);
144 children.push_back(std::move(child));
153 Child c = std::move(child);
161 return children.size();
170 return children.empty();
176 std::vector<Child>::const_iterator
begin()
const {
177 return children.begin();
183 std::vector<Child>::const_iterator
end()
const {
184 return children.end();
190 std::vector<Child>::iterator
begin() {
191 return children.begin();
197 std::vector<Child>::iterator
end() {
198 return children.end();
209 for (
const auto& child : children)
210 if (child->getSpecifier() == spec)
241 std::unique_ptr<List> make(std::string
const&
specifier) {
242 return std::make_unique<List>(
specifier);
251 if (child->getSpecifier() !=
specifier) {
252 std::cerr <<
"JSONParsingError: difference specification" 253 <<
" \"" << child->getSpecifier() <<
"\" in list.\n";
266 if (child->getSpecifier() !=
specifier) {
267 std::cerr <<
"JSONParsingError: difference specification" 268 <<
" \"" << child->getSpecifier() <<
"\" in list.\n";
280 if (child->getSpecifier() !=
specifier) {
281 std::cerr <<
"JSONParsingError: difference specification" 282 <<
" \"" << child->getSpecifier() <<
"\" in list.\n";
295 if (child->getSpecifier() !=
specifier) {
296 std::cerr <<
"JSONParsingError: difference specification" 297 <<
" \"" << child->getSpecifier() <<
"\" in list.\n";
324 virtual std::string getArgument()
const = 0;
334 template<
typename Type>
351 return std::make_unique<Leaf<Type>>(
specifier, t_argument);
355 std::ostringstream sout;
356 if (
typeid(argument) ==
typeid(std::string))
357 sout <<
"\"" << argument <<
"\"";
360 if constexpr(std::is_same<Type, double>::value) {
361 if (argument == std::round(argument)) {
bool empty() const
Tells if the Node is empty.
Definition: jsonObject.h:169
void addChild(Child &child) override
Adds a child in the List. Checks if the specifier is the same as the one of the List (each element mu...
Definition: jsonObject.h:250
void addChild(std::unique_ptr< T > &child)
Adds a child in the Node.
Definition: jsonObject.h:134
virtual void addChild(Child &child)
Adds a child in the Node.
Definition: jsonObject.h:125
Type getTypedArgument() const
Returns the bare argument with its own type, not a string (like the function getArgument() does)...
Definition: jsonObject.h:374
virtual void addChild(Child &&child)
Adds a child in the Node.
Definition: jsonObject.h:143
std::string specifier
String that represents the specifier of the object. For example: "name": "electron" is an object of w...
Definition: jsonObject.h:82
bool isNode() const override
Tells if the Object is a Node or not.
Definition: jsonObject.h:117
virtual bool isNode() const
Tells if the Object is a Node or not. This function is reimplemented in Node.
Definition: jsonObject.h:71
Template class inherited from Object that stores a parameter of a .json file. This class does not hav...
Definition: jsonObject.h:335
std::vector< Child > children
std::vector of Child owned by the Node. Each child is in the form of a unique_ptr to an Object...
Definition: jsonObject.h:221
std::vector< Child >::const_iterator end() const
Definition: jsonObject.h:183
List(std::string const &specifier)
Construtor with one paramter that initializes specifier.
Definition: jsonObject.h:238
Inherits from JSON::Object, specialized in JSON Node. A Node owns a vector of Object. The Node's children can either be Leaf or other Node objects. This allows to store the tree structure of a .json file.
Definition: jsonObject.h:97
Type argument
Argument of the Leaf. Final position on JSON tree, contains the int, double, string, ..., needed further in the program.
Definition: jsonObject.h:384
void addChild(std::unique_ptr< T > &child)
Adds a child in the List. Checks if the specifier is the same as the one of the List (each element mu...
Definition: jsonObject.h:265
std::vector< Child >::const_iterator begin() const
Definition: jsonObject.h:176
Abstract object in JSON tree structure. Can be specialized either in Node or in Leaf<T> with a specif...
Definition: jsonObject.h:43
void addChild(std::unique_ptr< T > &&child)
Adds a child in the Node.
Definition: jsonObject.h:152
void addChild(std::unique_ptr< T > &&child)
Adds a child in the List. Checks if the specifier is the same as the one of the List (each element mu...
Definition: jsonObject.h:294
AbstractLeaf(std::string const &specifier)
Construtor with one paramter that initializes specifier.
Definition: jsonObject.h:318
Abstract class inherited from Object, from which all leafs will derive. This class only contains a pu...
Definition: jsonObject.h:310
size_t size() const
Definition: jsonObject.h:160
Object(std::string const &t_specifier)
Construtor with one paramter that initializes specifier.
Definition: jsonObject.h:52
virtual ~Object()
Destructor.
Definition: jsonObject.h:57
A List is a particular Node of which all children are of the same type and have the same specifier...
Definition: jsonObject.h:229
std::unique_ptr< Object > Child
Type definition for unique_ptr<Object>. Lighten the vector of Object owned by Node objects...
Definition: jsonObject.h:89
Node(std::string const &specifier)
Construtor with one paramter that initializes specifier.
Definition: jsonObject.h:106
std::vector< Child >::iterator end()
Definition: jsonObject.h:197
std::string getArgument() const
Returns a std::string representing the argument of the Leaf.
Definition: jsonObject.h:354
void addChild(Child &&child) override
Adds a child in the List. Checks if the specifier is the same as the one of the List (each element mu...
Definition: jsonObject.h:279
Leaf(std::string const &specifier, Type t_argument)
Constructor with two paramters. The specifier and the argument of the Leaf.
Definition: jsonObject.h:346
Object * getChild(std::string const &spec) const
Returns the first child that has a given specifier.
Definition: jsonObject.h:208
std::vector< Child >::iterator begin()
Definition: jsonObject.h:190
Contains all objects related to JSON reading / writing.
Definition: csldatahandler.h:30
std::string getSpecifier() const
Definition: jsonObject.h:62