30#ifndef PT_JSON_DOCUMENT_H
31#define PT_JSON_DOCUMENT_H
33#include <Pt/Json/Api.h>
34#include <Pt/SerializationInfo.h>
47 friend class DocumentReader;
59 Element(
const Element& elem)
63 Element& operator=(
const Element& elem)
72 {
return _si->name(); }
102 return _si ? _si->isVoid() :
true;
123 return Element( _si->parent() );
134 if( it == _si->
end() )
172 Element operator[] (
const std::string&
name)
const
179 Element operator[] (
const char*
name)
const
228 _si->removeMember(
name);
236 _si->removeMember(
name);
243 if( ! _si || ! e._si )
246 _si->removeMember( *e._si );
263 _si = _si->sibling();
270 {
return _si != other._si; }
275 {
return _si == other._si; }
298 {
return _si->name(); }
302 template <
typename T>
316 return _si ? _si->isVoid() :
true;
331 return ConstElement(&si);
338 return ConstElement();
349 return ConstElement(si);
360 return ConstElement(si);
365 ConstElement operator[] (
const std::string&
name)
const
372 ConstElement operator[] (
const char*
name)
const
391 _si = _si->sibling();
398 {
return _si != other._si; }
403 {
return _si == other._si; }
429 void load( std::basic_istream<Pt::Char>& is );
433 void save( std::basic_ostream<Pt::Char>& os )
const;
546 root().removeMember(name);
553 root().removeMember(name);
560 root().removeElement(e);
Constant document element.
Definition Document.h:289
ConstElement begin() const
Begin of sub elements.
Definition Document.h:321
ConstElement getMember(const std::string &name) const
Returns a sub element.
Definition Document.h:343
bool getValue(T &value) const
Gets the value.
Definition Document.h:303
bool operator!() const
Returns true if element is invalid.
Definition Document.h:407
ConstElement & operator++()
Allows using the element like an iterator.
Definition Document.h:389
const char * name() const
Returns the element name.
Definition Document.h:297
const ConstElement * operator->() const
Allows using the element like an iterator.
Definition Document.h:384
ConstElement getMember(const char *name) const
Returns a sub element.
Definition Document.h:354
bool isNull() const
Returns true if element is null.
Definition Document.h:314
bool operator!=(const ConstElement &other) const
Allows using the element like an iterator.
Definition Document.h:397
bool operator==(const ConstElement &other) const
Allows using the element like an iterator.
Definition Document.h:402
const ConstElement & operator*() const
Allows using the element like an iterator.
Definition Document.h:379
ConstElement end() const
End of sub elements.
Definition Document.h:336
Modifiable document element.
Definition Document.h:53
void removeElement(const Element &e)
Removes a sub element.
Definition Document.h:241
Element & operator*()
Allows using the element like an iterator.
Definition Document.h:251
bool operator==(const Element &other) const
Allows using the element like an iterator.
Definition Document.h:274
bool getValue(T &value) const
Gets the value.
Definition Document.h:77
bool operator!=(const Element &other) const
Allows using the element like an iterator.
Definition Document.h:269
Element & operator++()
Allows using the element like an iterator.
Definition Document.h:261
bool operator!() const
Returns true if element is invalid.
Definition Document.h:279
void setValue(const T &value)
Sets the value.
Definition Document.h:89
Element begin() const
Begin of sub elements.
Definition Document.h:128
Element addElement()
Adds a sub element.
Definition Document.h:214
Element getMember(const char *name) const
Returns a sub element.
Definition Document.h:161
const char * name() const
Returns the element name.
Definition Document.h:71
void setNull()
Sets element to null.
Definition Document.h:107
void removeMember(const std::string &name)
Removes a sub element.
Definition Document.h:225
Element * operator->()
Allows using the element like an iterator.
Definition Document.h:256
bool isNull() const
Returns true if element is null.
Definition Document.h:100
Element addMember(const char *name)
Adds a sub element.
Definition Document.h:186
Element parent() const
Returns the parent element.
Definition Document.h:118
Element end() const
End of sub elements.
Definition Document.h:143
void removeMember(const char *name)
Removes a sub element.
Definition Document.h:233
Element getMember(const std::string &name) const
Returns a sub element.
Definition Document.h:150
Element addMember(const std::string &name)
Adds a sub element.
Definition Document.h:200
ConstElement begin() const
Begin of elements.
Definition Document.h:452
void removeElement(const Element &e)
Removes a top level element.
Definition Document.h:558
Element begin()
Begin of elements.
Definition Document.h:447
Element getMember(const char *name)
Returns a top level element.
Definition Document.h:481
ConstElement getMember(const std::string &name) const
Returns a top level element.
Definition Document.h:474
Document()
Default constructor.
Element addElement()
Adds a top level element.
Definition Document.h:537
void removeMember(const std::string &name)
Removes a top level element.
Definition Document.h:551
void save(std::basic_ostream< Pt::Char > &os) const
Saves a document to a output stream.
ConstElement root() const
Returns the root element.
Definition Document.h:442
ConstElement getMember(const char *name) const
Returns a top level element.
Definition Document.h:488
Element addMember(const char *name)
Adds a top level element.
Definition Document.h:523
void clear()
Clears the settings.
bool isEmpty() const
Returns true if settings are empty.
Element root()
Returns the root element.
Definition Document.h:437
void load(std::basic_istream< Pt::Char > &is)
Loads a document from a input stream.
ConstElement end() const
End of elements.
Definition Document.h:462
void removeMember(const char *name)
Removes a top level element.
Definition Document.h:544
Element getMember(const std::string &name)
Returns a top level element.
Definition Document.h:467
Element addMember(const std::string &name)
Adds a top level element.
Definition Document.h:530
Element end()
End of elements.
Definition Document.h:457
Const forward iterator for child elements.
Definition SerializationInfo.h:783
Forward Iterator for child elements.
Definition SerializationInfo.h:738
Represents arbitrary types during serialization.
Definition SerializationInfo.h:59
SerializationInfo & addElement()
Add a sequence element.
const SerializationInfo * findMember(const std::string &name) const
Find a struct member.
Definition SerializationInfo.h:508
Iterator begin()
Returns an iterator to the begin of child elements.
Iterator end()
Returns an iterator to the end of child elements.
Definition SerializationInfo.h:826
SerializationInfo & addMember(const std::string &name)
Add a struct member.
Definition SerializationInfo.h:449
Read and write JSON ducuments.
Core module.
Definition Allocator.h:33