Class CommandRegistry

Class Documentation

class CommandRegistry

A singleton registry that maintains all available commands in the application.

This class applies the Singleton design pattern to provide a centralized repository for ICommand instances. It maps command names (strings) to their respective ICommand implementations, allowing the application to dynamically resolve and dispatch command execution.

Public Functions

void register_command(std::unique_ptr<ICommand> command)

Registers a new command with the registry.

Parameters:

command – A unique pointer to the command being registered. The registry takes ownership.

ICommand *get_command(const std::string &name) const

Retrieves a command by its name.

Parameters:

name – The name of the command to retrieve.

Returns:

ICommand* Pointer to the command if found, or nullptr if not registered.

std::map<std::string, ICommand*> get_all_commands() const

Retrieves all registered commands.

Returns:

std::map<std::string, ICommand*> A map of all registered command names and their pointers.

Public Static Functions

static CommandRegistry &get_instance()

Retrieves the singleton instance of the CommandRegistry.

Returns:

CommandRegistry& Reference to the single target instance.