Update to latest settings library version

This commit is contained in:
Rasmus Karlsson
2018-11-03 13:00:07 +01:00
parent 9ced50e94e
commit ac4a496a06
36 changed files with 373 additions and 374 deletions
+34 -38
View File
@@ -1,49 +1,45 @@
#pragma once
#include <QString>
#include <pajlada/settings/serialize.hpp>
#include <pajlada/serialize.hpp>
namespace pajlada {
namespace Settings {
template <>
struct Serialize<QString> {
static rapidjson::Value get(const QString &value,
rapidjson::Document::AllocatorType &a)
template <>
struct Serialize<QString> {
static rapidjson::Value get(const QString &value,
rapidjson::Document::AllocatorType &a)
{
return rapidjson::Value(value.toUtf8(), a);
}
};
template <>
struct Deserialize<QString> {
static QString get(const rapidjson::Value &value, bool *error = nullptr)
{
if (!value.IsString())
{
return rapidjson::Value(value.toUtf8(), a);
}
};
template <>
struct Deserialize<QString> {
static QString get(const rapidjson::Value &value, bool *error = nullptr)
{
if (!value.IsString())
{
PAJLADA_REPORT_ERROR(error)
PAJLADA_THROW_EXCEPTION(
"Deserialized rapidjson::Value is not a string");
return QString{};
}
try
{
return QString::fromUtf8(value.GetString(),
value.GetStringLength());
}
catch (const std::exception &)
{
// int x = 5;
}
catch (...)
{
// int y = 5;
}
PAJLADA_REPORT_ERROR(error)
return QString{};
}
};
} // namespace Settings
try
{
return QString::fromUtf8(value.GetString(),
value.GetStringLength());
}
catch (const std::exception &)
{
// int x = 5;
}
catch (...)
{
// int y = 5;
}
return QString{};
}
};
} // namespace pajlada
+6 -8
View File
@@ -3,7 +3,7 @@
#include "util/RapidJsonSerializeQString.hpp"
#include <rapidjson/document.h>
#include <pajlada/settings/serialize.hpp>
#include <pajlada/serialize.hpp>
#include <cassert>
#include <string>
@@ -24,8 +24,7 @@ namespace rj {
{
assert(obj.IsObject());
addMember(obj, key, pajlada::Settings::Serialize<Type>::get(value, a),
a);
addMember(obj, key, pajlada::Serialize<Type>::get(value, a), a);
}
template <>
@@ -45,8 +44,7 @@ namespace rj {
auto &a = obj.GetAllocator();
addMember(obj, key, pajlada::Settings::Serialize<Type>::get(value, a),
a);
addMember(obj, key, pajlada::Serialize<Type>::get(value, a), a);
}
template <>
@@ -66,7 +64,7 @@ namespace rj {
{
assert(arr.IsArray());
arr.PushBack(pajlada::Settings::Serialize<Type>::get(value, a), a);
arr.PushBack(pajlada::Serialize<Type>::get(value, a), a);
}
template <typename Type>
@@ -88,7 +86,7 @@ namespace rj {
}
bool error = false;
out = pajlada::Settings::Deserialize<Type>::get(obj[key], &error);
out = pajlada::Deserialize<Type>::get(obj[key], &error);
return !error;
}
@@ -97,7 +95,7 @@ namespace rj {
bool getSafe(const rapidjson::Value &value, Type &out)
{
bool error = false;
out = pajlada::Settings::Deserialize<Type>::get(value, &error);
out = pajlada::Deserialize<Type>::get(value, &error);
return !error;
}