Initial backend test for user-based data/customizations (#4144)
Right now only support for colors and no real UX, idea is to test it & allow the idea to grow while figuring out the UX
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
#include <pajlada/serialize.hpp>
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
namespace pajlada {
|
||||
|
||||
template <typename ValueType, typename RJValue>
|
||||
struct Serialize<std::unordered_map<QString, ValueType>, RJValue> {
|
||||
static RJValue get(const std::unordered_map<QString, ValueType> &value,
|
||||
typename RJValue::AllocatorType &a)
|
||||
{
|
||||
RJValue ret(rapidjson::kObjectType);
|
||||
|
||||
for (auto it = value.begin(); it != value.end(); ++it)
|
||||
{
|
||||
detail::AddMember<ValueType, RJValue>(ret, it->first.toUtf8(),
|
||||
it->second, a);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename ValueType, typename RJValue>
|
||||
struct Deserialize<std::unordered_map<QString, ValueType>, RJValue> {
|
||||
static std::unordered_map<QString, ValueType> get(const RJValue &value,
|
||||
bool *error = nullptr)
|
||||
{
|
||||
std::unordered_map<QString, ValueType> ret;
|
||||
|
||||
if (!value.IsObject())
|
||||
{
|
||||
PAJLADA_REPORT_ERROR(error)
|
||||
return ret;
|
||||
}
|
||||
|
||||
for (typename RJValue::ConstMemberIterator it = value.MemberBegin();
|
||||
it != value.MemberEnd(); ++it)
|
||||
{
|
||||
ret.emplace(it->name.GetString(),
|
||||
Deserialize<ValueType, RJValue>::get(it->value, error));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace pajlada
|
||||
Reference in New Issue
Block a user