diff --git a/colour.cpp b/colour.cpp index ee724d55..fecd3904 100644 --- a/colour.cpp +++ b/colour.cpp @@ -36,12 +36,12 @@ colour::operator*= (double v) { const json::node& operator>> (const json::node &node, colour &c) { - c.red = node[0].to_number (); - c.green = node[1].to_number (); - c.blue = node[2].to_number (); + c.red = node[0].as_number (); + c.green = node[1].as_number (); + c.blue = node[2].as_number (); try { - c.alpha = node[3].to_number (); + c.alpha = node[3].as_number (); } catch (...) { c.alpha = 1.0; } diff --git a/json.cpp.rl b/json.cpp.rl index f8aa5e82..c008b4a4 100644 --- a/json.cpp.rl +++ b/json.cpp.rl @@ -281,27 +281,27 @@ json::write (const json::node &node, std::ostream &os) const json::object& -json::node::to_object (void) const +json::node::as_object (void) const { throw parse_error ("node is not an object"); } const json::array& -json::node::to_array (void) const +json::node::as_array (void) const { throw parse_error ("node is not an array"); } const json::string& -json::node::to_string (void) const +json::node::as_string (void) const { throw parse_error ("node is not a string"); } const json::number& -json::node::to_number (void) const +json::node::as_number (void) const { throw parse_error ("node is not a number"); } const json::boolean& -json::node::to_boolean (void) const +json::node::as_boolean (void) const { throw parse_error ("node is not a boolean"); } @@ -311,17 +311,17 @@ json::node::operator!=(const node &rhs) const bool json::node::operator==(const char *rhs) const - { return to_string () == rhs; } + { return as_string () == rhs; } const json::node& json::node::operator[] (const std::string &key) const - { return to_object ()[key]; } + { return as_object ()[key]; } const json::node& json::node::operator[] (unsigned int idx) const - { return to_array()[idx]; } + { return as_array()[idx]; } /* * Object diff --git a/json.hpp b/json.hpp index 3be4a6a3..71b9db50 100644 --- a/json.hpp +++ b/json.hpp @@ -50,11 +50,11 @@ namespace json { public: virtual ~node () { ; } - virtual const object& to_object (void) const; - virtual const array& to_array (void) const; - virtual const string& to_string (void) const; - virtual const number& to_number (void) const; - virtual const boolean& to_boolean (void) const; + virtual const object& as_object (void) const; + virtual const array& as_array (void) const; + virtual const string& as_string (void) const; + virtual const number& as_number (void) const; + virtual const boolean& as_boolean (void) const; virtual bool is_object (void) const { return false; } virtual bool is_array (void) const { return false; } @@ -91,7 +91,7 @@ namespace json { object () { ; } virtual ~object (); - virtual const object& to_object (void) const { return *this; } + virtual const object& as_object (void) const { return *this; } virtual bool is_object (void) const { return true; } virtual bool operator==(const object &rhs) const; virtual bool operator==(const node &rhs) const @@ -116,7 +116,7 @@ namespace json { public: virtual ~array(); - virtual const array& to_array (void) const { return *this; } + virtual const array& as_array (void) const { return *this; } virtual bool is_array (void) const { return true; } virtual bool operator==(const array &rhs) const; virtual bool operator==(const node &rhs) const @@ -147,7 +147,7 @@ namespace json { string (const std::string &_value): m_value (_value) { ; } string (const char *_value): m_value (_value) { ; } - virtual const string& to_string (void) const { return *this; } + virtual const string& as_string (void) const { return *this; } virtual bool is_string (void) const { return true; } virtual bool operator==(const string &rhs) const; virtual bool operator==(const node &rhs) const @@ -169,7 +169,7 @@ namespace json { number (double _value): m_value (_value) { ; } number (int _value): m_value (_value) { ; } - virtual const number& to_number (void) const { return *this; } + virtual const number& as_number (void) const { return *this; } virtual bool is_number (void) const { return true; } virtual bool operator==(const number &rhs) const; virtual bool operator==(const node &rhs) const @@ -190,7 +190,7 @@ namespace json { public: boolean (bool _value): m_value (_value) { ; } - virtual const boolean& to_boolean (void) const { return *this; } + virtual const boolean& as_boolean (void) const { return *this; } virtual bool is_boolean (void) const { return true; } virtual bool operator==(const boolean &rhs) const; virtual bool operator==(const node &rhs) const diff --git a/range.cpp b/range.cpp index ae33671a..8151a53e 100644 --- a/range.cpp +++ b/range.cpp @@ -18,17 +18,17 @@ using namespace util; template range::range (const json::node &node) { - if (node.is_string () && (node.to_string () == "UNIT" || - node.to_string () == "unit")) { + if (node.is_string () && (node.as_string () == "UNIT" || + node.as_string () == "unit")) { min = UNIT.min; max = UNIT.max; - } else if (node.is_string () && (node.to_string () == "UNLIMITED" || - node.to_string () == "unlimited")) { + } else if (node.is_string () && (node.as_string () == "UNLIMITED" || + node.as_string () == "unlimited")) { min = UNLIMITED.min; max = UNLIMITED.max; } else { - min = node[0].to_number (); - max = node[1].to_number (); + min = node[0].as_number (); + max = node[1].as_number (); } sanity (); diff --git a/vector.cpp b/vector.cpp index 82b7862c..27d0dd85 100644 --- a/vector.cpp +++ b/vector.cpp @@ -206,9 +206,9 @@ operator<< (std::ostream &os, const util::vector &v) { const json::node& operator>> (const json::node &node, util::vector &v) { - v.x = node[0].to_number (); - v.y = node[1].to_number (); - v.z = node[2].to_number (); + v.x = node[0].as_number (); + v.y = node[1].as_number (); + v.z = node[2].as_number (); return node; }