Eile Mit Weile
Loading...
Searching...
No Matches
vector_utils.hpp
Go to the documentation of this file.
1#ifndef EILE_MIT_WEILE_VECTOR_UTILS_HPP
2#define EILE_MIT_WEILE_VECTOR_UTILS_HPP
3
4#include <vector>
5#include "serializable.hpp"
6#include "unique_serializable.hpp"
7#include <rapidjson/document.h>
8
14namespace vector_utils {
15
16 template<class T, class B> struct derived_from {
17 static void constraints(T* p) { B* pb = p; }
18 derived_from() { void(*p)(T*) = constraints; }
19 };
20
21 template<class T>
22 /* WARNING: can only be called with vectors containing elements of type T that derives from "serializable" */
24 derived_from<T,Serializable>(); // ensure T derives from serializable
26 for (int i = 0; i < serializables.size(); i++) {
29 arr_val.PushBack(elem, allocator);
30 }
31 return arr_val;
32 }
33
34 //template<class T, class U, class V>
35 static rapidjson::Value serialize_vector_tuples(const std::vector<std::tuple<unsigned, unsigned, unsigned>> serializables, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> &allocator) {
36
38 for (auto & serializable : serializables) {
40 {
42 tuple_val.PushBack(elem, allocator);
43 elem = std::get<1>(serializable);
44 tuple_val.PushBack(elem, allocator);
45 elem = std::get<2>(serializable);
46 tuple_val.PushBack(elem, allocator);
47 }
48 arr_val.PushBack(tuple_val, allocator);
49 }
50 return arr_val;
51 }
52
53}
54
55
56#endif //EILE_MIT_WEILE_VECTOR_UTILS_HPP
A serializable value, used for writing values into json.
Definition serializable_value.hpp:28
SerializableValue(T val)
Definition serializable_value.hpp:30
void WriteIntoJson(rapidjson::Value &json, rapidjson::Document::AllocatorType &allocator) const override
Definition serializable_value.hpp:40
Helper functions to serialize vectors containing objects that implement the 'Serializable' class.
Definition vector_utils.hpp:16