Cleaned up and fixed some errors in the Json Parser.

This commit is contained in:
Arron David Nelson 2024-08-15 19:28:30 -07:00
parent 2e705627ac
commit c607b20bad
14 changed files with 241 additions and 253 deletions

View File

@ -12,13 +12,13 @@
namespace ehs
{
class EHS_LIB_IO Json
class EHS_LIB_IO Json final
{
private:
JsonBase *value;
public:
virtual ~Json();
~Json();
Json();
@ -34,9 +34,9 @@ namespace ehs
Json(const JsonStr &value);
Json(const char* data, const UInt_64 size, const UInt_64 extra);
Json(const char *data, UInt_64 size, UInt_64 extra);
Json(const Str_8& data, const UInt_64 extra);
Json(const Str_8 &data, UInt_64 extra);
Json(Json &&json) noexcept;
@ -50,19 +50,19 @@ namespace ehs
JsonBase *RetrieveValue(const Str_8 &access);
Str_8 ToStr(const bool compact) const;
Str_8 ToStr(bool compact) const;
private:
static Vector<Str_8> ParseAccess(const Str_8 &access);
void ParseValue(JsonVar* var, const Char_8** begin, const Char_8* end, const UInt_64 extra);
void ParseValue(JsonVar *var, const Char_8 **begin, const Char_8 *end, UInt_64 extra);
JsonVar ParseVar(const Char_8** begin, const Char_8* end, const UInt_64 extra);
JsonVar ParseVar(const Char_8 **begin, const Char_8 *end, UInt_64 extra);
void ParseObject(JsonObj* obj, const Char_8** begin, const Char_8* end, const UInt_64 extra);
void ParseObject(JsonObj *obj, const Char_8 **begin, const Char_8 *end, UInt_64 extra);
void ParseArray(JsonArray* arr, const Char_8** begin, const Char_8* end, const UInt_64 extra);
void ParseArray(JsonArray *arr, const Char_8 **begin, const Char_8 *end, UInt_64 extra);
void Parse(const Str_8& data, const UInt_64 extra);
void Parse(const Str_8 &data, UInt_64 extra);
};
}

View File

@ -20,13 +20,13 @@ namespace ehs
JsonBase** data;
public:
virtual ~JsonArray();
~JsonArray() override;
JsonArray();
JsonArray(const UInt_64 extra);
JsonArray(UInt_64 extra);
JsonArray(const UInt_64 size, const UInt_64 extra);
JsonArray(UInt_64 size, UInt_64 extra);
JsonArray(JsonArray&& ja) noexcept;
@ -46,9 +46,9 @@ namespace ehs
UInt_64 Size() const;
void Insert(const UInt_64 index, const JsonBase* const value);
void Insert(UInt_64 index, const JsonBase* value);
void Push(const JsonBase* const value);
void Push(const JsonBase* value);
void Push(const JsonBase& value);
@ -58,20 +58,20 @@ namespace ehs
void Push(const JsonBool& value);
void Push(const bool value);
void Push(bool value);
void Push(const JsonNum& value);
void Push(const float value);
void Push(float value);
void Push(const JsonStr& value);
void Push(const Char_8* value, const UInt_64 size = 0);
void Push(const Char_8* value, UInt_64 size = 0);
void Push(const Str_8& value);
void Pop();
Str_8 ToStr(const UInt_64 level, const bool compact) const;
Str_8 ToStr(UInt_64 level, bool compact) const override;
};
}

View File

@ -21,14 +21,16 @@ namespace ehs
JsonType type;
public:
virtual ~JsonBase() = default;
JsonBase();
JsonBase(const JsonType type);
JsonBase(JsonType type);
JsonBase(const JsonBase& base) = default;
JsonType GetType() const;
virtual Str_8 ToStr(const UInt_64 level, const bool compact) const;
virtual Str_8 ToStr(UInt_64 level, bool compact) const;
};
}

View File

@ -7,14 +7,14 @@
namespace ehs
{
class EHS_LIB_IO JsonBool : public JsonBase
class EHS_LIB_IO JsonBool final : public JsonBase
{
public:
bool value;
JsonBool();
JsonBool(const bool value);
JsonBool(bool value);
JsonBool(const JsonBool& jb) = default;
@ -22,6 +22,6 @@ namespace ehs
operator bool&();
Str_8 ToStr(const UInt_64 level, const bool compact) const;
Str_8 ToStr(UInt_64 level, bool compact) const override;
};
}

View File

@ -7,39 +7,37 @@
namespace ehs
{
class EHS_LIB_IO JsonNum : public JsonBase
class EHS_LIB_IO JsonNum final : public JsonBase
{
public:
float value;
JsonNum();
JsonNum(const SInt_64 value);
JsonNum(SInt_64 value);
JsonNum(const UInt_64 value);
JsonNum(UInt_64 value);
JsonNum(const SInt_32 value);
JsonNum(SInt_32 value);
JsonNum(const UInt_32 value);
JsonNum(UInt_32 value);
JsonNum(const SInt_16 value);
JsonNum(SInt_16 value);
JsonNum(const UInt_16 value);
JsonNum(UInt_16 value);
JsonNum(const SInt_8 value);
JsonNum(SInt_8 value);
JsonNum(const UInt_8 value);
JsonNum(UInt_8 value);
JsonNum(const double value);
JsonNum(double value);
JsonNum(const float value);
JsonNum(float value);
JsonNum(const JsonNum& jn) = default;
operator float() const;
operator float&();
Str_8 ToStr(const UInt_64 level, const bool compact) const;
Str_8 ToStr(UInt_64 level, bool compact) const override;
};
}

View File

@ -9,7 +9,7 @@ namespace ehs
{
class JsonVar;
class EHS_LIB_IO JsonObj : public JsonBase
class EHS_LIB_IO JsonObj final : public JsonBase
{
protected:
UInt_64 size;
@ -18,13 +18,13 @@ namespace ehs
JsonVar* vars;
public:
virtual ~JsonObj();
~JsonObj() override;
JsonObj();
JsonObj(const UInt_64 size, const UInt_64 extra);
JsonObj(UInt_64 size, UInt_64 extra);
JsonObj(const UInt_64 extra);
JsonObj(UInt_64 extra);
JsonObj(JsonObj &&value) noexcept;
@ -34,9 +34,7 @@ namespace ehs
JsonObj& operator=(const JsonObj &value);
operator const JsonVar*() const;
operator JsonVar*();
operator JsonVar *() const;
UInt_64 Size() const;
@ -44,20 +42,20 @@ namespace ehs
UInt_64 RawSize() const;
bool HasVar(const UInt_64 hashId) const;
bool HasVar(UInt_64 hashId) const;
bool HasVar(const Str_8 &identifier) const;
bool AddVar(const JsonVar &var);
const JsonVar* GetVar(const UInt_64 hashId) const;
const JsonVar *GetVar(UInt_64 hashId) const;
const JsonVar *GetVar(const Str_8& identifier) const;
JsonVar* GetVar(const UInt_64 hashId);
JsonVar *GetVar(UInt_64 hashId);
JsonVar *GetVar(const Str_8& identifier);
Str_8 ToStr(const UInt_64 level, const bool compact) const;
Str_8 ToStr(UInt_64 level, bool compact) const override;
};
}

View File

@ -7,7 +7,7 @@
namespace ehs
{
class EHS_LIB_IO JsonStr : public JsonBase
class EHS_LIB_IO JsonStr final : public JsonBase
{
public:
Str_8 value;
@ -16,7 +16,7 @@ namespace ehs
JsonStr(Str_8 value);
JsonStr(const Char_8* value, const UInt_64 size = 0);
JsonStr(const Char_8 *value, UInt_64 size = 0);
JsonStr(JsonStr &&js) noexcept;
@ -28,6 +28,6 @@ namespace ehs
operator Str_8 &();
Str_8 ToStr(const UInt_64 level, const bool compact) const;
Str_8 ToStr(UInt_64 level, bool compact) const override;
};
}

View File

@ -12,7 +12,7 @@ namespace ehs
class JsonNum;
class JsonStr;
class EHS_LIB_IO JsonVar
class EHS_LIB_IO JsonVar final
{
private:
UInt_64 hashId;
@ -20,13 +20,13 @@ namespace ehs
JsonBase* value;
public:
virtual ~JsonVar();
~JsonVar();
JsonVar();
JsonVar(Str_8 id);
JsonVar(Str_8 id, const JsonBase* const value);
JsonVar(Str_8 id, const JsonBase *value);
JsonVar(Str_8 id, const JsonBase &value);
@ -36,33 +36,33 @@ namespace ehs
JsonVar(Str_8 id, const JsonBool &value);
JsonVar(Str_8 id, const bool boolean);
JsonVar(Str_8 id, bool boolean);
JsonVar(Str_8 id, const JsonNum &value);
JsonVar(Str_8 id, const SInt_64 num);
JsonVar(Str_8 id, SInt_64 num);
JsonVar(Str_8 id, const UInt_64 num);
JsonVar(Str_8 id, UInt_64 num);
JsonVar(Str_8 id, const SInt_32 num);
JsonVar(Str_8 id, SInt_32 num);
JsonVar(Str_8 id, const UInt_32 num);
JsonVar(Str_8 id, UInt_32 num);
JsonVar(Str_8 id, const SInt_16 num);
JsonVar(Str_8 id, SInt_16 num);
JsonVar(Str_8 id, const UInt_16 num);
JsonVar(Str_8 id, UInt_16 num);
JsonVar(Str_8 id, const SInt_8 num);
JsonVar(Str_8 id, SInt_8 num);
JsonVar(Str_8 id, const UInt_8 num);
JsonVar(Str_8 id, UInt_8 num);
JsonVar(Str_8 id, const double num);
JsonVar(Str_8 id, double num);
JsonVar(Str_8 id, const float num);
JsonVar(Str_8 id, float num);
JsonVar(Str_8 id, const JsonStr &value);
JsonVar(Str_8 id, const Char_8* str, const UInt_64 size = 0);
JsonVar(Str_8 id, const Char_8 *str, UInt_64 size = 0);
JsonVar(Str_8 id, Str_8 str);
@ -78,7 +78,7 @@ namespace ehs
Str_8 GetId() const;
void SetValue(const JsonBase* const newValue);
void SetValue(const JsonBase *newValue);
void SetValue(const JsonBase &newValue);
@ -88,15 +88,15 @@ namespace ehs
void SetValue(const JsonBool &newValue);
void SetValue(const bool newValue);
void SetValue(bool newValue);
void SetValue(const JsonNum& newValue);
void SetValue(const float newValue);
void SetValue(float newValue);
void SetValue(const JsonStr& newValue);
void SetValue(const Char_8* newValue, const UInt_64 size = 0);
void SetValue(const Char_8* newValue, UInt_64 size = 0);
void SetValue(const Str_8& newValue);
@ -104,6 +104,6 @@ namespace ehs
JsonBase* GetValue();
Str_8 ToStr(const UInt_64 level, const bool compact) const;
Str_8 ToStr(UInt_64 level, bool compact) const;
};
}

View File

@ -71,11 +71,6 @@ namespace ehs
return value;
}
JsonNum::operator float&()
{
return value;
}
Str_8 JsonNum::ToStr(const UInt_64 level, const bool compact) const
{
Str_8 result;

View File

@ -79,12 +79,7 @@ namespace ehs
return *this;
}
JsonObj::operator const JsonVar*() const
{
return vars;
}
JsonObj::operator JsonVar*()
JsonObj::operator JsonVar*() const
{
return vars;
}