-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include "type_registry.hpp" | ||
#include "struct_type.hpp" | ||
#include "basic.hpp" | ||
#include <map> | ||
|
||
struct TypeRegistry::Impl { | ||
std::map<std::string, const StructTypeBase*> type_map; | ||
}; | ||
|
||
TypeRegistry::Impl* TypeRegistry::impl() { | ||
static Impl* i = new Impl; | ||
return i; | ||
} | ||
|
||
void TypeRegistry::add(const StructTypeBase* type) { | ||
impl()->type_map[type->name()] = type; | ||
} | ||
|
||
const StructTypeBase* TypeRegistry::get(const std::string& name) { | ||
return find_or(impl()->type_map, name, nullptr); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#pragma once | ||
#ifndef TYPE_REGISTRY_HPP_LPQGF8DT | ||
#define TYPE_REGISTRY_HPP_LPQGF8DT | ||
|
||
#include "object.hpp" | ||
#include <string> | ||
|
||
class TypeRegistry { | ||
public: | ||
template <typename T> | ||
static void add(); | ||
static void add(const StructTypeBase* type); | ||
|
||
static const StructTypeBase* get(const std::string& name); | ||
private: | ||
TypeRegistry(); | ||
struct Impl; | ||
static Impl* impl(); | ||
}; | ||
|
||
template <typename T> | ||
void TypeRegistry::add() { | ||
add(get_type<T>()); | ||
} | ||
|
||
|
||
#endif /* end of include guard: TYPE_REGISTRY_HPP_LPQGF8DT */ |