1 #ifndef ERF_DESCRIPTION_WRITER_H_
2 #define ERF_DESCRIPTION_WRITER_H_
4 #include <AMReX_BLassert.H>
31 first.push_back(
true);
36 AMREX_ASSERT(
first.size() > 1);
43 AMREX_ASSERT(
first.size() == 1);
44 if (!
yaml) {
os <<
'}';
if (newline)
os <<
'\n'; }
65 if (v ==
nullptr)
os <<
"null";
73 value(
name, v !=
nullptr && *v !=
'\0' ? v :
nullptr);
76 void strings (
const char*
name,
const std::vector<std::string>& values)
80 for (std::size_t i = 0; i < values.size(); ++i) {
88 template <
class T,
class Emit>
89 void objects (
const char*
name,
const std::vector<T>& values, Emit emit)
93 for (std::size_t i = 0; i < values.size(); ++i) {
96 emit(item, values[i]);
108 void key (
const char*
name,
bool object =
false)
111 os << std::string((
first.size() - 1) * 2,
' ');
114 if (!
object)
os <<
' ';
120 first.back() =
false;
127 constexpr
char hex[] =
"0123456789abcdef";
129 for (
const auto* c =
reinterpret_cast<const unsigned char*
>(
value); *c; ++c) {
130 if (*c ==
'"' || *c ==
'\\') {
131 os << '\\' << static_cast<char>(*c);
132 }
else if (*c < 0x20 || *c == 0x7f) {
133 os <<
"\\u00" << hex[*c >> 4] << hex[*c & 15];
134 }
else if (*c == 0xc2 && c[1] >= 0x80 && c[1] <= 0x9f) {
137 os <<
"\\u00" << hex[*c >> 4] << hex[*c & 15];
138 }
else if (*c == 0xe2 && c[1] == 0x80 && (c[2] == 0xa8 || c[2] == 0xa9)) {
140 os <<
"\\u202" << (c[2] == 0xa8 ?
'8' :
'9');
143 os << static_cast<char>(*c);
std::string name
Definition: ERF_Plotfile2DCatalog.cpp:139
Definition: ERF_DescriptionWriter.H:20
void finish(bool newline=true)
Definition: ERF_DescriptionWriter.H:41
void value(const char *name, bool v)
Definition: ERF_DescriptionWriter.H:52
bool yaml
Definition: ERF_DescriptionWriter.H:105
Writer(std::ostream &output, Format format)
Definition: ERF_DescriptionWriter.H:22
void value(const char *name, std::nullptr_t)
Definition: ERF_DescriptionWriter.H:47
void value(const char *name, int v)
Definition: ERF_DescriptionWriter.H:57
void optional_string(const char *name, const char *v)
Definition: ERF_DescriptionWriter.H:71
void objects(const char *name, const std::vector< T > &values, Emit emit)
Definition: ERF_DescriptionWriter.H:89
std::vector< bool > first
Definition: ERF_DescriptionWriter.H:106
void quoted(const char *value)
Definition: ERF_DescriptionWriter.H:125
void key(const char *name, bool object=false)
Definition: ERF_DescriptionWriter.H:108
void begin_object(const char *name)
Definition: ERF_DescriptionWriter.H:27
void strings(const char *name, const std::vector< std::string > &values)
Definition: ERF_DescriptionWriter.H:76
std::ostream & os
Definition: ERF_DescriptionWriter.H:104
void end_value()
Definition: ERF_DescriptionWriter.H:123
void end_object()
Definition: ERF_DescriptionWriter.H:34
void value(const char *name, const char *v)
Definition: ERF_DescriptionWriter.H:62
Definition: ERF_DescriptionWriter.H:11
Format
Definition: ERF_DescriptionWriter.H:13