From 96dfc87c05110c3d857fe6d1c6eaeb139e91826c Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 28 Mar 2023 10:02:45 +0200 Subject: Add member_begin_{object,array}() shortcuts to JSON serializer --- libbutl/json/serializer.hxx | 22 ++++++++++++++++++++++ libbutl/json/serializer.ixx | 28 ++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) (limited to 'libbutl') 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 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); -- cgit v1.1