Vulkan Schnee 0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
Serializable.h
Go to the documentation of this file.
1// Serializable.h
2#pragma once
3#include <string>
4#include "Factory.h"
5
6namespace EngineCore {
8 public:
9 virtual ~Serializable() = default;
10 virtual void Serialize(nlohmann::json& archive) {
11 archive[classNameKey] = getClassName();
12 }
13 virtual void Deserialize(nlohmann::json& archive) = 0;
14
15 [[nodiscard]] virtual std::string getClassName() const {
16 return getTypeName<std::remove_pointer_t<decltype(this)>>();
17 }
18
19 inline static const std::string classNameKey = "ClassName";
20
21 // Factory methods
22 static std::unique_ptr<Serializable> create(const std::string& typeName) {
23 return Factory::create(typeName);
24 }
25
26 static nlohmann::json createDefaultJson(const std::string& typeName) {
27 return Factory::createJson(typeName);
28 }
29
30 static const std::vector<std::string>& getRegisteredClasses() {
32 }
33 };
34}
static std::unique_ptr< T > create(const std::string &typeName)
Definition Factory.h:27
static const std::vector< std::string > & getRegisteredTypes()
Definition Factory.h:61
static nlohmann::json createJson(const std::string &typeName)
Definition Factory.h:53
virtual std::string getClassName() const
static nlohmann::json createDefaultJson(const std::string &typeName)
static const std::string classNameKey
static std::unique_ptr< Serializable > create(const std::string &typeName)
virtual void Serialize(nlohmann::json &archive)
virtual ~Serializable()=default
static const std::vector< std::string > & getRegisteredClasses()
virtual void Deserialize(nlohmann::json &archive)=0
Log category system implementation.
std::string getTypeName()
Definition Factory.h:93