Maze Builder Docs 7.5.6
Loading...
Searching...
No Matches
factory_interface.h
Go to the documentation of this file.
1#ifndef FACTORY_INTERFACE_H
2#define FACTORY_INTERFACE_H
3
4#include <functional>
5#include <memory>
6#include <optional>
7#include <string>
8#include <type_traits>
9#include <vector>
10
12namespace mazes
13{
14
15 class configurator;
16
22 template <typename InterfaceType>
24 {
25
26 public:
28 using factory_creator_t = std::function<std::unique_ptr<InterfaceType>(const configurator &)>;
29
34 virtual bool register_creator(const std::string &key, factory_creator_t creator) noexcept = 0;
35
39 virtual bool unregister_creator(const std::string &key) noexcept = 0;
40
44 virtual bool is_registered(const std::string &key) const = 0;
45
50 virtual std::optional<std::unique_ptr<InterfaceType>> create(const std::string &key, const configurator &config) const noexcept = 0;
51
54 virtual std::vector<std::string> get_registered_keys() const = 0;
55
57 virtual void clear() noexcept = 0;
58
59 virtual ~factory_interface() = default;
60 };
61
62 // Forward declaration for interfaces
63 class grid_interface;
64 class maze_interface;
65
69
70} // namespace mazes
71
72#endif // FACTORY_INTERFACE_H
Configuration class for arguments.
Definition configurator.h:23
Modern factory interface using registration pattern.
Definition factory_interface.h:24
virtual bool register_creator(const std::string &key, factory_creator_t creator) noexcept=0
Register a product creator function with a unique identifier.
virtual bool is_registered(const std::string &key) const =0
Check if a creator is registered for the given key.
virtual void clear() noexcept=0
Clear all registered creators.
virtual std::vector< std::string > get_registered_keys() const =0
Get all registered creator keys.
virtual bool unregister_creator(const std::string &key) noexcept=0
Unregister a product creator function.
std::function< std::unique_ptr< InterfaceType >(const configurator &)> factory_creator_t
Type alias for product creation function.
Definition factory_interface.h:28
virtual std::optional< std::unique_ptr< InterfaceType > > create(const std::string &key, const configurator &config) const noexcept=0
Create a product using a registered creator.
Interface for the grid class.
Definition grid_interface.h:20
Interface for the mazes.
Definition maze_interface.h:13
Namespace for the maze builder.
Definition algo_interface.h:6