26 template<
typename T = Serializable>
27 static std::unique_ptr<T>
create(
const std::string& typeName) {
28 static_assert(std::is_base_of<Serializable, T>::value,
"T must be derived from Serializable");
33 std::unique_ptr<Serializable> basePtr = it->second();
34 if constexpr (std::is_same_v<T, Serializable>) {
36 return std::unique_ptr<T>(basePtr.release());
39 T* derivedPtr =
dynamic_cast<T*
>(basePtr.get());
43 return std::unique_ptr<T>(derivedPtr);
53 static nlohmann::json
createJson(
const std::string& typeName) {
58 return nlohmann::json();
68 static std::map<std::string, CreateFunction> creators;
73 static std::map<std::string, JsonFactory> jsonFactories;
78 static std::vector<std::string> registeredTypes;
79 return registeredTypes;
94 return typeid(T).name();
static std::unique_ptr< T > create(const std::string &typeName)
static void registerType(const std::string &typeName, CreateFunction creator, JsonFactory jsonFactory)
static void addRegisteredType(const std::string &typeName)
static const std::vector< std::string > & getRegisteredTypes()
static std::map< std::string, JsonFactory > & getJsonFactories()
static std::map< std::string, CreateFunction > & getCreators()
std::function< std::unique_ptr< Serializable >()> CreateFunction
std::function< nlohmann::json()> JsonFactory
static nlohmann::json createJson(const std::string &typeName)
static std::vector< std::string > & getTypesList()
Log category system implementation.
std::string getTypeName()