Add more convenient array and object accessors

This commit is contained in:
Danny Robson 2011-09-23 13:45:09 +10:00
parent a3c602407f
commit c3ad96f88e
2 changed files with 16 additions and 1 deletions

View File

@ -304,6 +304,15 @@ json::node::operator!=(const node &rhs) const
{ return !(*this == rhs); }
const json::node&
json::node::operator[] (const std::string &key) const
{ return to_object ()[key]; }
const json::node&
json::node::operator[] (unsigned int idx) const
{ return to_array()[idx]; }
/*
* Object
*/

View File

@ -69,8 +69,10 @@ namespace json {
virtual bool operator==(const boolean &) const { return false; }
virtual bool operator==(const null &) const { return false; }
virtual std::ostream& print (std::ostream &os) const = 0;
virtual const node& operator[] (const std::string&) const;
virtual const node& operator[] (unsigned int) const;
virtual std::ostream& print (std::ostream &os) const = 0;
};
@ -146,6 +148,7 @@ namespace json {
{ return rhs == *this; }
operator const std::string&(void) const { return m_value; }
const std::string& native (void) const { return m_value; }
virtual std::ostream& print (std::ostream &os) const;
};
@ -167,6 +170,7 @@ namespace json {
{ return rhs == *this; }
operator double(void) const { return m_value; }
double native (void) const { return m_value; }
virtual std::ostream& print (std::ostream &os) const;
};
@ -186,6 +190,8 @@ namespace json {
virtual bool operator==(const node &rhs) const
{ return rhs == *this; }
bool native (void) const { return m_value; }
virtual std::ostream& print (std::ostream &os) const;
};