aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/json.ixx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2024-02-13 11:05:37 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2024-02-13 11:05:37 +0200
commitfc1fb583de222caecdb956c623765b6a1a047937 (patch)
tree144391aab338f11687a5584287d4e32943e21fd6 /libbuild2/json.ixx
parent20e49b4e63779abc0e25bec4c74399a83ec8a83c (diff)
Extend json_value C++ interface
Diffstat (limited to 'libbuild2/json.ixx')
-rw-r--r--libbuild2/json.ixx127
1 files changed, 127 insertions, 0 deletions
diff --git a/libbuild2/json.ixx b/libbuild2/json.ixx
index c2b8845..76cd00a 100644
--- a/libbuild2/json.ixx
+++ b/libbuild2/json.ixx
@@ -3,6 +3,119 @@
namespace build2
{
+ [[noreturn]] LIBBUILD2_SYMEXPORT void
+ json_as_throw (json_type actual, json_type expected);
+
+ inline bool json_value::
+ as_bool () const
+ {
+ if (type == json_type::boolean)
+ return boolean;
+
+ json_as_throw (type, json_type::boolean);
+ }
+
+ inline bool& json_value::
+ as_bool ()
+ {
+ if (type == json_type::boolean)
+ return boolean;
+
+ json_as_throw (type, json_type::boolean);
+ }
+
+ inline int64_t json_value::
+ as_int64 () const
+ {
+ if (type == json_type::signed_number)
+ return signed_number;
+
+ json_as_throw (type, json_type::signed_number);
+ }
+
+ inline int64_t& json_value::
+ as_int64 ()
+ {
+ if (type == json_type::signed_number)
+ return signed_number;
+
+ json_as_throw (type, json_type::signed_number);
+ }
+
+ inline uint64_t json_value::
+ as_uint64 () const
+ {
+ if (type == json_type::unsigned_number ||
+ type == json_type::hexadecimal_number)
+ return unsigned_number;
+
+ json_as_throw (type, json_type::unsigned_number);
+ }
+
+ inline uint64_t& json_value::
+ as_uint64 ()
+ {
+ if (type == json_type::unsigned_number ||
+ type == json_type::hexadecimal_number)
+ return unsigned_number;
+
+ json_as_throw (type, json_type::unsigned_number);
+ }
+
+ inline const string& json_value::
+ as_string () const
+ {
+ if (type == json_type::string)
+ return string;
+
+ json_as_throw (type, json_type::string);
+ }
+
+ inline string& json_value::
+ as_string ()
+ {
+ if (type == json_type::string)
+ return string;
+
+ json_as_throw (type, json_type::string);
+ }
+
+ inline const json_value::array_type& json_value::
+ as_array () const
+ {
+ if (type == json_type::array)
+ return array;
+
+ json_as_throw (type, json_type::array);
+ }
+
+ inline json_value::array_type& json_value::
+ as_array ()
+ {
+ if (type == json_type::array)
+ return array;
+
+ json_as_throw (type, json_type::array);
+ }
+
+ inline const json_value::object_type& json_value::
+ as_object () const
+ {
+ if (type == json_type::object)
+ return object;
+
+ json_as_throw (type, json_type::object);
+ }
+
+ inline json_value::object_type& json_value::
+ as_object ()
+ {
+ if (type == json_type::object)
+ return object;
+
+ json_as_throw (type, json_type::object);
+ }
+
inline json_value::
~json_value () noexcept
{
@@ -81,6 +194,19 @@ namespace build2
return at (n.c_str ());
}
+ inline const json_value* json_value::
+ find (const string_type& n) const
+ {
+ return find (n.c_str ());
+ }
+
+ inline json_value* json_value::
+ find (const string_type& n)
+ {
+ return find (n.c_str ());
+ }
+
+#if 0
inline const json_value& json_value::
operator[] (const string_type& n) const
{
@@ -92,6 +218,7 @@ namespace build2
{
return operator[] (n.c_str ());
}
+#endif
inline json_value::
json_value (json_value&& v) noexcept