Command Core Types & Factory
Overview
The command core types and factory provide the foundational infrastructure for the Command Architecture. These are the building blocks that all concrete commands and command consumers depend on.
Source files:
src/Commands/Core/CommandResult.hpp— Result type for command executionsrc/Commands/Core/CommandContext.hpp— Runtime context provided to commandssrc/Commands/Core/CommandDescriptor.hpp— JSON-serializable command descriptorssrc/Commands/Core/ICommand.hpp— Abstract base class for all commandssrc/Commands/Core/CommandFactory.hpp/.cpp— Thin wrappers delegating toCommandRegistrysrc/Commands/Core/CommandRegistry.hpp/.cpp— Singleton registry andregisterTypedCommand<>
All types live in the commands namespace and have no Qt dependency.
Core Types
CommandResult
Returned by every command’s execute() and undo() methods:
struct CommandResult {
bool success = false;
std::string error_message;
std::vector<std::string> affected_keys;
static CommandResult ok(std::vector<std::string> keys = {});
static CommandResult error(std::string msg);
};CommandContext
Runtime environment passed to commands. Not serialized — constructed at execution time:
struct CommandContext {
std::shared_ptr<DataManager> data_manager;
std::map<std::string, std::string> runtime_variables;
std::function<void(float)> on_progress;
};CommandDescriptor
JSON-serializable description of a single command invocation. Uses reflect-cpp for serialization:
struct CommandDescriptor {
std::string command_name;
std::optional<rfl::Generic> parameters;
std::optional<std::string> description;
};CommandSequenceDescriptor
A sequence of commands with optional template variables for ${variable} substitution:
struct CommandSequenceDescriptor {
std::optional<std::string> name;
std::optional<std::string> version;
std::optional<std::map<std::string, std::string>> variables;
std::vector<CommandDescriptor> commands;
};ICommand Base Class
All commands inherit from ICommand. The interface provides:
execute()— pure virtual, performs the command’s actioncommandName()— pure virtual, returns a human-readable nametoJson()— pure virtual, serializes parameters to JSONisUndoable()— opt-in, defaults tofalseundo()— opt-in, defaults to returning an errormergeId()/mergeWith()— for undo coalescing (Phase 5)
There is no separate IUndoableCommand hierarchy. Commands opt into undo support by overriding isUndoable() and undo().
Command Factory & Registry
CommandRegistry is the runtime lookup table. Libraries register commands at startup via registerTypedCommand<> in explicit dispatcher functions (see Command Registry).
CommandFactory exposes backward-compatible free functions that delegate to the registry:
std::unique_ptr<ICommand> createCommand(
std::string const & name,
rfl::Generic const & params);
std::vector<CommandInfo> getAvailableCommands();
std::optional<CommandInfo> getCommandInfo(std::string const & name);createCommand() returns nullptr if the command name is unknown or parameter deserialization fails.
Tests
Test file: src/Commands/Core/CommandFactory.test.cpp
Tests cover:
CommandResultfactory methods (ok,error)CommandDescriptorandCommandSequenceDescriptorJSON round-trip serialization- Factory returns
nullptrfor unknown and empty command names ICommanddefault behavior (not undoable, undo returns error, merge disabled)- Concrete
StubCommandexecution and name reporting
See Also
- Command Architecture — full design document
- Variable Substitution & Sequence Execution — runtime execution engine