Manager+Util: Switch to custom assert macro

This commit is contained in:
Riyyi
2022-07-27 00:10:11 +02:00
parent 04f5f42bb5
commit c59bfc20f7
9 changed files with 42 additions and 47 deletions
+9 -9
View File
@@ -7,7 +7,6 @@
#pragma once
#include <algorithm> // transform
#include <cassert> // assert
#include <cstddef> // nullptr_t
#include <map>
#include <string>
@@ -17,6 +16,7 @@
#include "util/json/array.h"
#include "util/json/object.h"
#include "util/meta/assert.h"
#include "util/meta/odr.h"
namespace Util::JSON {
@@ -33,42 +33,42 @@ void fromJson(const Json& json, Json& value)
template<typename Json>
void fromJson(const Json& json, std::nullptr_t& null)
{
assert(json.type() == Json::Type::Null);
VERIFY(json.type() == Json::Type::Null);
null = nullptr;
}
template<typename Json>
void fromJson(const Json& json, bool& boolean)
{
assert(json.type() == Json::Type::Bool);
VERIFY(json.type() == Json::Type::Bool);
boolean = json.asBool();
}
template<typename Json>
void fromJson(const Json& json, int& number)
{
assert(json.type() == Json::Type::Number);
VERIFY(json.type() == Json::Type::Number);
number = (int)json.asDouble();
}
template<typename Json>
void fromJson(const Json& json, double& number)
{
assert(json.type() == Json::Type::Number);
VERIFY(json.type() == Json::Type::Number);
number = json.asDouble();
}
template<typename Json>
void fromJson(const Json& json, std::string& string)
{
assert(json.type() == Json::Type::String);
VERIFY(json.type() == Json::Type::String);
string = json.asString();
}
template<typename Json, typename T>
void fromJson(const Json& json, std::vector<T>& array)
{
assert(json.type() == Json::Type::Array);
VERIFY(json.type() == Json::Type::Array);
array.resize(json.size());
std::transform(
json.asArray().elements().begin(),
@@ -82,7 +82,7 @@ void fromJson(const Json& json, std::vector<T>& array)
template<typename Json, typename T>
void fromJson(const Json& json, std::map<std::string, T>& object)
{
assert(json.type() == Json::Type::Object);
VERIFY(json.type() == Json::Type::Object);
object.clear();
for (const auto& [name, value] : json.asObject().members()) {
object.emplace(name, value.template get<T>());
@@ -92,7 +92,7 @@ void fromJson(const Json& json, std::map<std::string, T>& object)
template<typename Json, typename T>
void fromJson(const Json& json, std::unordered_map<std::string, T>& object)
{
assert(json.type() == Json::Type::Object);
VERIFY(json.type() == Json::Type::Object);
object.clear();
for (const auto& [name, value] : json.asObject().members()) {
object.emplace(name, value.template get<T>());
+3 -2
View File
@@ -17,6 +17,7 @@
#include "util/json/object.h"
#include "util/json/parser.h"
#include "util/json/value.h"
#include "util/meta/assert.h"
namespace Util::JSON {
@@ -88,13 +89,13 @@ bool Parser::isEOF()
Token Parser::peek()
{
assert(!isEOF());
VERIFY(!isEOF());
return (*m_tokens)[m_index];
}
Token Parser::consume()
{
assert(!isEOF());
VERIFY(!isEOF());
return (*m_tokens)[m_index++];
}
+12 -12
View File
@@ -5,7 +5,6 @@
*/
#include <algorithm> // all_of
#include <cassert> // assert
#include <cstdint> // uint32_t
#include <fstream> // >>
#include <iostream> // istream, ostream
@@ -18,6 +17,7 @@
#include "util/json/object.h"
#include "util/json/serializer.h"
#include "util/json/value.h"
#include "util/meta/assert.h"
namespace Util::JSON {
@@ -180,7 +180,7 @@ void Value::emplace_back(Value value)
m_value.array = new Array;
}
assert(m_type == Type::Array);
VERIFY(m_type == Type::Array);
m_value.array->emplace_back(value);
}
@@ -192,7 +192,7 @@ void Value::emplace(const std::string& key, Value value)
m_value.object = new Object;
}
assert(m_type == Type::Object);
VERIFY(m_type == Type::Object);
m_value.object->emplace(key, value);
}
@@ -203,7 +203,7 @@ bool Value::exists(size_t index) const
bool Value::exists(const std::string& key) const
{
assert(m_type == Type::Object);
VERIFY(m_type == Type::Object);
return m_value.object->members().find(key) != m_value.object->members().end();
}
@@ -217,7 +217,7 @@ Value& Value::operator[](size_t index)
m_value.array = new Array;
}
assert(m_type == Type::Array);
VERIFY(m_type == Type::Array);
return (*m_value.array)[index];
}
@@ -229,43 +229,43 @@ Value& Value::operator[](const std::string& key)
m_value.object = new Object;
}
assert(m_type == Type::Object);
VERIFY(m_type == Type::Object);
return (*m_value.object)[key];
}
const Value& Value::operator[](size_t index) const
{
assert(m_type == Type::Array);
VERIFY(m_type == Type::Array);
return (*m_value.array)[index];
}
const Value& Value::operator[](const std::string& key) const
{
assert(m_type == Type::Object);
VERIFY(m_type == Type::Object);
return (*m_value.object)[key];
}
Value& Value::at(size_t index)
{
assert(m_type == Type::Array);
VERIFY(m_type == Type::Array);
return m_value.array->at(index);
}
Value& Value::at(const std::string& key)
{
assert(m_type == Type::Object);
VERIFY(m_type == Type::Object);
return m_value.object->at(key);
}
const Value& Value::at(size_t index) const
{
assert(m_type == Type::Array);
VERIFY(m_type == Type::Array);
return m_value.array->at(index);
}
const Value& Value::at(const std::string& key) const
{
assert(m_type == Type::Object);
VERIFY(m_type == Type::Object);
return m_value.object->at(key);
}