33 #include <boost/container/list.hpp>
45 typedef boost::container::list<JsonTree> Container;
47 typedef Container::const_iterator ConstIter;
48 typedef Container::iterator Iter;
136 ConstIter
begin()
const;
140 ConstIter
end()
const;
175 bool hasChild(
const std::string &relativePath,
bool caseSensitive =
false,
char separator =
'.' )
const;
210 void write(
const fs::path &path, WriteOptions writeOptions = WriteOptions() );
224 template <
typename T>
228 return fromString<T>( mValue );
229 }
catch ( boost::bad_lexical_cast &) {
235 template <
typename T>
238 template <
typename T>
254 enum ValueType { VALUE_BOOL, VALUE_DOUBLE, VALUE_INT, VALUE_STRING, VALUE_UINT };
258 Json::Value createNativeDoc( WriteOptions writeOptions = WriteOptions() )
const;
259 static Json::Value deserializeNative(
const std::string &jsonString, ParseOptions parseOptions );
262 void init(
const std::string &key,
const Json::Value &
value,
bool setType =
false,
265 JsonTree* getNodePtr(
const std::string &relativePath,
bool caseSensitive,
char separator )
const;
273 ValueType mValueType;
289 virtual const char*
what()
const throw()
295 char mMessage[ 2048 ];
302 virtual const char*
what()
const throw()
308 char mMessage[ 2048 ];
315 virtual const char*
what()
const throw()
321 char mMessage[ 2048 ];
326 std::ostream&
operator<<( std::ostream &out,
const JsonTree &json );
WriteOptions & indented(bool indent=true)
Sets whether JSON string is indented. Default true.
Definition: Json.cpp:68
void replaceChild(size_t index, const JsonTree &newChild)
Replaces the child at index with JsonTree newChild. Throws ExcChildNotFound if none matches...
Definition: Json.cpp:334
WriteOptions()
Default options. Indents. Does not create root document.
Definition: Json.cpp:57
Options for JSON writing. Passed to the write method.
Definition: Json.h:72
bool hasChildren() const
Returns whether this node has a parent node.
Definition: Json.cpp:449
void write(const fs::path &path, WriteOptions writeOptions=WriteOptions())
Definition: Json.cpp:660
T getValueAtIndex(size_t index) const
Returns the value of the child at relativePath. Default type T is std::string. Convenience shortcut f...
Definition: Json.h:239
GLsizei const GLchar ** string
Definition: GLee.h:2427
bool getIgnoreErrors() const
Returns whether JSON parse errors are ignored.
Definition: Json.cpp:52
JsonTree & getChild(const std::string &relativePath, bool caseSensitive=false, char separator= '.')
Definition: Json.cpp:399
Iter end()
Returns an Iter which marks the end of the children of this node.
Definition: Json.cpp:389
Exception expressing the absence of an expected child node.
Definition: Json.h:286
T getValue() const
Returns the value of the node cast to T using ci::fromString(). float value = myNode.getValue( "key" );
Definition: Json.h:225
ExcChildNotFound(const JsonTree &node, const std::string &key)
Definition: Json.cpp:699
T getValueForKey(const std::string &relativePath, bool caseSensitive=false, char separator= '.') const
Returns the value of the child at relativePath. Default type T is std::string. Convenience shortcut f...
Definition: Json.h:236
GLuint index
Definition: GLee.h:2259
Iter begin()
Returns an Iter to the first child of this node.
Definition: Json.cpp:379
GLenum target
Definition: GLee.h:13607
const std::string & getValueAtIndex(size_t index) const
Returns the value of the child at relativePath. Default type T is std::string. Convenience shortcut f...
Definition: Json.h:246
void removeChild(size_t index)
Removes the child at index. Throws ExcChildNotFound if none matches.
Definition: Json.cpp:313
Exception expressing the existence of errors when serializing or deserializing JSON.
Definition: Json.h:312
ParseOptions & ignoreErrors(bool ignore=true)
Sets if JSON parse errors are ignored. Default true.
Definition: Json.cpp:46
ParseOptions()
Default options. Enables parsing errors.
Definition: Json.cpp:41
bool getCreateDocument() const
whether JSON is wrapped in a 'document root' object.
Definition: Json.cpp:74
JsonTree & operator[](const std::string &relativePath)
Definition: Json.cpp:359
const std::string & getKey() const
Returns the node's key as a string. Returns index if node does not have a key.
Definition: Json.cpp:467
const std::string & getValue() const
Returns the value of the node as a string.
Definition: Json.h:242
friend std::ostream & operator<<(std::ostream &out, const JsonTree &json)
Streams the JsonTree json to std::ostream out with standard formatting.
bool hasChild(const std::string &relativePath, bool caseSensitive=false, char separator= '.') const
Definition: Json.cpp:444
virtual const char * what() const
Definition: Json.h:289
bool getIndented() const
Returns whether JSON string is indented.
Definition: Json.cpp:79
Base class for JsonTree exceptions.
Definition: Json.h:281
virtual const char * what() const
Definition: Json.h:315
virtual const char * what() const
Definition: Json.h:302
size_t getNumChildren() const
Returns the number of child nodes.
Definition: Json.h:171
const Container & getChildren() const
Returns a reference to the node's list of children nodes.
Definition: Json.cpp:439
void clear()
Removes all child nodes.
Definition: Json.cpp:289
JsonTree & operator=(const JsonTree &jsonTree)
Assigns the JsonTree a new value, and creates it if it doesn't exist.
Definition: Json.cpp:104
std::string serialize() const
Returns the JsonTree as a string with standard formatting.
Definition: Json.cpp:643
typedef int64_t(APIENTRYP GLEEPFNGLXSWAPBUFFERSMSCOMLPROC)(Display *dpy
GLsizei const GLfloat * value
Definition: GLee.h:2487
WriteOptions & createDocument(bool createDocument=true)
Sets whether JSON is wrapped in a 'document root' object. Default false.
Definition: Json.cpp:62
std::ostream & operator<<(std::ostream &lhs, const ColorT< float > &rhs)
Definition: Color.cpp:203
Options for JSON parsing. Passed to the JsonTree constructor.
Definition: Json.h:55
JsonTree & getParent()
Returns a reference to the node which is the parent of this node.
Definition: Json.cpp:454
static JsonTree makeArray(const std::string &key="")
Definition: Json.cpp:190
JsonTree & addChild(const JsonTree &newChild)
Definition: Json.cpp:294
NodeType getNodeType() const
Returns the type of the node.
Definition: Json.h:249
std::shared_ptr< class DataTarget > DataTargetRef
Definition: DataTarget.h:33
bool hasParent() const
Returns whether this node has a parent node.
Definition: Json.cpp:462
std::string getPath(char separator= '.') const
Definition: Json.cpp:472
Definition: Exception.h:32
const std::string & getValueForKey(const std::string &relativePath, bool caseSensitive=false, char separator= '.') const
Returns the value of the child at relativePath. Default type T is std::string. Convenience shortcut f...
Definition: Json.h:244
NodeType
Enum listing all types of JSON nodes understood by the parser.
Definition: Json.h:52
std::shared_ptr< class DataSource > DataSourceRef
Definition: DataSource.h:35
static JsonTree makeObject(const std::string &key="")
Definition: Json.cpp:198
ExcJsonParserError(const std::string &errorMessage)
Definition: Json.cpp:717
Exception expressing the inability to convert a node's value to a requested type. ...
Definition: Json.h:299
JsonTree()
Creates a null JsonTree.
Definition: Json.cpp:86
void pushBack(const JsonTree &newChild)
Definition: Json.cpp:300
ExcNonConvertible(const JsonTree &node)
Definition: Json.cpp:708