osgEarth 2.1.1
Classes | Namespaces | Defines | Functions | Variables

/home/cube/sources/osgearth/src/osgEarth/JsonUtils.cpp File Reference

#include <osgEarth/JsonUtils>
#include <osg/Notify>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <sstream>
Include dependency graph for JsonUtils.cpp:

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 *&current)
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 Documentation

#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.


Function Documentation

std::ostream& operator<< ( std::ostream &  ,
const Value root 
)

Output using the StyledStreamWriter.

See also:
Json::operator>>()

Definition at line 3511 of file JsonUtils.cpp.

{
   Json::StyledStreamWriter writer;
   writer.write(sout, root);
   return sout;
}

Here is the call graph for this function:

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.
	    }
	}
    }
    
Exceptions:
std::exceptionon parse error.
See also:
Json::operator<<()

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;
}

Here is the call graph for this function:

static ValueAllocator*& valueAllocator ( ) [static]

Definition at line 99 of file JsonUtils.cpp.

{
   static DefaultValueAllocator defaultAllocator;
   static ValueAllocator *valueAllocator = &defaultAllocator;
   return valueAllocator;
}

Here is the caller graph for this function:


Variable Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines