15 #ifndef INCLUDED_basic_Emitter_hh
16 #define INCLUDED_basic_Emitter_hh
28 typedef utility::pointer::shared_ptr< Emitter >
EmitterOP;
29 typedef utility::pointer::shared_ptr< Emitter const >
EmitterCOP;
32 typedef utility::pointer::shared_ptr< YamlEmitter >
YamlEmitterOP;
36 typedef utility::pointer::shared_ptr< JsonEmitter >
JsonEmitterOP;
87 void write(std::string
const & label,
T const &
data);
93 void start_list(std::string
const & label,
bool indent=
true)
96 void start_list(
const char * label,
bool indent=
true);
98 void start_map(std::string
const & label,
bool indent=
true)
101 void start_map(
const char * label,
bool indent=
true);
108 void end(
size_t desired_depth=0);
114 std::ostringstream
s;
115 for (
int i = 0; i < num_spaces; ++i ) s <<
' ';
144 {
out_ << (b ?
"true" :
"false"); }
157 std::string
escape_string(std::string
const &
s,
bool & needs_quotes_out);
166 void do_indent(
bool write_comma=
true) = 0;
174 void start_raw(
bool is_map,
bool indent) = 0;
193 template <
typename T>
196 assert_in(
false,
"Tried to write list data inside a map");
202 template <
typename T>
205 assert_in(
true,
"Tried to write map data inside a list");
241 bool needs_quotes(
false);
243 if ( needs_quotes )
return "\""+t+
"\"";
270 if ( indent )
out_ <<
"- ";
278 if ( is_map )
out_ <<
"{ ";
302 if ( is_map )
out_ <<
" }";
365 bool needs_quotes(
false);
394 if ( is_map )
out_ <<
"{";
416 if ( is_map )
out_ <<
"}";
427 #endif // INCLUDED_basic_Emitter_HH
utility::pointer::shared_ptr< YamlEmitter > YamlEmitterOP
int depth() const
Number of closing brackets/braces required to end document (non-negative)
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()
YAML uses "-" for list items when in block (indented) mode.
void end_list()
Counterpart to start_list() – writes closing bracket.
Emitter(std::ostream &out)
Emitter for more classically formatted YAML.
JsonEmitter(std::ostream &out)
utility::pointer::shared_ptr< JsonEmitter > JsonEmitterOP
void start_map(std::string const &label, bool indent=true)
Write method for use inside maps / dicts / objects.
void write_raw(std::string const &s)
bool assert_in(bool in_map, std::string const &msg)
Check that we're in the expected context (either map or list)
virtual void start_doc()
Start a new YAML document, ending the previous one first if necessary.
void end_map()
Counterpart to start_map() – writes closing brace.
virtual std::string quote_string(std::string const &s)
JSON always quotes strings, regardless.
std::vector< bool > in_map_
utility::pointer::shared_ptr< JsonEmitter const > JsonEmitterCOP
void start_list(bool indent=true)
Write method for use inside lists / arrays.
void write(T const &data)
Write method for use inside lists / arrays.
std::vector< bool > indent_
virtual void start_raw(bool is_map, bool indent)
utility::pointer::shared_ptr< Emitter const > EmitterCOP
YamlEmitter(std::ostream &out)
std::vector< bool > first_
Tracer & T(std::string const &channel, TracerPriority priority)
T is special function for assign tracer property on the static object.
void end(size_t desired_depth=0)
By default, closes all open maps/lists, ending the document.
virtual void start_doc()
JSON doesn't support multiple documents, so this just calls end(1) to return you to the top (least-ne...
utility::pointer::shared_ptr< YamlEmitter const > YamlEmitterCOP
virtual std::string quote_string(std::string const &s)
YAML only quotes strings when they contain special characters.
void start_list(std::string const &label, bool indent=true)
Write method for use inside maps / dicts / objects.
void start_map(bool indent=true)
Write method for use inside lists / arrays.
Base class for reference-counted polymorphic classes.
virtual void start_raw(bool is_map, bool indent)=0
Actual implementation of start_map() and start_list().
std::vector< int > indent_depth_
virtual void write_list_marker()=0
Used for traditional YAML output, writes the "-" marker.
utility::pointer::shared_ptr< Emitter > EmitterOP
Lightweight class to ease writting YAML documents (http://yaml.org)
Tracer & Warning(TracerPriority priority=t_warning)
Predefined Warning tracer.
virtual void start_doc()=0
Start a new document, ending the previous one first if necessary. A no-op for some types of output (e...
virtual void end_raw()=0
Actual implementation of end_map() and end_list().
Lightweight class to ease writting JSON documents, a subset of YAML (http://json.org) ...
virtual void do_indent(bool write_comma=true)=0
Handle pretty-printing indentation. Don't want to use commas for opening/closing brace/bracket.
void set_indent(int num_spaces)
Number of spaces used for indenting. Default is one.
virtual void do_indent(bool write_comma=true)
Handle pretty-printing indentation. Don't want to use commas for opening/closing brace/bracket.
void write_label(std::string const &label)
Write the key part of a key-value pair.
void flush()
Flush the underlying output stream.
virtual void write_list_marker()
JSON has no special marker for list items.
std::string escape_string(std::string const &s, bool &needs_quotes_out)
Converts special characters (newlines, etc) to escape codes ( , etc).
virtual void start_raw(bool is_map, bool indent)
virtual std::string quote_string(std::string const &s)=0
Quotes strings as much as needed for this format (e.g. always for JSON).