12#ifndef ZYPP_BASE_JSON_H
13#define ZYPP_BASE_JSON_H
32 inline static const std::string &
nullJSON() {
static const std::string _s(
"null" );
return _s; }
33 inline static const std::string &
trueJSON() {
static const std::string _s(
"true" );
return _s; }
34 inline static const std::string &
falseJSON() {
static const std::string _s(
"false" );
return _s; }
41 typedef unsigned char uchar;
43 std::string::size_type add = 2;
80 for ( ;
r !=
val_r.rend(); ++
r )
84 static const char *
digit =
"0123456789abcdef";
119 switch ( (*
w++ = *
r) )
159 template <
class V> std::string
toJSON(
const std::vector<V> &
cont_r );
160 template <
class V> std::string
toJSON(
const std::list<V> &
cont_r );
161 template <
class V> std::string
toJSON(
const std::set<V> &
cont_r );
164 template <
class K,
class V> std::string
toJSON(
const std::map<K,V> &
cont_r );
232 {
return obj.dumpOn(
str ); }
261 template <
class Iterator>
303 {
return obj.dumpOn(
str ); }
326 template <
class Iterator>
340 void add(
const std::initializer_list<std::pair<String, Value>> &
contents_r )
360 return str << endl <<
'}';
364 std::ostream &
dumpOn( std::ostream &
str, std::map<std::string,std::string>::const_iterator
val_r )
const
367 std::map<std::string,std::string>
_data;
372 {
return obj.dumpOn(
str ); }
374 template <
class K,
class V>
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
String related utilities and Regular expression matching.
std::string strEncode(std::string val_r)
static const std::string & falseJSON()
static const std::string & trueJSON()
static const std::string & nullJSON()
std::string numstring(char n, int w=0)
Easy-to use interface to the ZYPP dependency resolver.
std::ostream & dumpOn(std::ostream &str) const
Stream output.
void add(const std::initializer_list< Value > &contents_r)
std::string asJSON() const
JSON representation.
std::ostream & operator<<(std::ostream &str, const Array &obj)
Stream output.
std::list< std::string > _data
std::string asString() const
String representation.
Array(Iterator begin, Iterator end)
Construct from container iterator.
void add(const Value &val_r)
Push JSON Value to Array.
Array(const std::initializer_list< Value > &contents_r)
Construct from container initializer list { v1, v2,... }.
Object(Iterator begin, Iterator end)
Construct from map-iterator.
void add(const String &key_r, const Value &val_r)
Add key/value pair.
std::string asJSON() const
JSON representation.
std::ostream & dumpOn(std::ostream &str, std::map< std::string, std::string >::const_iterator val_r) const
std::ostream & dumpOn(std::ostream &str) const
Stream output.
std::ostream & operator<<(std::ostream &str, const Object &obj)
Stream output.
void add(const std::initializer_list< std::pair< String, Value > > &contents_r)
std::string asString() const
String representation.
std::map< std::string, std::string > _data
Object(const std::initializer_list< std::pair< String, Value > > &contents_r)
Construct from map-initializer list { {k1,v1}, {k2,v2},... }.
JSON string Force representation as JSON string, mapping e.g.
String(const char *val_r)
String(const std::string &val_r)
JSON representation of datatypes via toJSON.
std::ostream & dumpOn(std::ostream &str) const
Stream output.
std::ostream & operator<<(std::ostream &str, const Value &obj)
Stream output.
Value()
Default ctor (null)
const std::string & asString() const
String representation.
const std::string & asJSON() const
JSON representation.
Value(const Value &rhs)
Copy ctor.
Value(const T &val_r)
Ctor creating a JSON representation of T via toJSON(T)
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...
#define for_(IT, BEG, END)
Convenient for-loops using iterator.