44 G_EXCEPTION( Error ,
"item error" ) ;
45 G_EXCEPTION( ParseError ,
"item error: parsing failed" ) ;
46 enum Type { t_string , t_list , t_map } m_type ;
57 static Item parse(
const std::string & ) ;
64 explicit Item( Type
type = t_string ) ;
67 explicit Item(
const std::string & s ) ;
86 void add(
const std::string & s ) ;
92 void add(
const std::string & k ,
const std::string & s ) ;
95 void add(
const std::string & k ,
const Item & i ) ;
98 bool has(
const std::string & k )
const ;
101 void remove(
const std::string & k ) ;
107 size_t size()
const ;
116 void out( std::ostream & s ,
int indent = -1 )
const ;
119 void in( std::istream & s ) ;
122 std::string
str(
int indent = -1 )
const ;
126 void check( Type type )
const ;
127 void checkNot( Type type )
const ;
129 void need(
const std::string & k )
const ;
130 void need(
size_t i )
const ;
131 void update(
const std::string & k ) ;
132 static bool less(
const Item & a ,
const Item & b ) ;
133 void clear( Type type = t_string ) ;
134 void read( std::istream & ,
char eos ) ;
135 void readn( std::istream & ,
char ) ;
136 static bool escaped(
const std::string & s ) ;
137 static void unescape( std::string & s ) ;
138 static void unescape( std::string & s ,
char bs ,
const char * map_in ,
const char * map_out ) ;
141 typedef std::map<std::string,Item> Map ;
142 std::string m_string ;
143 std::vector<Item> m_list ;
145 std::vector<std::string> m_keys ;
151 std::ostream & operator<<( std::ostream & stream ,
const Item & item )
157 std::istream & operator>>( std::istream & stream , Item & item )
void out(std::ostream &s, int indent=-1) const
Does output streaming, using a json-like format.
static Item map()
Factory function for a map item.
size_t size() const
Returns the size of this map-or-list item.
bool empty() const
Returns true if an empty item.
void in(std::istream &s)
Does input parsing. Throws on error.
std::string str(int indent=-1) const
Returns a string representation, using a json-like format.
static Item parse(const std::string &)
Parses the string representation. Throws on error.
static Item list()
Factory function for a list item.
const Item & operator[](const std::string &k) const
Indexing operator for a map item. Throws if no such item.
std::string operator()() const
Returns the value of this string item.
A variant class holding a string, an item map keyed by name, or an ordered list of items...
void add(const std::string &s)
Adds a string item to this list item.
static Item string()
Factory function for a string item.
Item(Type type=t_string)
Constructor.
Item keys() const
Returns the keys of this map item as a list of string items.
bool has(const std::string &k) const
Returns true if this map item has the named key.
Type type() const
Returns the item type (string, list or map).