osgEarth 2.1.1
Public Member Functions | Private Member Functions | Private Attributes

osgEarth::Json::FastWriter Class Reference

Outputs a Value in JSON format without formatting (not human friendly). More...

Inheritance diagram for osgEarth::Json::FastWriter:
Collaboration diagram for osgEarth::Json::FastWriter:

List of all members.

Public Member Functions

 FastWriter ()
virtual ~FastWriter ()
void enableYAMLCompatibility ()
virtual std::string write (const Value &root)

Private Member Functions

void writeValue (const Value &value)

Private Attributes

std::string document_
bool yamlCompatiblityEnabled_

Detailed Description

Outputs a Value in JSON format without formatting (not human friendly).

The JSON document is written in a single line. It is not intended for 'human' consumption, but may be usefull to support feature such as RPC where bandwith is limited.

See also:
Reader, Value

Definition at line 1131 of file JsonUtils.


Constructor & Destructor Documentation

FastWriter::FastWriter ( )

Definition at line 2874 of file JsonUtils.cpp.

   : yamlCompatiblityEnabled_( false )
{
}
virtual osgEarth::Json::FastWriter::~FastWriter ( ) [inline, virtual]

Definition at line 1135 of file JsonUtils.

{}

Member Function Documentation

void FastWriter::enableYAMLCompatibility ( )

Definition at line 2881 of file JsonUtils.cpp.

std::string FastWriter::write ( const Value root) [virtual]

Implements osgEarth::Json::Writer.

Definition at line 2888 of file JsonUtils.cpp.

{
   document_ = "";
   writeValue( root );
   document_ += "\n";
   return document_;
}

Here is the call graph for this function:

void FastWriter::writeValue ( const Value value) [private]

Definition at line 2898 of file JsonUtils.cpp.

{
   switch ( value.type() )
   {
   case nullValue:
      document_ += "null";
      break;
   case intValue:
      document_ += valueToString( value.asInt() );
      break;
   case uintValue:
      document_ += valueToString( value.asUInt() );
      break;
   case realValue:
      document_ += valueToString( value.asDouble() );
      break;
   case stringValue:
      document_ += valueToQuotedString( value.asCString() );
      break;
   case booleanValue:
      document_ += valueToString( value.asBool() );
      break;
   case arrayValue:
      {
         document_ += "[";
         int size = value.size();
         for ( int index =0; index < size; ++index )
         {
            if ( index > 0 )
               document_ += ",";
            writeValue( value[index] );
         }
         document_ += "]";
      }
      break;
   case objectValue:
      {
         Value::Members members( value.getMemberNames() );
         document_ += "{";
         for ( Value::Members::iterator it = members.begin(); 
               it != members.end(); 
               ++it )
         {
            const std::string &name = *it;
            if ( it != members.begin() )
               document_ += ",";
            document_ += valueToQuotedString( name.c_str() );
            document_ += yamlCompatiblityEnabled_ ? ": " 
                                                  : ":";
            writeValue( value[name] );
         }
         document_ += "}";
      }
      break;
   }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 1145 of file JsonUtils.

Definition at line 1146 of file JsonUtils.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines