Maze Builder Docs 7.5.6
Loading...
Searching...
No Matches
mazes::factory_interface< InterfaceType > Class Template Referenceabstract

Modern factory interface using registration pattern. More...

#include <factory_interface.h>

Inheritance diagram for mazes::factory_interface< InterfaceType >:
[legend]

Public Types

using factory_creator_t = std::function<std::unique_ptr<InterfaceType>(const configurator &)>
 Type alias for product creation function.
 

Public Member Functions

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 unregister_creator (const std::string &key) noexcept=0
 Unregister a product creator function.
 
virtual bool is_registered (const std::string &key) const =0
 Check if a creator is registered for the given key.
 
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.
 
virtual std::vector< std::string > get_registered_keys () const =0
 Get all registered creator keys.
 
virtual void clear () noexcept=0
 Clear all registered creators.
 

Detailed Description

template<typename InterfaceType>
class mazes::factory_interface< InterfaceType >

Modern factory interface using registration pattern.

Uses function objects for flexible product creation with registration capabilities

Template Parameters
InterfaceTypeThe interface type that products must implement

Member Function Documentation

◆ clear()

template<typename InterfaceType >
virtual void mazes::factory_interface< InterfaceType >::clear ( )
pure virtualnoexcept

Clear all registered creators.

Implemented in mazes::grid_factory, and mazes::maze_factory.

◆ create()

template<typename InterfaceType >
virtual std::optional< std::unique_ptr< InterfaceType > > mazes::factory_interface< InterfaceType >::create ( const std::string & key,
const configurator & config ) const
pure virtualnoexcept

Create a product using a registered creator.

Parameters
keyUnique identifier for the product type
configConfiguration parameters
Returns
Unique pointer to the created product, nullptr if key not found or creation failed

Implemented in mazes::grid_factory, and mazes::maze_factory.

◆ get_registered_keys()

template<typename InterfaceType >
virtual std::vector< std::string > mazes::factory_interface< InterfaceType >::get_registered_keys ( ) const
pure virtual

Get all registered creator keys.

Returns
Vector of registered keys

Implemented in mazes::grid_factory, and mazes::maze_factory.

◆ is_registered()

template<typename InterfaceType >
virtual bool mazes::factory_interface< InterfaceType >::is_registered ( const std::string & key) const
pure virtual

Check if a creator is registered for the given key.

Parameters
keyUnique identifier to check
Returns
True if a creator is registered for this key

Implemented in mazes::grid_factory, and mazes::maze_factory.

◆ register_creator()

template<typename InterfaceType >
virtual bool mazes::factory_interface< InterfaceType >::register_creator ( const std::string & key,
factory_creator_t creator )
pure virtualnoexcept

Register a product creator function with a unique identifier.

Parameters
keyUnique identifier for the product type
creatorFunction object that creates the product
Returns
True if registration was successful, false if key already exists

Implemented in mazes::grid_factory, and mazes::maze_factory.

◆ unregister_creator()

template<typename InterfaceType >
virtual bool mazes::factory_interface< InterfaceType >::unregister_creator ( const std::string & key)
pure virtualnoexcept

Unregister a product creator function.

Parameters
keyUnique identifier for the product type to remove
Returns
True if unregistration was successful, false if key was not found

Implemented in mazes::grid_factory, and mazes::maze_factory.


The documentation for this class was generated from the following file: