smgl 0.11.0
Structured Metadata Engine and Graph Objects Library
Loading...
Searching...
No Matches
Factory.hpp
Go to the documentation of this file.
1#pragma once
2
5#include <exception>
6#include <functional>
7
8namespace smgl
9{
10namespace policy
11{
13template <class IdentifierType, class ProductType>
15{
16public:
19 {
20 public:
22 explicit unknown_identifier(const IdentifierType& unknownId);
23
25 const char* what() const noexcept override;
26
27 private:
29 IdentifierType unknownId_;
30 };
31
32protected:
38 static ProductType OnUnknownType(const IdentifierType& id);
39
45 static IdentifierType OnUnnamedType(const std::type_info& info);
46};
47
48} // namespace policy
49
50namespace detail
51{
64// clang-format off
65template <
66 class BaseClass,
67 typename IdentifierType,
68 class AbstractProduct = BaseClass*,
69 typename ProductCreator = std::function<AbstractProduct()>,
70template <typename, class> class FactoryErrorPolicy = policy::DefaultFactoryError
71>
72// clang-format on
73class Factory : public FactoryErrorPolicy<IdentifierType, AbstractProduct>
74{
75public:
77 using IDType = IdentifierType;
78
80 void Reserve(std::size_t count);
81
84
86 bool Register(
87 const IDType& id, ProductCreator creator, const std::type_info& info);
88
90 bool Deregister(const IDType& id);
91
93 bool IsRegistered(const IDType& id);
94
96 bool IsRegistered(const std::type_info& info);
97
99 AbstractProduct CreateObject(const IDType& id);
100
103
106
107private:
116};
117
118} // namespace detail
119} // namespace smgl
120
121#include "smgl/FactoryImpl.hpp"
Abstract Factory class.
Definition Factory.hpp:74
void ReserveAdditional(std::size_t count)
bool Register(const IDType &id, ProductCreator creator, const std::type_info &info)
AbstractProduct CreateObject(const IDType &id)
bool IsRegistered(const IDType &id)
void Reserve(std::size_t count)
bool Deregister(const IDType &id)
IdentifierType IDType
Definition Factory.hpp:77
IDType GetTypeIdentifier(const std::type_info &info)
std::vector< IDType > GetRegisteredIdentifiers() const
Default exception thrown when registered type not found.
Definition Factory.hpp:19
const char * what() const noexcept override
Default factory error policy.
Definition Factory.hpp:15
static IdentifierType OnUnnamedType(const std::type_info &info)
static ProductType OnUnknownType(const IdentifierType &id)
Project top-level namespace.