feat: saving entities (WIP)

This commit is contained in:
MihailRis
2024-07-05 05:16:31 +03:00
parent 019a88ef84
commit f0270d3391
24 changed files with 290 additions and 101 deletions
+5 -22
View File
@@ -1,42 +1,22 @@
#ifndef DATA_DYNAMIC_HPP_
#define DATA_DYNAMIC_HPP_
#include "../typedefs.hpp"
#include "dynamic_fwd.hpp"
#include <cmath>
#include <string>
#include <vector>
#include <memory>
#include <ostream>
#include <variant>
#include <stdexcept>
#include <unordered_map>
namespace dynamic {
class Map;
class List;
enum class Type {
none=0, map, list, string, number, boolean, integer
};
using Map_sptr = std::shared_ptr<Map>;
using List_sptr = std::shared_ptr<List>;
struct none {};
inline constexpr none NONE = {};
using Value = std::variant<
none,
Map_sptr,
List_sptr,
std::string,
number_t,
bool,
integer_t
>;
const std::string& type_name(const Value& value);
List_sptr create_list(std::initializer_list<Value> values={});
Map_sptr create_map(std::initializer_list<std::pair<const std::string, Value>> entries={});
@@ -153,6 +133,9 @@ namespace dynamic {
Map& put(std::string key, int64_t value) {
return put(key, Value(static_cast<integer_t>(value)));
}
Map& put(std::string key, uint64_t value) {
return put(key, Value(static_cast<integer_t>(value)));
}
Map& put(std::string key, float value) {
return put(key, Value(static_cast<number_t>(value)));
}
+31
View File
@@ -0,0 +1,31 @@
#ifndef DATA_DYNAMIC_FWD_HPP_
#define DATA_DYNAMIC_FWD_HPP_
#include "../typedefs.hpp"
#include <memory>
#include <variant>
namespace dynamic {
class Map;
class List;
using Map_sptr = std::shared_ptr<Map>;
using List_sptr = std::shared_ptr<List>;
struct none {};
inline constexpr none NONE = {};
using Value = std::variant<
none,
Map_sptr,
List_sptr,
std::string,
number_t,
bool,
integer_t
>;
}
#endif // DATA_DYNAMIC_FWD_HPP_
+30
View File
@@ -0,0 +1,30 @@
#ifndef DATA_DYNAMIC_UTIL_HPP_
#define DATA_DYNAMIC_UTIL_HPP_
#include "dynamic.hpp"
#include <glm/glm.hpp>
namespace dynamic {
template<int n>
inline dynamic::List_sptr to_value(glm::vec<n, float> vec) {
auto list = dynamic::create_list();
for (size_t i = 0; i < n; i++) {
list->put(vec[i]);
}
return list;
}
template<int n, int m>
inline dynamic::List_sptr to_value(glm::mat<n, m, float> mat) {
auto list = dynamic::create_list();
for (size_t i = 0; i < n; i++) {
for (size_t j = 0; j < m; j++) {
list->put(mat[i][j]);
}
}
return list;
}
}
#endif // DATA_DYNAMIC_UTIL_HPP_