Belle II Software light-2406-ragdoll
|
create human-readable or JSON output for key value pairs. More...
#include <KeyValuePrinter.h>
Public Member Functions | |
KeyValuePrinter (bool use_json, unsigned key_max_length=10) | |
Ctor. | |
std::string | string () const |
Return completed string. | |
template<class T > | |
void | put (const std::string &key, const T &value) |
Add one key-value pair. | |
template<class T > | |
void | put (const std::string &key, const std::map< std::string, T > &value) |
Specialization for map<> | |
Private Member Functions | |
std::string | escape (const std::string &value) const |
escape string. | |
std::string | escape (const char *value) const |
escape string literals. | |
template<class T > | |
std::string | escape (const T &value) const |
escape numeric value. | |
template<class T > | |
std::string | escape (const std::vector< T > &value) const |
escape vector<T>. | |
template<class T > | |
std::string | escape (const std::map< std::string, T > &value) const |
escape map<string, T>. | |
Private Attributes | |
bool | m_json |
create JSON output? | |
unsigned | m_maxpad |
for human-readable output: how much padding after key? | |
std::string | m_delim |
for JSON: comma to print after prev entry. | |
std::stringstream | m_stream |
output being built. | |
create human-readable or JSON output for key value pairs.
Usage example for human-readable output:
std::string, numeric types, std::vector<SUPPORTED TYPE>, and std::map<std::string, SUPPORTED TYPE> * are supported as value types for put().
JSON output is suitable for reading via e.g. json.loads() in Python, and performs the necessary escaping for strings. Compared to boost::property_tree::json_parser::write_json, KeyValuePrinter handles non-string types correctly.
Definition at line 46 of file KeyValuePrinter.h.
|
inlineexplicit |
Ctor.
use_json | true for JSON output, false for human-readable output. |
key_max_length | for human-readable output, this should be equal to strlen(longest_key) for aligning values in output. |
Definition at line 53 of file KeyValuePrinter.h.
|
inline |
Definition at line 58 of file KeyValuePrinter.h.
|
inlineprivate |
escape string literals.
Definition at line 102 of file KeyValuePrinter.h.
|
inlineprivate |
escape map<string, T>.
Definition at line 118 of file KeyValuePrinter.h.
|
private |
escape string.
Definition at line 14 of file KeyValuePrinter.cc.
|
inlineprivate |
escape vector<T>.
Definition at line 106 of file KeyValuePrinter.h.
|
inlineprivate |
escape numeric value.
Definition at line 104 of file KeyValuePrinter.h.
|
inline |
Specialization for map<>
Definition at line 79 of file KeyValuePrinter.h.
|
inline |
Add one key-value pair.
Definition at line 69 of file KeyValuePrinter.h.
|
inline |
Return completed string.
Definition at line 61 of file KeyValuePrinter.h.
|
private |
for JSON: comma to print after prev entry.
Definition at line 96 of file KeyValuePrinter.h.
|
private |
create JSON output?
Definition at line 94 of file KeyValuePrinter.h.
|
private |
for human-readable output: how much padding after key?
Definition at line 95 of file KeyValuePrinter.h.
|
private |
output being built.
Definition at line 97 of file KeyValuePrinter.h.