json/object: add find method
This commit is contained in:
parent
9230de8c98
commit
f333c75218
@ -422,18 +422,11 @@ json::tree::object::has (const std::string &key) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
//-----------------------------------------------------------------------------
|
||||||
json::tree::object::clear (void)
|
json::tree::object::const_iterator
|
||||||
{ m_values.clear (); }
|
json::tree::object::find (const std::string &key) const
|
||||||
|
{
|
||||||
|
return m_values.find (key);
|
||||||
void
|
|
||||||
json::tree::object::erase (const std::string &key) {
|
|
||||||
auto pos = m_values.find (key);
|
|
||||||
if (pos == m_values.end ())
|
|
||||||
throw json::error ("erasing invalid key");
|
|
||||||
|
|
||||||
m_values.erase (key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -449,6 +442,35 @@ json::tree::object::end (void) const
|
|||||||
{ return m_values.end (); }
|
{ return m_values.end (); }
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
size_t
|
||||||
|
json::tree::object::size (void) const
|
||||||
|
{
|
||||||
|
return m_values.size ();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void
|
||||||
|
json::tree::object::clear (void)
|
||||||
|
{
|
||||||
|
m_values.clear ();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void
|
||||||
|
json::tree::object::erase (const std::string &key)
|
||||||
|
{
|
||||||
|
auto pos = m_values.find (key);
|
||||||
|
if (pos == m_values.end ())
|
||||||
|
throw json::error ("erasing invalid key");
|
||||||
|
|
||||||
|
m_values.erase (key);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
std::ostream&
|
std::ostream&
|
||||||
json::tree::object::write (std::ostream &os) const
|
json::tree::object::write (std::ostream &os) const
|
||||||
{
|
{
|
||||||
|
@ -134,14 +134,18 @@ namespace json { namespace tree {
|
|||||||
virtual node& operator[](const std::string &key);
|
virtual node& operator[](const std::string &key);
|
||||||
virtual bool has (const std::string&) const;
|
virtual bool has (const std::string&) const;
|
||||||
|
|
||||||
virtual void clear (void);
|
virtual const_iterator find (const std::string&) const;
|
||||||
virtual void erase (const std::string &key);
|
|
||||||
|
|
||||||
virtual const_iterator begin (void) const;
|
virtual const_iterator begin (void) const;
|
||||||
virtual const_iterator end (void) const;
|
virtual const_iterator end (void) const;
|
||||||
virtual const_iterator cbegin (void) const { return begin (); }
|
virtual const_iterator cbegin (void) const { return begin (); }
|
||||||
virtual const_iterator cend (void) const { return end (); }
|
virtual const_iterator cend (void) const { return end (); }
|
||||||
|
|
||||||
|
virtual size_t size (void) const;
|
||||||
|
|
||||||
|
virtual void clear (void);
|
||||||
|
virtual void erase (const std::string &key);
|
||||||
|
|
||||||
virtual std::ostream& write (std::ostream &os) const;
|
virtual std::ostream& write (std::ostream &os) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user