Code cleanup.
This commit is contained in:
parent
706f588b36
commit
c6530e352f
18 changed files with 341 additions and 212 deletions
|
@ -5,8 +5,8 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -40,7 +40,9 @@ static const rapidjson::Value kNullValue;
|
|||
|
||||
bool xmrig::Json::getBool(const rapidjson::Value &obj, const char *key, bool defaultValue)
|
||||
{
|
||||
assert(obj.IsObject());
|
||||
if (isEmpty(obj)) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
auto i = obj.FindMember(key);
|
||||
if (i != obj.MemberEnd() && i->value.IsBool()) {
|
||||
|
@ -51,9 +53,17 @@ bool xmrig::Json::getBool(const rapidjson::Value &obj, const char *key, bool def
|
|||
}
|
||||
|
||||
|
||||
bool xmrig::Json::isEmpty(const rapidjson::Value &obj)
|
||||
{
|
||||
return !obj.IsObject() || obj.ObjectEmpty();
|
||||
}
|
||||
|
||||
|
||||
const char *xmrig::Json::getString(const rapidjson::Value &obj, const char *key, const char *defaultValue)
|
||||
{
|
||||
assert(obj.IsObject());
|
||||
if (isEmpty(obj)) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
auto i = obj.FindMember(key);
|
||||
if (i != obj.MemberEnd() && i->value.IsString()) {
|
||||
|
@ -66,7 +76,9 @@ const char *xmrig::Json::getString(const rapidjson::Value &obj, const char *key,
|
|||
|
||||
const rapidjson::Value &xmrig::Json::getArray(const rapidjson::Value &obj, const char *key)
|
||||
{
|
||||
assert(obj.IsObject());
|
||||
if (isEmpty(obj)) {
|
||||
return kNullValue;
|
||||
}
|
||||
|
||||
auto i = obj.FindMember(key);
|
||||
if (i != obj.MemberEnd() && i->value.IsArray()) {
|
||||
|
@ -79,7 +91,9 @@ const rapidjson::Value &xmrig::Json::getArray(const rapidjson::Value &obj, const
|
|||
|
||||
const rapidjson::Value &xmrig::Json::getObject(const rapidjson::Value &obj, const char *key)
|
||||
{
|
||||
assert(obj.IsObject());
|
||||
if (isEmpty(obj)) {
|
||||
return kNullValue;
|
||||
}
|
||||
|
||||
auto i = obj.FindMember(key);
|
||||
if (i != obj.MemberEnd() && i->value.IsObject()) {
|
||||
|
@ -92,7 +106,9 @@ const rapidjson::Value &xmrig::Json::getObject(const rapidjson::Value &obj, cons
|
|||
|
||||
const rapidjson::Value &xmrig::Json::getValue(const rapidjson::Value &obj, const char *key)
|
||||
{
|
||||
assert(obj.IsObject());
|
||||
if (isEmpty(obj)) {
|
||||
return kNullValue;
|
||||
}
|
||||
|
||||
auto i = obj.FindMember(key);
|
||||
if (i != obj.MemberEnd()) {
|
||||
|
@ -105,7 +121,9 @@ const rapidjson::Value &xmrig::Json::getValue(const rapidjson::Value &obj, const
|
|||
|
||||
int xmrig::Json::getInt(const rapidjson::Value &obj, const char *key, int defaultValue)
|
||||
{
|
||||
assert(obj.IsObject());
|
||||
if (isEmpty(obj)) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
auto i = obj.FindMember(key);
|
||||
if (i != obj.MemberEnd() && i->value.IsInt()) {
|
||||
|
@ -118,7 +136,9 @@ int xmrig::Json::getInt(const rapidjson::Value &obj, const char *key, int defaul
|
|||
|
||||
int64_t xmrig::Json::getInt64(const rapidjson::Value &obj, const char *key, int64_t defaultValue)
|
||||
{
|
||||
assert(obj.IsObject());
|
||||
if (isEmpty(obj)) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
auto i = obj.FindMember(key);
|
||||
if (i != obj.MemberEnd() && i->value.IsInt64()) {
|
||||
|
@ -131,7 +151,9 @@ int64_t xmrig::Json::getInt64(const rapidjson::Value &obj, const char *key, int6
|
|||
|
||||
uint64_t xmrig::Json::getUint64(const rapidjson::Value &obj, const char *key, uint64_t defaultValue)
|
||||
{
|
||||
assert(obj.IsObject());
|
||||
if (isEmpty(obj)) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
auto i = obj.FindMember(key);
|
||||
if (i != obj.MemberEnd() && i->value.IsUint64()) {
|
||||
|
@ -144,7 +166,9 @@ uint64_t xmrig::Json::getUint64(const rapidjson::Value &obj, const char *key, ui
|
|||
|
||||
unsigned xmrig::Json::getUint(const rapidjson::Value &obj, const char *key, unsigned defaultValue)
|
||||
{
|
||||
assert(obj.IsObject());
|
||||
if (isEmpty(obj)) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
auto i = obj.FindMember(key);
|
||||
if (i != obj.MemberEnd() && i->value.IsUint()) {
|
||||
|
@ -169,5 +193,5 @@ rapidjson::Value xmrig::Json::normalize(double value, bool zero)
|
|||
|
||||
bool xmrig::JsonReader::isEmpty() const
|
||||
{
|
||||
return !m_obj.IsObject() || m_obj.ObjectEmpty();
|
||||
return Json::isEmpty(m_obj);
|
||||
}
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -37,6 +37,7 @@ class Json
|
|||
{
|
||||
public:
|
||||
static bool getBool(const rapidjson::Value &obj, const char *key, bool defaultValue = false);
|
||||
static bool isEmpty(const rapidjson::Value &obj);
|
||||
static const char *getString(const rapidjson::Value &obj, const char *key, const char *defaultValue = nullptr);
|
||||
static const rapidjson::Value &getArray(const rapidjson::Value &obj, const char *key);
|
||||
static const rapidjson::Value &getObject(const rapidjson::Value &obj, const char *key);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue