SVCS - English Documentation
Loading...
Searching...
No Matches
svcs::integration::CompositeCommandFactory Class Reference

Integration component for combining multiple command factories. More...

#include <CompositeCommandFactory.hxx>

Public Member Functions

 CompositeCommandFactory (std::shared_ptr< ISubject > event_bus, std::shared_ptr< RepositoryManager > repo_manager)
 Constructs a CompositeCommandFactory with necessary dependencies.
 ~CompositeCommandFactory ()=default
 Default destructor.
 CompositeCommandFactory (const CompositeCommandFactory &)=delete
 Deleted copy constructor.
CompositeCommandFactoryoperator= (const CompositeCommandFactory &)=delete
 Deleted assignment operator.
void registerFactory (std::function< std::unique_ptr< ICommand >(const std::string &)> factory)
 Registers a factory function for command creation.
std::unique_ptr< ICommandcreateCommand (const std::string &name) const
 Creates a command by name using registered factories.
std::vector< std::string > getAllCommandNames () const
 Gets names of all available commands from all factories.
std::string getCommandDescription (const std::string &name) const
 Gets the description for a command.
void showCommandHelp (const std::string &name) const
 Shows detailed help for a command.
bool commandExists (const std::string &name) const
 Checks if a command with the given name exists.
size_t getFactoryCount () const
 Gets the number of registered factories.

Detailed Description

Integration component for combining multiple command factories.

Serves as a bridge between different command subsystems (CLI, Server). When creating a command, it tries each registered factory in order until one successfully creates the command. This design allows clean separation of concerns while providing a unified command interface to the application.

Constructor & Destructor Documentation

◆ CompositeCommandFactory()

svcs::integration::CompositeCommandFactory::CompositeCommandFactory ( std::shared_ptr< ISubject > event_bus,
std::shared_ptr< RepositoryManager > repo_manager )

Constructs a CompositeCommandFactory with necessary dependencies.

Parameters
event_busShared pointer to the event bus for command notifications.
repo_managerShared pointer to the repository manager for repository operations.

Member Function Documentation

◆ commandExists()

bool svcs::integration::CompositeCommandFactory::commandExists ( const std::string & name) const

Checks if a command with the given name exists.

Parameters
nameThe name of the command to check.
Returns
True if any registered factory can create the command, false otherwise.

Tries to create the command to determine existence.

◆ createCommand()

std::unique_ptr< ICommand > svcs::integration::CompositeCommandFactory::createCommand ( const std::string & name) const

Creates a command by name using registered factories.

Parameters
nameThe name of the command to create.
Returns
Unique pointer to the created command, or nullptr if no factory can create it.

Tries each registered factory in order until one successfully creates the command. Returns the first non-null command found.

◆ getAllCommandNames()

std::vector< std::string > svcs::integration::CompositeCommandFactory::getAllCommandNames ( ) const

Gets names of all available commands from all factories.

Returns
Vector of all command names that can be created by any registered factory.

Collects command names from all registered factories, removing duplicates. Commands are returned in registration order (factory order), not alphabetical order.

◆ getCommandDescription()

std::string svcs::integration::CompositeCommandFactory::getCommandDescription ( const std::string & name) const

Gets the description for a command.

Parameters
nameThe name of the command.
Returns
Command description, or error message if command not found.

Creates a temporary command instance to retrieve its description. If command cannot be created, returns an appropriate error message.

◆ getFactoryCount()

size_t svcs::integration::CompositeCommandFactory::getFactoryCount ( ) const

Gets the number of registered factories.

Returns
Number of factory functions currently registered.

◆ registerFactory()

void svcs::integration::CompositeCommandFactory::registerFactory ( std::function< std::unique_ptr< ICommand >(const std::string &)> factory)

Registers a factory function for command creation.

Parameters
factoryFactory function that takes a command name and returns a command pointer.

Factories are called in the order they are registered until one returns a non-null command. This allows prioritizing certain command types over others.

◆ showCommandHelp()

void svcs::integration::CompositeCommandFactory::showCommandHelp ( const std::string & name) const

Shows detailed help for a command.

Parameters
nameThe name of the command.

Creates a temporary command instance and calls its showHelp method. If command cannot be created, shows an error message.


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