Eile Mit Weile
Loading...
Searching...
No Matches
serializable_value.hpp
1#ifndef EILE_MIT_WEILE_SERIALIZABLEVALUE_HPP
2#define EILE_MIT_WEILE_SERIALIZABLEVALUE_HPP
3#include <vector>
4#include <iostream>
5#include <functional>
6
7#include "unique_serializable.hpp"
9#include "rapidjson/document.h"
10
27template <class T>
29 public:
30 explicit SerializableValue(T val) : Serializable(), value(val) { }
32 T GetValue() const { return this->value; }
34 void SetValue(T val) {
35 if (this->value != val) {
36 this->value = val;
37 }
38 }
39
40 void WriteIntoJson(rapidjson::Value& json, rapidjson::Document::AllocatorType& allocator) const override {
41 json.AddMember("value", value_type_helpers::get_json_value<decltype(value)>(value, allocator), allocator);
42 }
43
44 static SerializableValue<T>* FromJson(const rapidjson::Value& json) {
45 if (json.HasMember("value")) {
46 T val = json["value"].Get<T>();
47 return new SerializableValue<T>(val);
48 }
49 return nullptr;
50 }
51
52 private:
54};
55#endif //EILE_MIT_WEILE_SERIALIZABLEVALUE_HPP
A serializable value, used for writing values into json.
Definition serializable_value.hpp:28
T GetValue() const
Definition serializable_value.hpp:32
SerializableValue(T val)
Definition serializable_value.hpp:30
void WriteIntoJson(rapidjson::Value &json, rapidjson::Document::AllocatorType &allocator) const override
Definition serializable_value.hpp:40
T value
Definition serializable_value.hpp:53
void SetValue(T val)
Definition serializable_value.hpp:34
static SerializableValue< T > * FromJson(const rapidjson::Value &json)
Definition serializable_value.hpp:44
Abstract Base Class for a serializable object.
Definition serializable.hpp:17
Contains helper functions for serializing and deserializing instances of SerializableValue.