diff --git a/include/jsonbuilder/JsonBuilder.h b/include/jsonbuilder/JsonBuilder.h index 7e05538..cc21b1e 100644 --- a/include/jsonbuilder/JsonBuilder.h +++ b/include/jsonbuilder/JsonBuilder.h @@ -1283,8 +1283,8 @@ class JsonBuilder const_iterator const& itParent, NameStringView const& name, JsonType type, - unsigned cbData = 0, - _In_reads_bytes_(cbData) void const* pbData = nullptr) + unsigned cbData, + _In_reads_bytes_opt_(cbData) void const* pbData) noexcept(false) // may throw bad_alloc, length_error { std::basic_string_view nameView{ name }; @@ -1310,8 +1310,8 @@ class JsonBuilder const_iterator const& itParent, NameStringView const& name, JsonType type, - unsigned cbData = 0, - _In_reads_bytes_(cbData) void const* pbData = nullptr) + unsigned cbData, + _In_reads_bytes_opt_(cbData) void const* pbData) noexcept(false) // may throw bad_alloc, length_error { std::basic_string_view nameView{ name }; @@ -1337,8 +1337,8 @@ class JsonBuilder const_iterator const& itParent, NameStringView const& name, JsonType type, - unsigned cbData = 0, - _In_reads_bytes_(cbData) void const* pbData = nullptr) + unsigned cbData, + _In_reads_bytes_opt_(cbData) void const* pbData) noexcept(false) // may throw bad_alloc, length_error { std::basic_string_view nameView{ name }; @@ -1357,6 +1357,7 @@ class JsonBuilder Data must be a supported type. Supported types include: + - For null, array, object: JsonType (JsonNull, JsonArray, JsonObject). - For boolean data: bool. - For UTF-8 string data: std::string_view, char*. - For integer data: signed and unsigned char, short, int, long, long long. @@ -1401,6 +1402,7 @@ class JsonBuilder Data must be a supported type. Supported types include: + - For null, array, object: JsonType (JsonNull, JsonArray, JsonObject). - For boolean data: bool. - For UTF-8 string data: std::string_view, char*. - For integer data: signed and unsigned char, short, int, long, long long. @@ -1444,6 +1446,7 @@ class JsonBuilder Data must be a supported type. Supported types include: + - For null, array, object: JsonType (JsonNull, JsonArray, JsonObject). - For boolean data: bool. - For UTF-8 string data: std::string_view, char*. - For integer data: signed and unsigned char, short, int, long, long long. @@ -1602,8 +1605,8 @@ private: const_iterator const& itParent, NameStringView nameView, JsonType type, - unsigned cbData = 0, - _In_reads_bytes_(cbData) void const* pbData = nullptr) + unsigned cbData, + _In_reads_bytes_opt_(cbData) void const* pbData) noexcept(false) // may throw bad_alloc, length_error { using char_type = typename JsonInternal::CharTypeOk::char_type; @@ -2015,6 +2018,8 @@ JSON_DECLARE_JsonImplementType_AddValueSz(wchar_t); JSON_DECLARE_JsonImplementType_AddValueSz(char16_t); JSON_DECLARE_JsonImplementType_AddValueSz(char32_t); +JSON_DECLARE_JsonImplementType_AddValue(JsonType, ); // For null, array, object. + #ifdef __cpp_lib_char8_t // Support u8string_view and char8_t, inline so they work even if lib builds as C++17. // JSON_DECLARE_JsonImplementType(std::u8string_view,, ): diff --git a/src/JsonBuilder.cpp b/src/JsonBuilder.cpp index 90c1bce..8234f71 100644 --- a/src/JsonBuilder.cpp +++ b/src/JsonBuilder.cpp @@ -2026,4 +2026,22 @@ JsonImplementType::GetUnchecked(JsonValue const& jsonValue) noexcept emptyUuid; } +// JsonType + +JsonIterator +JsonImplementType::AddValueCommit( + JsonBuilder& builder, + JsonType type) +{ + // This method is only for 0-size values like null, array, or object. + // The following types cannot have 0-size values and should not call this: + assert(type != JsonUInt); + assert(type != JsonInt); + assert(type != JsonFloat); + assert(type != JsonBool); + assert(type != JsonTime); + assert(type != JsonUuid); + return builder._newValueCommit(type, 0, nullptr); +} + } // namespace jsonbuilder