json/tree: style
This commit is contained in:
parent
580ee9e663
commit
daa2587240
@ -42,9 +42,7 @@ using namespace std;
|
|||||||
using namespace util;
|
using namespace util;
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// External support
|
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
bool
|
bool
|
||||||
is_integer (const json::tree::number &node)
|
is_integer (const json::tree::number &node)
|
||||||
@ -53,6 +51,7 @@ is_integer (const json::tree::number &node)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
template <>
|
template <>
|
||||||
bool
|
bool
|
||||||
is_integer (const json::tree::node &node)
|
is_integer (const json::tree::node &node)
|
||||||
@ -62,8 +61,7 @@ is_integer (const json::tree::node &node)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// Node
|
|
||||||
static std::vector<json::flat::item>::const_iterator
|
static std::vector<json::flat::item>::const_iterator
|
||||||
parse (std::vector<json::flat::item>::const_iterator first,
|
parse (std::vector<json::flat::item>::const_iterator first,
|
||||||
std::vector<json::flat::item>::const_iterator last,
|
std::vector<json::flat::item>::const_iterator last,
|
||||||
@ -162,7 +160,8 @@ parse (std::vector<json::flat::item>::const_iterator first,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
std::unique_ptr<json::tree::node>
|
std::unique_ptr<json::tree::node>
|
||||||
json::tree::parse (const boost::filesystem::path &path)
|
json::tree::parse (const boost::filesystem::path &path)
|
||||||
{
|
{
|
||||||
@ -171,21 +170,25 @@ json::tree::parse (const boost::filesystem::path &path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
std::unique_ptr<json::tree::node>
|
std::unique_ptr<json::tree::node>
|
||||||
json::tree::parse (const std::string &path)
|
json::tree::parse (const std::string &path)
|
||||||
{ return parse (path.c_str (), path.c_str () + path.size ()); }
|
{ return parse (path.c_str (), path.c_str () + path.size ()); }
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
std::unique_ptr<json::tree::node>
|
std::unique_ptr<json::tree::node>
|
||||||
json::tree::parse (const char *start)
|
json::tree::parse (const char *start)
|
||||||
{ return parse (start, start + strlen (start)); }
|
{ return parse (start, start + strlen (start)); }
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
void
|
void
|
||||||
json::tree::write (const json::tree::node &node, std::ostream &os)
|
json::tree::write (const json::tree::node &node, std::ostream &os)
|
||||||
{ node.write (os); }
|
{ node.write (os); }
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
std::unique_ptr<json::tree::node>
|
std::unique_ptr<json::tree::node>
|
||||||
json::tree::parse (const char *first, const char *last)
|
json::tree::parse (const char *first, const char *last)
|
||||||
{
|
{
|
||||||
@ -208,64 +211,73 @@ json::tree::node::as_object (void) const
|
|||||||
{ throw json::type_error ("node is not an object"); }
|
{ throw json::type_error ("node is not an object"); }
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
const json::tree::array&
|
const json::tree::array&
|
||||||
json::tree::node::as_array (void) const
|
json::tree::node::as_array (void) const
|
||||||
{ throw json::type_error ("node is not an array"); }
|
{ throw json::type_error ("node is not an array"); }
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
const json::tree::string&
|
const json::tree::string&
|
||||||
json::tree::node::as_string (void) const
|
json::tree::node::as_string (void) const
|
||||||
{ throw json::type_error ("node is not a string"); }
|
{ throw json::type_error ("node is not a string"); }
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
const json::tree::number&
|
const json::tree::number&
|
||||||
json::tree::node::as_number (void) const
|
json::tree::node::as_number (void) const
|
||||||
{ throw json::type_error ("node is not a number"); }
|
{ throw json::type_error ("node is not a number"); }
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
const json::tree::boolean&
|
const json::tree::boolean&
|
||||||
json::tree::node::as_boolean (void) const
|
json::tree::node::as_boolean (void) const
|
||||||
{ throw json::type_error ("node is not a boolean"); }
|
{ throw json::type_error ("node is not a boolean"); }
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
const json::tree::null&
|
const json::tree::null&
|
||||||
json::tree::node::as_null (void) const
|
json::tree::node::as_null (void) const
|
||||||
{ throw json::type_error ("node is not a null"); }
|
{ throw json::type_error ("node is not a null"); }
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
json::tree::object&
|
json::tree::object&
|
||||||
json::tree::node::as_object (void)
|
json::tree::node::as_object (void)
|
||||||
{ throw json::type_error ("node is not an object"); }
|
{ throw json::type_error ("node is not an object"); }
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
json::tree::array&
|
json::tree::array&
|
||||||
json::tree::node::as_array (void)
|
json::tree::node::as_array (void)
|
||||||
{ throw json::type_error ("node is not an array"); }
|
{ throw json::type_error ("node is not an array"); }
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
json::tree::string&
|
json::tree::string&
|
||||||
json::tree::node::as_string (void)
|
json::tree::node::as_string (void)
|
||||||
{ throw json::type_error ("node is not a string"); }
|
{ throw json::type_error ("node is not a string"); }
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
json::tree::number&
|
json::tree::number&
|
||||||
json::tree::node::as_number (void)
|
json::tree::node::as_number (void)
|
||||||
{ throw json::type_error ("node is not a number"); }
|
{ throw json::type_error ("node is not a number"); }
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
json::tree::boolean&
|
json::tree::boolean&
|
||||||
json::tree::node::as_boolean (void)
|
json::tree::node::as_boolean (void)
|
||||||
{ throw json::type_error ("node is not a boolean"); }
|
{ throw json::type_error ("node is not a boolean"); }
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
json::tree::null&
|
json::tree::null&
|
||||||
json::tree::node::as_null (void)
|
json::tree::node::as_null (void)
|
||||||
{ throw json::type_error ("node is not a null"); }
|
{ throw json::type_error ("node is not a null"); }
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
bool
|
bool
|
||||||
json::tree::node::as_bool (void) const
|
json::tree::node::as_bool (void) const
|
||||||
{
|
{
|
||||||
@ -317,7 +329,9 @@ json::tree::node::operator!= (const node &rhs) const
|
|||||||
{ return !(*this == rhs); }
|
{ return !(*this == rhs); }
|
||||||
|
|
||||||
|
|
||||||
bool json::tree::node::operator==(const char *rhs) const {
|
//-----------------------------------------------------------------------------
|
||||||
|
bool json::tree::node::operator==(const char *rhs) const
|
||||||
|
{
|
||||||
try {
|
try {
|
||||||
return as_string ().native () == rhs;
|
return as_string ().native () == rhs;
|
||||||
} catch (const json::type_error&) {
|
} catch (const json::type_error&) {
|
||||||
@ -352,7 +366,6 @@ json::tree::node::operator[] (unsigned int idx) const
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// Object
|
// Object
|
||||||
|
|
||||||
json::tree::object::~object ()
|
json::tree::object::~object ()
|
||||||
{ ; }
|
{ ; }
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user