libjsonincpp/src/library/jsonincpp/jsonobj.h

149 lines
3.5 KiB
C++

#ifndef TEST_WEBSITE_SRC_MODULE_JSON_LIBJSONINCPP_JSONOBJ_H
#define TEST_WEBSITE_SRC_MODULE_JSON_LIBJSONINCPP_JSONOBJ_H
#include "integer.h"
#include <vector>
#include <map>
#include <stdexcept>
namespace json {
struct misuse : std::runtime_error {
explicit misuse(const char *string);
};
enum json_t {
null_symbol,
false_symbol,
true_symbol,
integer,
string,
array,
dictionary,
};
enum imaginary_key_t {
undefined_array_element,
undefined_dictionary_element,
};
struct JSON_reference;
struct JSON_reference_const;
struct JSON {
void* value = NULL;
json_t type = null_symbol;
JSON() = default;
explicit JSON(json_t type);
explicit JSON(bool V);
explicit JSON(int64_t val);
explicit JSON(const Integer& V);
explicit JSON(const char* str);
explicit JSON(const std::string& V);
explicit JSON(const std::vector<JSON>& V);
explicit JSON(const std::map<std::string, JSON>& V);
JSON(const JSON& other);
JSON& operator=(const JSON& other);
~JSON();
JSON_reference r() noexcept;
JSON_reference_const r() const noexcept;
json_t getType() const;
bool isNull() const;
bool isBool() const;
bool isInteger() const;
bool isFalse() const;
bool isTrue() const;
bool isString() const;
bool isArray() const;
bool isDictionary() const;
bool isNatalistic() const;
bool isSymbol() const;
bool toBool() const;
const Integer& asInteger() const;
const std::string& asString() const;
const std::vector<JSON>& asArray() 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);
JSON& operator=(const std::string& V);
bool operator==(const JSON& B) const;
bool operator!=(const JSON& B) const;
};
struct ImaginaryKeyChainEValue {
imaginary_key_t type;
/* Why messing with RAII-ing (int|string) value behind some void pointer when I can just include both.
* C'mon, bros, memory consumption issue does not exist */
size_t when_array_index;
std::string when_dictionary_key;
};
/* These references get invalidated as soon as referenced object or any of its parents get changed */
struct JSON_reference {
JSON& last_real;
std::vector<ImaginaryKeyChainEValue> imaginary_chain;
bool isDefined();
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