You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.3 KiB
C++

#pragma once
#include <string>
// thirdparty
#include "nlohmann/json.hpp"
// project
#include "GeneralUtils.h"
namespace nsKeyValue
{
using stKeyValue = struct _stKeyValue
{
std::string Name;
double Value{ 0.0 };
};
using stKeyValueBool = struct _stKeyValueBool
{
std::string Name;
bool Value{};
};
};
namespace nsKeyValue
{
using namespace nlohmann;
using namespace nsUtils;
void from_json(const json& j, stKeyValue& x);
void to_json(json& j, const stKeyValue& x);
void from_json(const json& j, stKeyValueBool& x);
void to_json(json& j, const stKeyValueBool& x);
inline void from_json(const json& j, stKeyValue& x)
{
getValue(j, "Name", x.Name);
getValue(j, "Value", x.Value);
}
inline void to_json(json& j, const stKeyValue& x)
{
j = nlohmann::json{
{ "Name", x.Name },
{ "Value", x.Value }
};
}
inline void from_json(const json& j, stKeyValueBool& x)
{
getValue(j, "Name", x.Name);
getValue(j, "Value", x.Value);
}
inline void to_json(json& j, const stKeyValueBool& x)
{
j = nlohmann::json{
{ "Name", x.Name },
{ "Value", x.Value }
};
}
}