Rosetta
|
Lightweight class to ease writting YAML documents (http://yaml.org) More...
#include <Emitter.hh>
Public Member Functions | |
Emitter (std::ostream &out) | |
~Emitter () override | |
void | flush () |
Flush the underlying output stream. More... | |
template<typename T > | |
void | write (T const &data) |
Write method for use inside lists / arrays. More... | |
void | start_list (bool indent=true) |
Write method for use inside lists / arrays. More... | |
void | start_map (bool indent=true) |
Write method for use inside lists / arrays. More... | |
template<typename T > | |
void | write (std::string const &label, T const &data) |
Write method for use inside maps / dicts / objects. More... | |
void | start_list (std::string const &label, bool indent=true) |
Write method for use inside maps / dicts / objects. More... | |
void | start_list (const char *label, bool indent=true) |
Write method for use inside maps / dicts / objects. More... | |
void | start_map (std::string const &label, bool indent=true) |
Write method for use inside maps / dicts / objects. More... | |
void | start_map (const char *label, bool indent=true) |
Write method for use inside maps / dicts / objects. More... | |
void | end_list () |
Counterpart to start_list() – writes closing bracket. More... | |
void | end_map () |
Counterpart to start_map() – writes closing brace. More... | |
void | end (size_t desired_depth=0) |
By default, closes all open maps/lists, ending the document. More... | |
int | depth () const |
Number of closing brackets/braces required to end document (non-negative) More... | |
void | set_indent (int num_spaces) |
Number of spaces used for indenting. Default is one. More... | |
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.g. JSON) that don't allow multiple documents. More... | |
![]() | |
VirtualBase ()=default | |
Default constructor. More... | |
virtual | ~VirtualBase ()=default |
The virtual destructor is one of the main reasons for the VirtualBase class. More... | |
VirtualBase (VirtualBase const &)=default | |
VirtualBase (VirtualBase &&)=default | |
VirtualBase & | operator= (VirtualBase const &)=default |
VirtualBase & | operator= (VirtualBase &&)=default |
Protected Member Functions | |
Emitter () | |
Emitter (Emitter const &) | |
bool | assert_in (bool in_map, std::string const &msg) |
Check that we're in the expected context (either map or list) More... | |
void | write_label (std::string const &label) |
Write the key part of a key-value pair. More... | |
void | write_raw (bool b) |
void | write_raw (int i) |
void | write_raw (long l) |
void | write_raw (float f) |
void | write_raw (double d) |
void | write_raw (std::string const &s) |
std::string | escape_string (std::string const &s, bool &needs_quotes_out) |
Converts special characters (newlines, etc) to escape codes ( , etc). More... | |
virtual std::string | quote_string (std::string const &s)=0 |
Quotes strings as much as needed for this format (e.g. always for JSON). More... | |
virtual void | do_indent (bool write_comma=true)=0 |
Handle pretty-printing indentation. Don't want to use commas for opening/closing brace/bracket. More... | |
virtual void | write_list_marker ()=0 |
Used for traditional YAML output, writes the "-" marker. More... | |
virtual void | start_raw (bool is_map, bool indent)=0 |
Actual implementation of start_map() and start_list(). More... | |
virtual void | end_raw ()=0 |
Actual implementation of end_map() and end_list(). More... | |
Protected Attributes | |
std::ostream & | out_ |
std::string | indent_str_ |
std::vector< bool > | in_map_ |
std::vector< bool > | first_ |
std::vector< bool > | indent_ |
std::vector< int > | indent_depth_ |
Lightweight class to ease writting YAML documents (http://yaml.org)
YAML is a structured data format, a more human-readable alternative to XML.
I use the terms "map" and "list" here, but you may also see "mapping" and "sequence". The former is a series of key : value pairs, while the latter is a simple series of items. This class is not entirely able to enforce the generation of valid YAML – you can still e.g. write a key : value pair in the middle of a list. It will print a warning message but will otherwise try to continue on.
YAML documents have optional explicit start/end markers; if the emitter supports them, they will be auto-generated when the class is initialized and when you're finished and you call end().
Whitespace is YAML documents is semi-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. YAML refers to these two styles as "block" and "flow", respectively.
|
inline |
|
inlineoverride |
|
protected |
|
protected |
|
inlineprotected |
Check that we're in the expected context (either map or list)
References in_map_, and basic::Warning().
Referenced by end_list(), end_map(), start_list(), start_map(), and write().
|
inline |
Number of closing brackets/braces required to end document (non-negative)
References in_map_.
Referenced by basic::YamlEmitter::do_indent(), basic::JsonEmitter::do_indent(), and end().
|
protectedpure virtual |
Handle pretty-printing indentation. Don't want to use commas for opening/closing brace/bracket.
Implemented in basic::JsonEmitter, and basic::YamlEmitter.
Referenced by start_list(), start_map(), and write().
void basic::Emitter::end | ( | size_t | desired_depth = 0 | ) |
By default, closes all open maps/lists, ending the document.
References depth(), end_raw(), and create_a3b_hbs::i.
Referenced by basic::YamlEmitter::start_doc(), and basic::JsonEmitter::start_doc().
void basic::Emitter::end_list | ( | ) |
Counterpart to start_list() – writes closing bracket.
References assert_in(), and end_raw().
void basic::Emitter::end_map | ( | ) |
Counterpart to start_map() – writes closing brace.
References assert_in(), and end_raw().
|
protectedpure virtual |
Actual implementation of end_map() and end_list().
Implemented in basic::JsonEmitter, and basic::YamlEmitter.
Referenced by end(), end_list(), and end_map().
|
protected |
Converts special characters (newlines, etc) to escape codes (
, etc).
Anything but the most basic characters needs to be quoted and escaped. For normal YAML, very simple text can be output without quotes, though.
needs_quotes_out | will be set to true if string contains "special" characters. |
References basic::options::OptionKeys::out::file::o, and docking::s.
Referenced by basic::YamlEmitter::quote_string(), and basic::JsonEmitter::quote_string().
|
inline |
Flush the underlying output stream.
References out_.
|
protectedpure virtual |
Quotes strings as much as needed for this format (e.g. always for JSON).
Implemented in basic::JsonEmitter, and basic::YamlEmitter.
Referenced by write_label(), and write_raw().
|
inline |
Number of spaces used for indenting. Default is one.
References create_a3b_hbs::i, indent_str_, and docking::s.
|
pure virtual |
Start a new document, ending the previous one first if necessary. A no-op for some types of output (e.g. JSON) that don't allow multiple documents.
Implemented in basic::JsonEmitter, and basic::YamlEmitter.
void basic::Emitter::start_list | ( | bool | indent = true | ) |
Write method for use inside lists / arrays.
References assert_in(), do_indent(), binder::indent(), and start_raw().
Referenced by start_list().
void basic::Emitter::start_list | ( | const char * | label, |
bool | indent = true |
||
) |
Write method for use inside maps / dicts / objects.
References assert_in(), do_indent(), binder::indent(), predPRE::label, start_raw(), and write_label().
|
inline |
Write method for use inside maps / dicts / objects.
References binder::indent(), predPRE::label, and start_list().
void basic::Emitter::start_map | ( | bool | indent = true | ) |
Write method for use inside lists / arrays.
References assert_in(), do_indent(), binder::indent(), and start_raw().
Referenced by start_map().
void basic::Emitter::start_map | ( | const char * | label, |
bool | indent = true |
||
) |
Write method for use inside maps / dicts / objects.
References assert_in(), do_indent(), binder::indent(), predPRE::label, start_raw(), and write_label().
|
inline |
Write method for use inside maps / dicts / objects.
References binder::indent(), predPRE::label, and start_map().
|
protectedpure virtual |
Actual implementation of start_map() and start_list().
Implemented in basic::JsonEmitter, and basic::YamlEmitter.
Referenced by start_list(), and start_map().
void basic::Emitter::write | ( | std::string const & | label, |
T const & | data | ||
) |
Write method for use inside maps / dicts / objects.
References assert_in(), data, do_indent(), predPRE::label, write_label(), and write_raw().
void basic::Emitter::write | ( | T const & | data | ) |
Write method for use inside lists / arrays.
References assert_in(), data, do_indent(), write_list_marker(), and write_raw().
|
inlineprotected |
Write the key part of a key-value pair.
References predPRE::label, out_, and quote_string().
Referenced by start_list(), start_map(), and write().
|
protectedpure virtual |
Used for traditional YAML output, writes the "-" marker.
Implemented in basic::JsonEmitter, and basic::YamlEmitter.
Referenced by write().
|
inlineprotected |
References compute_difference::b, and out_.
Referenced by write().
|
inlineprotected |
References create_a3b_hbs::f, and out_.
|
inlineprotected |
References create_a3b_hbs::i, and out_.
|
inlineprotected |
References extract_by_sidechain_sasa_score::l, and out_.
|
inlineprotected |
References out_, quote_string(), and docking::s.
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
Referenced by basic::YamlEmitter::do_indent(), basic::JsonEmitter::do_indent(), and set_indent().
|
protected |
Referenced by basic::YamlEmitter::do_indent(), basic::JsonEmitter::do_indent(), basic::YamlEmitter::end_raw(), basic::JsonEmitter::end_raw(), flush(), basic::YamlEmitter::start_doc(), basic::YamlEmitter::start_raw(), basic::JsonEmitter::start_raw(), write_label(), basic::YamlEmitter::write_list_marker(), and write_raw().