64 return "{\n" +
m_stream.str() +
"\n}\n";
69 template <
class T>
void put(
const std::string& key,
const T& value)
79 template <
class T>
void put(
const std::string& key,
const std::map<std::string, T>& value)
85 for (
char unused : key) {
100 std::string
escape(
const std::string& value)
const;
102 std::string
escape(
const char* value)
const {
return escape(std::string(value)); }
104 template <
class T> std::string
escape(
const T& value)
const {
return std::to_string(value); }
106 template <
class T> std::string
escape(
const std::vector<T>& value)
const
108 std::string delim =
"";
110 for (
auto el : value) {
118 template <
class T> std::string
escape(
const std::map<std::string, T>& value)
const
122 for (
auto pair : value)
123 printer.
put(pair.first, pair.second);
create human-readable or JSON output for key value pairs.
std::string escape(const std::map< std::string, T > &value) const
escape map<string, T>.
void put(const std::string &key, const std::map< std::string, T > &value)
Specialization for map<>
void put(const std::string &key, const T &value)
Add one key-value pair.
std::string escape(const char *value) const
escape string literals.
unsigned m_maxpad
for human-readable output: how much padding after key?
std::stringstream m_stream
output being built.
std::string escape(const std::string &value) const
escape string.
std::string escape(const T &value) const
escape numeric value.
bool m_json
create JSON output?
std::string m_delim
for JSON: comma to print after prev entry.
std::string string() const
Return completed string.
KeyValuePrinter(bool use_json, unsigned key_max_length=10)
Ctor.
std::string escape(const std::vector< T > &value) const
escape vector<T>.
Abstract base class for different kinds of events.