11const Value Value::empty_value;
30 if (index() == RECORD)
32 if (key == field.name)
42 if (index() == RECORD)
54 return t == INT64 || t == DOUBLE || (t == BOOL && boolisnumeric);
67 case ARRAY:
return count();
68 case RECORD:
return count();
85 case ARRAY:
return count();
86 case RECORD:
return count();
103 case ARRAY:
return count() ?
"[...]" :
"[]";
104 case RECORD:
return count() ?
"{...}" :
"{}";
107 return ip ? Jsonipc::rtti_typename (*ip) +
"{}" :
"(Instance*) nullptr";
137 if (index() == ARRAY)
139 return ValueS::empty_array;
143Value::as_record ()
const
145 if (index() == RECORD)
147 return ValueR::empty_record;
151Value::operator[] (
size_t i)
153 if (index() == ARRAY)
163 if (index() == RECORD)
177Value::operator[] (
size_t i)
const
179 if (index() == ARRAY)
182 if (i < a.size() && a[i])
185 if (index() == RECORD)
188 if (i < r.size() && r[i].value)
195Value::operator[] (
const String &name)
197 if (index() == RECORD)
203Value::operator[] (
const String &name)
const
205 if (index() == RECORD)
211value_array_to_string (
const ValueS &vec)
214 for (
auto const &valuep : vec)
216 const Value &value = valuep ? *valuep : Value::empty_value;
226value_record_to_string (
const ValueR &vec)
229 for (
auto const &field : vec)
231 const Value &value = field.value ? *field.value : Value::empty_value;
255 case NONE: s +=
"null";
break;
264 if (index() == Value::ARRAY)
268 if (index() == Value::RECORD)
271 for (
size_t i = rec.
size(); i > 0; i--)
272 if (pred (rec[i - 1]))
274 else if (rec[i - 1].value)
275 rec[i - 1].value->filter (pred);
280const ValueS ValueS::empty_array;
289 push_back (
std::move (e));
295 return value_array_to_string (*
this);
312const ValueR ValueR::empty_record;
327 return value_record_to_string (*
this);
331ValueR::peek (
const String &name)
const
333 for (
size_t i = 0; i <
size(); i++)
334 if (name == (*
this)[i].name)
335 return (*
this)[i].value;
340ValueR::valuep (
const String &name,
bool front)
342 for (
size_t i = 0; i <
size(); i++)
343 if (name == (*
this)[i].name)
345 if (!(*
this)[i].value)
347 return (*
this)[i].value;
352 return begin()->value;
362ValueR::operator[] (
const String &name)
364 return *valuep (name,
false);
368ValueR::operator[] (
const String &name)
const
370 for (
size_t i = 0; i <
size(); i++)
371 if ((*
this)[i].value && name == (*this)[i].name)
372 return *(*
this)[i].value;
373 return Value::empty_value;
377ValueField::ValueField() :
381ValueField::ValueField (
const String &nam,
const Value &val) :
385ValueField::ValueField (
const String &nam, Value &&val) :
389ValueField::ValueField (
const String &nam, ValueP val) :
404 for (
const auto &pair : enuminfo_funcs)
405 if (enumtype == *pair.first)
419 enuminfo_funcs.push_back ({ &enumtype, fun });
The Anklang C++ API namespace.
std::string string_format(const char *format, const Args &...args) __attribute__((__format__(__printf__
Format a string similar to sprintf(3) with support for std::string and std::ostringstream convertible...
String string_from_double(double value)
Convert a double into a string, using the POSIX/C locale.
int64_t int64
A 64-bit unsigned integer, use PRI*64 in format strings.
String string_from_int(int64 value)
Convert a 64bit signed integer into a string.
int64 string_to_int(const String &string, size_t *consumed, uint base)
Parse a string into a 64bit integer, optionally specifying the expected number base.
double string_to_double(const String &string)
Parse a double from a string, trying locale specific characters and POSIX/C formatting.
std::string String
Convenience alias for std::string.
String string_to_cquote(const String &str)
Returns a string as C string including double quotes.
Get auxiallary enum information.
double as_double() const
Convert Value to double or return 0.
String repr() const
Convert Value to a string representation, useful for debugging.
bool is_numeric(bool boolisnumeric=true) const
Checks if Value is a DOUBLE, INT64, or BOOL.
int64 as_int() const
Convert Value to int64 or return 0.
size_t count() const
Number of elements in a RECORD or ARRAY Value.
bool has(const String &key) const
Check for a named field in a RECORD.
String as_string() const
Convert Value to a string, not very useful for RECORD or ARRAY.
void filter(const std::function< bool(const ValueField &)> &pred)
Recursively purge/remove RECORD elements iff to pred (recordfield) == true.
StringS keys() const
List the field names of a RECORD Value.
const ValueS & as_array() const
Retrive a non-empty array if Value contains a non-empty array.