moved from include/libjsonincpp to include/jsonincpp, added const version of everything, bs now uses getenv
This commit is contained in:
parent
3f968e7dd8
commit
149a363947
@ -38,7 +38,7 @@ struct TestWebsiteBuildScript {
|
||||
const NormalCBuildSystemCommandMeaning& cmd)
|
||||
: build_type(_build_type), make_tests(make_tests)
|
||||
{
|
||||
ASSERT(build_type == "release" || build_type == "debug", "Unknown build type");
|
||||
ASSERT(build_type == "release" || build_type == "debug", "Unknown build type " + _build_type);
|
||||
|
||||
std::vector<ExternalLibraryTarget> ext_targets;
|
||||
|
||||
@ -58,7 +58,7 @@ struct TestWebsiteBuildScript {
|
||||
"container_parsing.cpp",
|
||||
};
|
||||
for (std::string& u: T.units)
|
||||
u = "library/libjsonincpp/" + u;
|
||||
u = "library/jsonincpp/" + u;
|
||||
T.include_pr = "library";
|
||||
T.include_ir = "";
|
||||
T.exported_headers = {
|
||||
@ -68,7 +68,7 @@ struct TestWebsiteBuildScript {
|
||||
"integer.h",
|
||||
};
|
||||
for (std::string& u: T.exported_headers)
|
||||
u = "libjsonincpp/" + u;
|
||||
u = "jsonincpp/" + u;
|
||||
T.installation_dir = "";
|
||||
T.pc_output_path = "libjsonincpp.pc";
|
||||
my_targets.push_back(T);
|
||||
@ -94,7 +94,12 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
NormalCBuildSystemCommandMeaning cmd;
|
||||
regular_bs_cli_cmd_interpret(args, cmd);
|
||||
TestWebsiteBuildScript bs("debug", false, cmd);
|
||||
const char* BS_SCRIPT_TYPE = getenv("BS_SCRIPT_TYPE");
|
||||
const char* BS_SCRIPT_TESTS = getenv("BS_SCRIPT_TESTS");
|
||||
TestWebsiteBuildScript bs(
|
||||
BS_SCRIPT_TYPE ? BS_SCRIPT_TYPE : "release",
|
||||
BS_SCRIPT_TESTS ? true : false,
|
||||
cmd);
|
||||
if (cmd.need_to_build)
|
||||
complete_tasks_of_build_units(bs.runlevel_1);
|
||||
umask(~0755);
|
||||
|
@ -47,13 +47,13 @@ namespace json {
|
||||
free(uncomprehendable_horror);
|
||||
}
|
||||
|
||||
bool Integer::operator==(const Integer &other) {
|
||||
bool Integer::operator==(const Integer &other) const {
|
||||
if (uncomprehendable_horror || other.uncomprehendable_horror)
|
||||
return to_string() == other.to_string();
|
||||
return value == other.value;
|
||||
}
|
||||
|
||||
bool Integer::operator!=(const Integer &other) {
|
||||
bool Integer::operator!=(const Integer &other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
}
|
@ -25,8 +25,8 @@ namespace json {
|
||||
|
||||
~Integer();
|
||||
|
||||
bool operator==(const Integer& other);
|
||||
bool operator!=(const Integer& other);
|
||||
bool operator==(const Integer& other) const;
|
||||
bool operator!=(const Integer& other) const;
|
||||
};
|
||||
}
|
||||
|
@ -85,6 +85,10 @@ namespace json {
|
||||
}
|
||||
|
||||
JSON_reference JSON::r() noexcept {
|
||||
return {this, {}};
|
||||
return {*this, {}};
|
||||
}
|
||||
|
||||
JSON_reference_const JSON::r() const noexcept {
|
||||
return {*this, false};
|
||||
}
|
||||
}
|
@ -27,6 +27,7 @@ namespace json {
|
||||
};
|
||||
|
||||
struct JSON_reference;
|
||||
struct JSON_reference_const;
|
||||
|
||||
struct JSON {
|
||||
void* value = NULL;
|
||||
@ -48,6 +49,8 @@ namespace json {
|
||||
|
||||
JSON_reference r() noexcept;
|
||||
|
||||
JSON_reference_const r() const noexcept;
|
||||
|
||||
json_t getType() const;
|
||||
|
||||
bool isNull() const;
|
||||
@ -72,17 +75,28 @@ namespace json {
|
||||
|
||||
bool toBool() const;
|
||||
|
||||
Integer& asInteger() const;
|
||||
const Integer& asInteger() const;
|
||||
|
||||
std::string& asString() const;
|
||||
const std::string& asString() const;
|
||||
|
||||
std::vector<JSON>& asArray() const;
|
||||
const std::vector<JSON>& asArray() const;
|
||||
|
||||
std::map<std::string, JSON>& asDictionary() const;
|
||||
const std::map<std::string, JSON>& asDictionary() const;
|
||||
|
||||
Integer& asInteger();
|
||||
|
||||
std::string& asString();
|
||||
|
||||
std::vector<JSON>& asArray();
|
||||
|
||||
std::map<std::string, JSON>& asDictionary();
|
||||
|
||||
JSON_reference operator[](size_t index);
|
||||
JSON_reference operator[](const std::string& key);
|
||||
|
||||
JSON_reference_const operator[](size_t index) const;
|
||||
JSON_reference_const operator[](const std::string& key) const;
|
||||
|
||||
JSON& operator=(int64_t V);
|
||||
JSON& operator=(const Integer& V);
|
||||
JSON& operator=(const char* V);
|
||||
@ -102,18 +116,33 @@ namespace json {
|
||||
|
||||
/* These references get invalidated as soon as referenced object or any of its parents get changed */
|
||||
struct JSON_reference {
|
||||
JSON* last_real = NULL;
|
||||
JSON& last_real;
|
||||
std::vector<ImaginaryKeyChainEValue> imaginary_chain;
|
||||
|
||||
bool isDefined() const;
|
||||
bool isDefined();
|
||||
|
||||
JSON& operator*() const;
|
||||
JSON& operator*();
|
||||
JSON& g();
|
||||
|
||||
void operator=(const JSON& obj);
|
||||
|
||||
JSON_reference operator[](size_t index);
|
||||
JSON_reference operator[](const std::string& key);
|
||||
};
|
||||
|
||||
/* text */
|
||||
struct JSON_reference_const {
|
||||
const JSON& last_real;
|
||||
bool bad = false;
|
||||
|
||||
bool isDefined();
|
||||
|
||||
const JSON& operator*();
|
||||
const JSON& g();
|
||||
|
||||
JSON_reference_const operator[](size_t index);
|
||||
JSON_reference_const operator[](const std::string& key);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -58,30 +58,49 @@ namespace json {
|
||||
}
|
||||
}
|
||||
|
||||
Integer& JSON::asInteger() const {
|
||||
const Integer& JSON::asInteger() const {
|
||||
if (isInteger())
|
||||
return *static_cast<Integer*>(value);
|
||||
return *((const Integer*)value);
|
||||
throw misuse("json obj is not integer");
|
||||
}
|
||||
|
||||
std::string& JSON::asString() const {
|
||||
const std::string& JSON::asString() const {
|
||||
if (isString())
|
||||
return *static_cast<std::string*>(value);
|
||||
return *(const std::string*)value;
|
||||
throw misuse("json obj is not string");
|
||||
}
|
||||
|
||||
std::vector<JSON>& JSON::asArray() const {
|
||||
const std::vector<JSON>& JSON::asArray() const {
|
||||
if (isArray())
|
||||
return static_cast<ArrayData*>(value)->data;
|
||||
throw misuse("json obj is not array");
|
||||
}
|
||||
|
||||
std::map<std::string, JSON>& JSON::asDictionary() const {
|
||||
const std::map<std::string, JSON>& JSON::asDictionary() const {
|
||||
if (isDictionary())
|
||||
return static_cast<DictionaryData*>(value)->data;
|
||||
throw misuse("json obj is not dictionary");
|
||||
}
|
||||
|
||||
Integer & JSON::asInteger() {
|
||||
return const_cast<Integer&>(const_cast<const JSON*>(this)->asInteger());
|
||||
}
|
||||
|
||||
std::string &JSON::asString() {
|
||||
return const_cast<std::string&>(const_cast<const JSON*>(this)->asString());
|
||||
}
|
||||
|
||||
std::vector<JSON> &JSON::asArray() {
|
||||
return const_cast<std::vector<JSON>&>(const_cast<const JSON*>(this)->asArray());
|
||||
}
|
||||
|
||||
std::map<std::string, JSON> &JSON::asDictionary() {
|
||||
return const_cast<std::map<std::string, JSON>&>(const_cast<const JSON*>(this)->asDictionary());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
JSON_reference JSON::operator[](size_t index) {
|
||||
return r()[index];
|
||||
}
|
||||
@ -90,6 +109,14 @@ namespace json {
|
||||
return r()[key];
|
||||
}
|
||||
|
||||
JSON_reference_const JSON::operator[](size_t index) const {
|
||||
return r()[index];
|
||||
}
|
||||
|
||||
JSON_reference_const JSON::operator[](const std::string &key) const {
|
||||
return r()[key];
|
||||
}
|
||||
|
||||
JSON& JSON::operator=(int64_t V) {
|
||||
nullify(*this);
|
||||
value = new Integer(V);
|
@ -1,18 +1,22 @@
|
||||
#include "jsonobj.h"
|
||||
|
||||
namespace json {
|
||||
bool JSON_reference::isDefined() const {
|
||||
bool JSON_reference::isDefined(){
|
||||
return imaginary_chain.empty();
|
||||
}
|
||||
|
||||
JSON& JSON_reference::operator*() const {
|
||||
JSON& JSON_reference::operator*(){
|
||||
return g();
|
||||
}
|
||||
|
||||
JSON & JSON_reference::g() {
|
||||
if (!isDefined())
|
||||
throw misuse("dereferencing json reference with non-empty imaginary part");
|
||||
return *last_real;
|
||||
return last_real;
|
||||
}
|
||||
|
||||
void JSON_reference::operator=(const JSON &obj) {
|
||||
JSON* cur_last_real = last_real;
|
||||
JSON* cur_last_real = &last_real;
|
||||
for (const auto& ck: imaginary_chain) {
|
||||
if (ck.type == undefined_array_element) {
|
||||
if (cur_last_real->type == null_symbol)
|
||||
@ -38,8 +42,8 @@ namespace json {
|
||||
elongated.push_back({undefined_array_element, index, ""});
|
||||
return {last_real, elongated};
|
||||
}
|
||||
if (last_real->isArray() && last_real->asArray().size() > index) {
|
||||
return {&last_real->asArray()[index], {}};
|
||||
if (last_real.isArray() && last_real.asArray().size() > index) {
|
||||
return {last_real.asArray()[index], {}};
|
||||
}
|
||||
return {last_real, {ImaginaryKeyChainEValue{undefined_array_element, index, ""}}};
|
||||
}
|
||||
@ -50,9 +54,39 @@ namespace json {
|
||||
elongated.push_back({undefined_dictionary_element, 0, key});
|
||||
return {last_real, elongated};
|
||||
}
|
||||
if (last_real->isDictionary() && last_real->asDictionary().count(key) > 0) {
|
||||
return {&last_real->asDictionary()[key], {}};
|
||||
if (last_real.isDictionary() && last_real.asDictionary().count(key) > 0) {
|
||||
return {last_real.asDictionary()[key], {}};
|
||||
}
|
||||
return {last_real, {ImaginaryKeyChainEValue{undefined_dictionary_element, 0, key}}};
|
||||
}
|
||||
|
||||
bool JSON_reference_const::isDefined() {
|
||||
return !bad;
|
||||
}
|
||||
|
||||
const JSON & JSON_reference_const::operator*() {
|
||||
return g();
|
||||
}
|
||||
|
||||
const JSON & JSON_reference_const::g() {
|
||||
if (bad)
|
||||
throw misuse("dereferencing const json reference with non-empty imaginary part");
|
||||
return last_real;
|
||||
}
|
||||
|
||||
JSON_reference_const JSON_reference_const::operator[](size_t index) {
|
||||
if (bad)
|
||||
return {last_real, true};
|
||||
if (last_real.isArray() && last_real.asArray().size() > index)
|
||||
return {last_real.asArray()[index], false};
|
||||
return {last_real, true};
|
||||
}
|
||||
|
||||
JSON_reference_const JSON_reference_const::operator[](const std::string &key) {
|
||||
if (bad)
|
||||
return {last_real, true};
|
||||
if (last_real.isDictionary() && last_real.asDictionary().count(key) > 0)
|
||||
return {last_real.asDictionary().at(key), false};
|
||||
return {last_real, true};
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
#include <libjsonincpp/jsonobj.h>
|
||||
#include <libjsonincpp/string_representation.h>
|
||||
#include <jsonincpp/jsonobj.h>
|
||||
#include <jsonincpp/string_representation.h>
|
||||
#include <assert.h>
|
||||
|
||||
using namespace json;
|
||||
|
Loading…
Reference in New Issue
Block a user