aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2023-03-28 10:02:45 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2023-03-28 10:02:45 +0200
commit96dfc87c05110c3d857fe6d1c6eaeb139e91826c (patch)
tree1ab30f6a88f428b89f3e19a94c7755bf63a4d1b7
parentd37263139e511b3dbfea2bd355f5edd779a71324 (diff)
Add member_begin_{object,array}() shortcuts to JSON serializer
-rw-r--r--libbutl/json/serializer.hxx22
-rw-r--r--libbutl/json/serializer.ixx28
2 files changed, 50 insertions, 0 deletions
diff --git a/libbutl/json/serializer.hxx b/libbutl/json/serializer.hxx
index b52bf65..c143dab 100644
--- a/libbutl/json/serializer.hxx
+++ b/libbutl/json/serializer.hxx
@@ -167,10 +167,21 @@ namespace butl
// Begin/end an object.
//
+ // The member_begin_object() version is a shortcut for:
+ //
+ // member_name (name, check);
+ // begin_object ();
+ //
void
begin_object ();
void
+ member_begin_object (const char*, bool check = true);
+
+ void
+ member_begin_object (const std::string&, bool check = true);
+
+ void
end_object ();
// Serialize an object member (name and value).
@@ -199,10 +210,21 @@ namespace butl
// Begin/end an array.
//
+ // The member_begin_array() version is a shortcut for:
+ //
+ // member_name (name, check);
+ // begin_array ();
+ //
void
begin_array ();
void
+ member_begin_array (const char*, bool check = true);
+
+ void
+ member_begin_array (const std::string&, bool check = true);
+
+ void
end_array ();
// Serialize a string.
diff --git a/libbutl/json/serializer.ixx b/libbutl/json/serializer.ixx
index 50fe397..ac6ea22 100644
--- a/libbutl/json/serializer.ixx
+++ b/libbutl/json/serializer.ixx
@@ -81,6 +81,20 @@ namespace butl
next (event::name, {n.c_str (), n.size ()}, c);
}
+ inline void buffer_serializer::
+ member_begin_object (const char* n, bool c)
+ {
+ member_name (n, c);
+ begin_object ();
+ }
+
+ inline void buffer_serializer::
+ member_begin_object (const std::string& n, bool c)
+ {
+ member_name (n, c);
+ begin_object ();
+ }
+
template <typename T>
inline void buffer_serializer::
member (const char* n, const T& v, bool c)
@@ -104,6 +118,20 @@ namespace butl
}
inline void buffer_serializer::
+ member_begin_array (const char* n, bool c)
+ {
+ member_name (n, c);
+ begin_array ();
+ }
+
+ inline void buffer_serializer::
+ member_begin_array (const std::string& n, bool c)
+ {
+ member_name (n, c);
+ begin_array ();
+ }
+
+ inline void buffer_serializer::
end_array ()
{
next (event::end_array);