command_pattern

namespace command_pattern

Namespace for the Command pattern.

class Command
#include <command.hpp>

The Command interface declares methods for executing and undoing commands.

Subclassed by command_pattern::ConcreteCommand

Public Functions

virtual void execute() const = 0

Execute the command.

virtual void undo() const = 0

Undo the command.

class ConcreteCommand : public command_pattern::Command
#include <command.hpp>

ConcreteCommand binds a Receiver object with an action.

Public Functions

inline ConcreteCommand(std::shared_ptr<Receiver> receiver, const std::string &operation)

Constructor to initialize the command.

Parameters:
  • receiver – The receiver that performs the operation.

  • operation – The operation to be executed.

inline virtual void execute() const override

Execute the command by invoking the receiver’s action.

inline virtual void undo() const override

Undo the command by invoking the receiver’s reverseAction.

class Invoker
#include <command.hpp>

The Invoker class stores a command and triggers its execution or undo.

Public Functions

inline void setCommand(std::shared_ptr<Command> command)

Sets the command to be executed.

Parameters:

command – The command to set.

inline void pressButton() const

Executes the stored command.

inline void pressUndo() const

Undoes the stored command.

class Receiver
#include <command.hpp>

The Receiver class performs the actual operations associated with a request.