Skip to content

Commit

Permalink
Bdljsn jsonnull constant drqs 175433360.1 (#4801) (#5163)
Browse files Browse the repository at this point in the history
* drqs-175433360: 'bdljsn_jsonnull': Add 'bdljsn::jsonNull' constant.

* drqs-175433360: 'bdljsn_jsonnull': Revisions per NGR 20240612.

* drqs-175433360: 'bdljsn_jsonnull.t.cpp': Fix IBM warning, per matrix build.

* drqs-175433360: 'bdljsn_jsonnull': Revisions per NGR 20240617.

drqs-175433288: 'bdljsn_json': convenience_overloads (#4799)

* drqs-175433288: 'bdljsn_json': convenience_overloads: initial

* drqs-175433288: 'bdljsn_json': Revisions per NGR 20240624.

* drqs-175433288: 'bdljsn_json': Revisions per NGR 20240702.

* drqs-175433288: 'bdljsn_json': Fix several 'bde_verify' warnings.

drqs-175775852: 'bdljsn_json', et al.: Support 'long' and 'unsigned long'. (#4826)

* drqs-175775852: 'bdl_json', et al.: Support 'long' and 'unsigned long'.

* drqs-175775852: 'bdljsn_numberutil.t.cpp': Fix per matrix build.

* drqs-175775852: 'bdljsn_numberutil': Revisions per NGR 20240716.

* drqs-175775852: 'bdljsn_numberutil': Revisions per 'bde_verify'.

* drqs-175775852: 'bdljsn_json': Revisions per 'bde_verify'.

drqs-175433310: 'bdljsn_json': Add manipulators that promote from null. (#4842)

* drqs-175433310: 'bdljsn_json': Add manipulators that promote from null.

* drqs-175433310: 'bdljsn_json.t.cpp': Fix warning on IBM per matrix build.

* drqs-175433310: 'bdljsn': Per NGR, Fixed clang warnings.

Add 'asShort' and 'asUshort' (#4950)

Add initializer_list support to bdljsn (#4819)

* Initial implementation of Json_Initializer

* Get working on C++11, clean up code

* Add basic tests for Json_Initializer

* Add some commente to the tests

* Add tests

* Rework JsonArray list ctor; more tests

* update 'assign'

* Add Json_MemberInitializer

* Respond to Nathan's phab comments (1)

* Rework JSON initializers after discussion with Nathan

* make the test helper return a string_view instead of a string

* Make many JSON ctors explicit again

* Add more tests; fix some bde-verify warnings

* Add tests for JsonObject from IL

* Remove some no-longer used code.  NFC

* Address Jake's review comments

* Exception safety in assign

* Address Jake's review comments

* Add loop curlies per Jake's request

drqs-175774817: 'bdljsn_json': Adjust to facilitate rebase. (#4991)

drqs-175774817: 'bdljsn_json': Make several mannipulators "fluent". (#4943)

* drqs-175774817: 'bdljsn_json': Make several mannipulators "fluent".

* drqs-175774817: 'bdljsn_json': Make several mannipulators "fluent".

* drqs-175774817: 'bdljsn_json': Revisions per NGR 20241008.

drqs-175433356: 'bdljsn_json': 'visit' methods (#4896)

* drqs-175433356: 'bdljsn_json': 'visit' methods: Initial. TC in progress.

* drqs-175433356: 'bdljsn_json': Revisions per HMV 20240824.

* drqs-175433356: 'bdljsn_json': Usage example for 'visit'.

* drqs-175433356: 'bdljsn_json.t.cpp': TC 47 for 'visit'.

* drqs-175774817: 'bdljsn_json.t.p': Fix rebase detritus.

* drqs-175433356: 'bdljsn_json': 'visit' revisions per NGR 20240923.

Co-authored-by: Steven Breitstein <sbreitstein@bloomberg.net>
  • Loading branch information
2 people authored and GitHub Enterprise committed Jan 15, 2025
1 parent 6d64ed8 commit 9498c63
Show file tree
Hide file tree
Showing 13 changed files with 7,980 additions and 870 deletions.
8 changes: 4 additions & 4 deletions groups/bdl/bdljsn/bdljsn_error.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1960,7 +1960,7 @@ int main(int argc, char *argv[])
objAllocatorPtr);
} break;
default: {
BSLS_ASSERT_OPT(0 == "Bad allocator config.");
BSLS_ASSERT_OPT(false && "Bad allocator config.");
} break;
}
ASSERTV(LINE, CONFIG, 2*sizeof(Obj) == fa.numBytesInUse());
Expand Down Expand Up @@ -2312,7 +2312,7 @@ int main(int argc, char *argv[])
objPtr = new (fa) Obj(Z, objAllocatorPtr);
} break;
default: {
BSLS_ASSERT_OPT(0 == "Bad allocator config.");
BSLS_ASSERT_OPT(false && "Bad allocator config.");
} break;
}
ASSERTV(LINE, CONFIG, sizeof(Obj) == fa.numBytesInUse());
Expand Down Expand Up @@ -3314,7 +3314,7 @@ int main(int argc, char *argv[])
objPtr = new (fa) Obj(LOC, MESSAGE, objAllocatorPtr);
} break;
default: {
BSLS_ASSERT_OPT(0 == "Bad allocator config.");
BSLS_ASSERT_OPT(false && "Bad allocator config.");
} break;
}
ASSERTV(LINE, CONFIG,
Expand Down Expand Up @@ -3635,7 +3635,7 @@ int main(int argc, char *argv[])
objPtr = new (fa) Obj(objAllocatorPtr);
} break;
default: {
BSLS_ASSERT_OPT(0 == "Bad allocator config.");
BSLS_ASSERT_OPT(false && "Bad allocator config.");
} break;
}

Expand Down
172 changes: 171 additions & 1 deletion groups/bdl/bdljsn/bdljsn_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ BSLS_IDENT_RCSID(bdljsn_json_cpp, "$Id$ $CSID$")

#include <bdljsn_stringutil.h>

#include <bsla_unreachable.h>

#include <bsl_ostream.h>
#include <bsl_string.h>

Expand Down Expand Up @@ -91,9 +93,156 @@ void PrintVisitor::operator()(const JsonArray& value) const

void PrintVisitor::operator()(bslmf::Nil) const
{
BSLS_ASSERT(false);
BSLA_UNREACHABLE;
BSLS_ASSERT_INVOKE_NORETURN("Unreachable");
}

#ifdef BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS
// ======================
// class ConstructVisitor
// ======================

class ConstructVisitor {
Json *d_this_p;

public:
explicit ConstructVisitor(Json *json);
// Create a 'ConstructVisitor' object configured write into the
// specified 'json'.

void operator()(const JsonNull &jNull) const;
// Store the specified 'jNull' into the Json object pointed to by
// 'd_this_p'.

void operator()(bool b) const;
// Store the specified 'b' into the Json object pointed to by
// 'd_this_p'.

void operator()(long long ll) const;
// Store the specified 'll' into the Json object pointed to by
// 'd_this_p'.

void operator()(unsigned long long ull) const;
// Store the specified 'ull' into the Json object pointed to by
// 'd_this_p'.

void operator()(double d) const;
// Store the specified 'd' into the Json object pointed to by
// 'd_this_p'.

void operator()(bdldfp::Decimal64 value) const;
// Store the specified 'value' into the Json object pointed to by
// 'd_this_p'.

void operator()(const bsl::string_view& sv) const;
// Store the specified 'sv' into the Json object pointed to by
// 'd_this_p'.

void operator()(const JsonObject *jObj) const;
// Store the object pointed to by the specified 'jObj' to the 'Json'
// object pointed to by 'd_this_p'.

void operator()(const JsonArray *jArr) const;
// Store the object pointed to by the specified 'jArr' to the 'Json'
// object pointed to by 'd_this_p'.

void operator()(const JsonNumber *jNum) const;
// Store the object pointed to by the specified 'jNum' to the 'Json'
// object pointed to by 'd_this_p'.

void operator()(const Json *json) const;
// Store the object pointed to by the specified 'json' to the 'Json'
// object pointed to by 'd_this_p'.

void operator()(std::initializer_list<Json_Initializer> il) const;
// Store a JsonArray containing the elements of the specified 'il' into
// the Json object pointed to by 'd_this_p'.

void operator()(bslmf::Nil) const;
// The behavior is undefined when this method is called.
};

// ---------------------
// class ConstructVisitor
// ---------------------

ConstructVisitor::ConstructVisitor(Json *json)
: d_this_p(json)
{
}

void ConstructVisitor::operator()(const JsonNull &jNull) const
{
(void)jNull;
}

void ConstructVisitor::operator()(bool b) const
{
d_this_p->makeBoolean(b);
}

void ConstructVisitor::operator()(long long ll) const
{
d_this_p->makeNumber(JsonNumber(ll));
}

void ConstructVisitor::operator()(unsigned long long ull) const
{
d_this_p->makeNumber(JsonNumber(ull));
}

void ConstructVisitor::operator()(double d) const
{
d_this_p->makeNumber(JsonNumber(d));
}

void ConstructVisitor::operator()(bdldfp::Decimal64 value) const
{
d_this_p->makeNumber(JsonNumber(value));
}

void ConstructVisitor::operator()(const bsl::string_view& sv) const
{
d_this_p->makeString(sv);
}

void ConstructVisitor::operator()(const JsonObject *jObj) const
{
d_this_p->makeObject(*jObj);
}

void ConstructVisitor::operator()(const JsonArray *jArr) const
{
d_this_p->makeArray(*jArr);
}

void ConstructVisitor::operator()(const JsonNumber *jNum) const
{
d_this_p->makeNumber(*jNum);
}

void ConstructVisitor::operator()(const Json *json) const
{
*d_this_p = *json;
}

void ConstructVisitor::operator()(
std::initializer_list<Json_Initializer> il) const
{
JsonArray arr;
for (const auto & val : il) {
arr.pushBack(val);
}
d_this_p->makeArray(bslmf::MovableRefUtil::move(arr));
}

void ConstructVisitor::operator()(bslmf::Nil) const
{
BSLA_UNREACHABLE;
BSLS_ASSERT_INVOKE_NORETURN("Unreachable");
}

#endif
} // close unnamed namespace

// ---------------
Expand Down Expand Up @@ -133,6 +282,19 @@ bsl::ostream& JsonArray::print(bsl::ostream& stream,
// class JsonObject
// ----------------

#ifdef BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS
bsl::pair<JsonObject::Iterator, bool> JsonObject::insert(
const bsl::string_view& key,
const Json_Initializer& init)
{
BSLS_ASSERT(bdlde::Utf8Util::isValid(key.data(), key.size()));
Json json(init, allocator());
Member member(key, Json(), allocator());
member.second = bslmf::MovableRefUtil::move(json);
return insert(bslmf::MovableRefUtil::move(member));
}
#endif

bsl::ostream& JsonObject::print(bsl::ostream& stream,
int level,
int spacesPerLevel) const
Expand Down Expand Up @@ -169,6 +331,14 @@ bsl::ostream& JsonObject::print(bsl::ostream& stream,
// class Json
// ----------

#ifdef BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS
Json::Json(const Json_Initializer& init, bslma::Allocator *basicAllocator)
: d_value(JsonNull(), basicAllocator)
{
init.get_storage().apply(ConstructVisitor(this));
}
#endif

bsl::ostream& Json::print(bsl::ostream& stream,
int level,
int spacesPerLevel) const
Expand Down
Loading

0 comments on commit 9498c63

Please sign in to comment.