Rosetta 3.3
Public Member Functions | Protected Member Functions
basic::JsonEmitter Class Reference

Lightweight class to ease writting JSON documents, a subset of YAML (http://json.org) More...

#include <Emitter.hh>

Inheritance diagram for basic::JsonEmitter:
Inheritance graph
[legend]
Collaboration diagram for basic::JsonEmitter:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 JsonEmitter (std::ostream &out)
virtual ~JsonEmitter ()
virtual void start_doc ()
 JSON doesn't support multiple documents, so this just calls end(1) to return you to the top (least-nested) level.

Protected Member Functions

virtual std::string quote_string (std::string const &s)
 JSON always quotes strings, regardless.
virtual void do_indent (bool write_comma=true)
 Handle pretty-printing indentation. Don't want to use commas for opening/closing brace/bracket.
virtual void write_list_marker ()
 JSON has no special marker for list items.
virtual void start_raw (bool is_map, bool indent)
virtual void end_raw ()

Detailed Description

Lightweight class to ease writting JSON documents, a subset of YAML (http://json.org)

Using this class is not recommended -- use YamlEmitter instead.

JSON is JavaScript Object Notation, the format for object and array literals in the JavaScript language. It also looks a great deal like nested Python dicts and lists, except for the special JSON values true, false, and null. (Python uses True, False, and None instead. Otherwise, JSON can be embedded directly into Python scripts.)

JSON is legal subset of YAML, but leaves out much of YAML's complexity and advanced features. At the present time, there appears to be more library support for JSON than for YAML, especially for reading and parsing. (Both are fairly easy to write, as demonstrated here.)

The topmost level of every valid JSON document consists of exactly one map, which is automatically started for you when the class is initialized. When you're finished you should call end(), and then probably flush().

Whitespace is JSON documents is not significant. By default, this class will try to pretty-print, showing the depth of nesting through indentation. When starting a new list or map, you can request that it not be indented (i.e., be printed all on one line), but all lists and maps nested inside it will also be printed without linebreaks, regardless of the requested indentation.


Constructor & Destructor Documentation

basic::JsonEmitter::JsonEmitter ( std::ostream &  out) [inline]

References start_raw().

virtual basic::JsonEmitter::~JsonEmitter ( ) [inline, virtual]

Member Function Documentation

virtual void basic::JsonEmitter::do_indent ( bool  write_comma = true) [inline, protected, virtual]

Handle pretty-printing indentation. Don't want to use commas for opening/closing brace/bracket.

Implements basic::Emitter.

References basic::Emitter::depth(), assign_charges::first, basic::Emitter::first_, color_pdb::i, basic::Emitter::indent_, basic::Emitter::indent_depth_, basic::Emitter::indent_str_, and basic::Emitter::out_.

Referenced by end_raw().

virtual void basic::JsonEmitter::end_raw ( ) [inline, protected, virtual]

JSON always uses brackets and braces, regardless of whether we're indenting.

Implements basic::Emitter.

References do_indent(), basic::Emitter::first_, basic::Emitter::in_map_, basic::Emitter::indent_, basic::Emitter::indent_depth_, and basic::Emitter::out_.

virtual std::string basic::JsonEmitter::quote_string ( std::string const &  s) [inline, protected, virtual]

JSON always quotes strings, regardless.

Implements basic::Emitter.

References basic::Emitter::escape_string(), and sd::t.

virtual void basic::JsonEmitter::start_doc ( ) [inline, virtual]

JSON doesn't support multiple documents, so this just calls end(1) to return you to the top (least-nested) level.

Implements basic::Emitter.

References basic::Emitter::end().

virtual void basic::JsonEmitter::start_raw ( bool  is_map,
bool  indent 
) [inline, protected, virtual]

JSON always uses brackets and braces, regardless of whether we're indenting.

Implements basic::Emitter.

References basic::Emitter::first_, basic::Emitter::in_map_, basic::Emitter::indent_, basic::Emitter::indent_depth_, and basic::Emitter::out_.

Referenced by JsonEmitter().

virtual void basic::JsonEmitter::write_list_marker ( ) [inline, protected, virtual]

JSON has no special marker for list items.

Implements basic::Emitter.


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