}
}
- static void fromGVariant(GVariant* object, int& value)
+ static void fromGVariant(GVariant* object, std::int32_t& value)
{
checkType(object, G_VARIANT_TYPE_INT32);
value = g_variant_get_int32(object);
value = g_variant_get_int64(object);
}
+ static void fromGVariant(GVariant* object, std::uint32_t& value)
+ {
+ checkType(object, G_VARIANT_TYPE_UINT32);
+ value = g_variant_get_uint32(object);
+ }
+
+ static void fromGVariant(GVariant* object, std::uint64_t& value)
+ {
+ checkType(object, G_VARIANT_TYPE_UINT64);
+ value = g_variant_get_uint64(object);
+ }
+
static void fromGVariant(GVariant* object, bool& value)
{
checkType(object, G_VARIANT_TYPE_BOOLEAN);
}
}
- static void fromJsonObject(json_object* object, int& value)
+ static void fromJsonObject(json_object* object, std::int32_t& value)
{
checkType(object, json_type_int);
std::int64_t value64 = json_object_get_int64(object);
if (value64 > INT32_MAX || value64 < INT32_MIN) {
throw ConfigException("Value out of range");
}
- value = static_cast<int>(value64);
+ value = static_cast<std::int32_t>(value64);
+ }
+
+ static void fromJsonObject(json_object* object, std::uint32_t& value)
+ {
+ checkType(object, json_type_int);
+ std::int64_t value64 = json_object_get_int64(object);
+ if (value64 > UINT32_MAX || value64 < 0) {
+ throw ConfigException("Value out of range");
+ }
+ value = static_cast<std::uint32_t>(value64);
}
static void fromJsonObject(json_object* object, std::int64_t& value)
value = json_object_get_int64(object);
}
+ static void fromJsonObject(json_object* object, std::uint64_t& value)
+ {
+ checkType(object, json_type_int);
+ std::int64_t value64 = json_object_get_int64(object);
+ if (value64 < 0) {
+ throw ConfigException("Value out of range");
+ }
+ value = static_cast<std::uint64_t>(value64);
+ }
+
static void fromJsonObject(json_object* object, bool& value)
{
checkType(object, json_type_boolean);
value = json_object_get_int64(object);
}
+ static void fromJsonObject(json_object* object, std::uint32_t& value)
+ {
+ checkType(object, json_type_int);
+ std::int64_t value64 = json_object_get_int64(object);
+ if (value64 > UINT32_MAX || value64 < 0) {
+ throw ConfigException("Value out of range");
+ }
+ value = static_cast<std::uint32_t>(value64);
+ }
+
+ static void fromJsonObject(json_object* object, std::uint64_t& value)
+ {
+ checkType(object, json_type_int);
+ std::int64_t value64 = json_object_get_int64(object);
+ if (value64 < 0) {
+ throw ConfigException("Value out of range");
+ }
+ value = static_cast<std::uint64_t>(value64);
+ }
+
static void fromJsonObject(json_object* object, bool& value)
{
checkType(object, json_type_boolean);
void writeInternal(std::int32_t value) { add("i", value); };
void writeInternal(std::int64_t value) { add("x", value); };
+ void writeInternal(std::uint32_t value) { add("u", value); };
+ void writeInternal(std::uint64_t value) { add("t", value); };
void writeInternal(bool value) { add("b", value); };
void writeInternal(double value) { add("d", value); };
void writeInternal(const std::string& value) { add("s", value.c_str()); };
#define CONFIG_TO_JSON_VISITOR_HPP
#include "config/is-visitable.hpp"
+#include "config/exception.hpp"
#include <json/json.h>
#include <string>
return ret;
}
- static json_object* toJsonObject(int value)
+ static json_object* toJsonObject(std::int32_t value)
{
return json_object_new_int(value);
}
return json_object_new_int64(value);
}
+ static json_object* toJsonObject(std::uint32_t value)
+ {
+ if (value > INT32_MAX) {
+ throw ConfigException("Value out of range");
+ }
+ return json_object_new_int(value);
+ }
+
+ static json_object* toJsonObject(std::uint64_t value)
+ {
+ if (value > INT64_MAX) {
+ throw ConfigException("Value out of range");
+ }
+ return json_object_new_int64(value);
+ }
+
static json_object* toJsonObject(bool value)
{
return json_object_new_boolean(value);