Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
228e290b94 | ||
|
|
cacd3ca8fd |
@@ -9,3 +9,9 @@ Utility library for C++.
|
||||
- Formatting library
|
||||
- JSON parsing
|
||||
- Unit test macros
|
||||
|
||||
** Formatting library
|
||||
|
||||
The format specification has been heavily inspired by the ~{fmt}~ library, most of the [[https://fmt.dev/latest/syntax.html#format-specification-mini-language][mini-language]] is supported.
|
||||
|
||||
*Note*: Development was previously done at: [[https://github.com/riyyi/manafiles/tree/6f0e3d6063ab75ad81899135689569e440ddb813/src/util][manafiles/src/util]] and [[https://github.com/riyyi/manafiles/tree/6f0e3d6063ab75ad81899135689569e440ddb813/test][manafiles/test]].
|
||||
|
||||
+25
-3
@@ -7,7 +7,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <algorithm> // transform
|
||||
#include <cstddef> // nullptr_t
|
||||
#include <cstddef> // nullptr_t, size_t
|
||||
#include <cstdint> // int32_t, int64_t, uint32_t
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
@@ -45,10 +46,31 @@ void fromJson(const Json& json, bool& boolean)
|
||||
}
|
||||
|
||||
template<typename Json>
|
||||
void fromJson(const Json& json, int& number)
|
||||
void fromJson(const Json& json, int32_t& number)
|
||||
{
|
||||
VERIFY(json.type() == Json::Type::Number);
|
||||
number = (int)json.asDouble();
|
||||
number = static_cast<int32_t>(json.asDouble());
|
||||
}
|
||||
|
||||
template<typename Json>
|
||||
void fromJson(const Json& json, uint32_t& number)
|
||||
{
|
||||
VERIFY(json.type() == Json::Type::Number);
|
||||
number = static_cast<uint32_t>(json.asDouble());
|
||||
}
|
||||
|
||||
template<typename Json>
|
||||
void fromJson(const Json& json, int64_t& number)
|
||||
{
|
||||
VERIFY(json.type() == Json::Type::Number);
|
||||
number = static_cast<int64_t>(json.asDouble());
|
||||
}
|
||||
|
||||
template<typename Json>
|
||||
void fromJson(const Json& json, size_t& number) // uint64_t
|
||||
{
|
||||
VERIFY(json.type() == Json::Type::Number);
|
||||
number = static_cast<size_t>(json.asDouble());
|
||||
}
|
||||
|
||||
template<typename Json>
|
||||
|
||||
+28
-4
@@ -6,8 +6,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cassert> // assert
|
||||
#include <cstddef> // nullptr_t
|
||||
#include <cstddef> // nullptr_t, size_t
|
||||
#include <cstdint> // int32_t, int64_t, uint32_t
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
@@ -31,11 +31,35 @@ struct jsonConstructor {
|
||||
}
|
||||
|
||||
template<typename Json>
|
||||
static void construct(Json& json, int number)
|
||||
static void construct(Json& json, int32_t number)
|
||||
{
|
||||
json.destroy();
|
||||
json.m_type = Json::Type::Number;
|
||||
json.m_value.number = (double)number;
|
||||
json.m_value.number = static_cast<double>(number);
|
||||
}
|
||||
|
||||
template<typename Json>
|
||||
static void construct(Json& json, int64_t number)
|
||||
{
|
||||
json.destroy();
|
||||
json.m_type = Json::Type::Number;
|
||||
json.m_value.number = static_cast<double>(number);
|
||||
}
|
||||
|
||||
template<typename Json>
|
||||
static void construct(Json& json, uint32_t number)
|
||||
{
|
||||
json.destroy();
|
||||
json.m_type = Json::Type::Number;
|
||||
json.m_value.number = static_cast<double>(number);
|
||||
}
|
||||
|
||||
template<typename Json>
|
||||
static void construct(Json& json, size_t number)
|
||||
{
|
||||
json.destroy();
|
||||
json.m_type = Json::Type::Number;
|
||||
json.m_value.number = static_cast<double>(number);
|
||||
}
|
||||
|
||||
template<typename Json>
|
||||
|
||||
Reference in New Issue
Block a user