osgEarth 2.1.1
|
#include <osgEarth/JsonUtils>
#include <osg/Notify>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <sstream>
Go to the source code of this file.
Classes | |
class | osgEarth::Json::DefaultValueAllocator |
struct | DummyValueAllocatorInitializer |
Namespaces | |
namespace | osgEarth |
namespace | osgEarth::Json |
Defines | |
#define | JSON_ASSERT_UNREACHABLE assert( false ) |
#define | JSON_ASSERT(condition) assert( condition ); |
#define | JSON_ASSERT_MESSAGE(condition, message) if (!( condition )) throw std::runtime_error( message ); |
Functions | |
static ValueAllocator *& | valueAllocator () |
static bool | osgEarth::Json::in (Reader::Char c, Reader::Char c1, Reader::Char c2, Reader::Char c3, Reader::Char c4) |
static bool | osgEarth::Json::in (Reader::Char c, Reader::Char c1, Reader::Char c2, Reader::Char c3, Reader::Char c4, Reader::Char c5) |
static bool | osgEarth::Json::containsNewLine (Reader::Location begin, Reader::Location end) |
std::istream & | operator>> (std::istream &sin, Value &root) |
Read from 'sin' into 'root'. | |
static void | osgEarth::Json::uintToString (unsigned int value, char *¤t) |
std::string JSON_API | osgEarth::Json::valueToString (Value::Int value) |
std::string JSON_API | osgEarth::Json::valueToString (Value::UInt value) |
std::string JSON_API | osgEarth::Json::valueToString (double value) |
std::string JSON_API | osgEarth::Json::valueToString (bool value) |
std::string JSON_API | osgEarth::Json::valueToQuotedString (const char *value) |
std::ostream & | operator<< (std::ostream &sout, const Value &root) |
Output using the StyledStreamWriter. | |
Variables | |
static struct DummyValueAllocatorInitializer | dummyValueAllocatorInitializer |
#define JSON_ASSERT | ( | condition | ) | assert( condition ); |
Definition at line 40 of file JsonUtils.cpp.
#define JSON_ASSERT_MESSAGE | ( | condition, | |
message | |||
) | if (!( condition )) throw std::runtime_error( message ); |
Definition at line 41 of file JsonUtils.cpp.
#define JSON_ASSERT_UNREACHABLE assert( false ) |
The code here and in JsonUtils.h is adapted from the "json-cpp" project, developed by Baptiste Lepilleur and put in the publi domain. Since the json-cpp project is relatively compact, and has not been updated in 3 years, we decided to simply incorporate it here instead of introducing another dependency.
Definition at line 39 of file JsonUtils.cpp.
std::ostream& operator<< | ( | std::ostream & | , |
const Value & | root | ||
) |
Output using the StyledStreamWriter.
Definition at line 3511 of file JsonUtils.cpp.
{ Json::StyledStreamWriter writer; writer.write(sout, root); return sout; }
std::istream& operator>> | ( | std::istream & | , |
Value & | |||
) |
Read from 'sin' into 'root'.
Always keep comments from the input JSON.
This can be used to read a file into a particular sub-object. For example:
Json::Value root; cin >> root["dir"]["file"]; cout << root;
Result:
{ "dir": { "file": { // The input stream JSON would be nested here. } } }
std::exception | on parse error. |
Definition at line 2719 of file JsonUtils.cpp.
{ Json::Reader reader; bool ok = reader.parse(sin, root, true); //JSON_ASSERT( ok ); if (!ok) throw std::runtime_error(reader.getFormatedErrorMessages()); return sin; }
static ValueAllocator*& valueAllocator | ( | ) | [static] |
Definition at line 99 of file JsonUtils.cpp.
{ static DefaultValueAllocator defaultAllocator; static ValueAllocator *valueAllocator = &defaultAllocator; return valueAllocator; }
struct DummyValueAllocatorInitializer dummyValueAllocatorInitializer [static] |