VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
G::Item Class Reference

A variant class holding a string, an item map keyed by name, or an ordered list of items. More...

#include <gitem.h>

Public Types

enum  Type { t_string, t_list, t_map }
 

Public Member Functions

 Item (Type type=t_string)
 Constructor.
 
 Item (const std::string &s)
 Constructor for a string item.
 
Type type () const
 Returns the item type (string, list or map).
 
const Itemoperator[] (const std::string &k) const
 Indexing operator for a map item. Throws if no such item.
 
Itemoperator[] (const std::string &k)
 Indexing operator for a map item. More...
 
Itemoperator[] (size_t i)
 Indexing operator for a list item. Throws if out of range.
 
const Itemoperator[] (size_t i) const
 Indexing operator for a list item. Throws if out of range.
 
void add (const std::string &s)
 Adds a string item to this list item.
 
void add (Item i)
 Adds an item to this list item.
 
void add (const std::string &k, const std::string &s)
 Adds a string item to this map item. Replaces any pre-existing item with that key.
 
void add (const std::string &k, const Item &i)
 Adds an item to this map item. Replaces any pre-existing item with that key.
 
bool has (const std::string &k) const
 Returns true if this map item has the named key.
 
void remove (const std::string &k)
 Removes an item from this map item.
 
Item keys () const
 Returns the keys of this map item as a list of string items.
 
size_t size () const
 Returns the size of this map-or-list item.
 
bool empty () const
 Returns true if an empty item.
 
std::string operator() () const
 Returns the value of this string item.
 
void out (std::ostream &s, int indent=-1) const
 Does output streaming, using a json-like format.
 
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 Public Member Functions

static Item list ()
 Factory function for a list item.
 
static Item map ()
 Factory function for a map item.
 
static Item string ()
 Factory function for a string item.
 
static Item parse (const std::string &)
 Parses the string representation. Throws on error.
 
static bool parse (const std::string &, Item &out)
 A non-throwing overload to parse the string representation. More...
 

Public Attributes

enum G::Item::Type m_type
 

Detailed Description

A variant class holding a string, an item map keyed by name, or an ordered list of items.

The definition is recursive, so items can be nested. The string representation is curiously json-like.

Definition at line 41 of file gitem.h.

Member Function Documentation

G::Item & G::Item::operator[] ( const std::string &  k)

Indexing operator for a map item.

Creates an empty string item if no such item initially.

Definition at line 96 of file gitem.cpp.

bool G::Item::parse ( const std::string &  s,
Item out 
)
static

A non-throwing overload to parse the string representation.

Returns false on error.

Definition at line 52 of file gitem.cpp.


The documentation for this class was generated from the following files: