Tree structure to manage commands and their subcommands.
More...
#include <command_tree.h>
|
| | CommandTree (std::string_view rootName) |
| | Construct a new CommandTree.
|
| |
| template<typename... Ids> |
| void | insert (std::unique_ptr< Command > cmd, std::string_view parentId, Ids &&...rest) |
| | Insert a command into the tree.
|
| |
| void | insert (std::unique_ptr< Command > cmd) |
| | Insert a command into the tree.
|
| |
| template<typename... Ids> |
| Command * | find (Ids &&...ids) const |
| | Find a command in the tree by a path of identifiers leading to it.
|
| |
| void | forEachCommand (const std::function< void(Command *)> &func) const |
| | Apply a function to each command in the tree.
|
| |
| void | forEachCommand (const std::function< void(Command &)> &func) const |
| | Apply a function to each command in the tree.
|
| |
| Command * | getRootCommand () |
| | Get the root command of the tree.
|
| |
| const Command * | getRootCommand () const |
| | Get the root command of the tree.
|
| |
| std::string_view | getPathForCommand (Command *cmd) const |
| | Get the path for a command in the tree.
|
| |
| void | buildCommandPathMap (const std::string &separator=" ") |
| | Build a map of command paths for quick lookup.
|
| |
| std::vector< Command * > | getAllCommands () const |
| | Get a vector of all commands in the tree.
|
| |
| std::vector< const Command * > | getAllCommandsConst () const |
| | Get a vector of all commands in the tree (const version).
|
| |
Tree structure to manage commands and their subcommands.
Each node in the tree is a Command, and commands can have multiple subcommands. The tree allows for insertion, lookup, and traversal of commands.
◆ CommandTree()
| inline_t cli::commands::CommandTree::CommandTree |
( |
std::string_view |
rootName | ) |
|
|
explicit |
Construct a new CommandTree.
- Parameters
-
| rootName | The name of the root command. |
◆ buildCommandPathMap()
| inline_t void cli::commands::CommandTree::buildCommandPathMap |
( |
const std::string & |
separator = " " | ) |
|
Build a map of command paths for quick lookup.
- Parameters
-
| separator | The separator to use between command names in the path (default is a space). |
◆ find()
template<typename... Ids>
| Command * cli::commands::CommandTree::find |
( |
Ids &&... |
ids | ) |
const |
|
inline |
Find a command in the tree by a path of identifiers leading to it.
- Template Parameters
-
| ...Ids | The types of the command IDs. |
- Parameters
-
- Returns
- A pointer to the found command, or nullptr if not found.
◆ forEachCommand() [1/2]
| void cli::commands::CommandTree::forEachCommand |
( |
const std::function< void(Command &)> & |
func | ) |
const |
|
inline |
Apply a function to each command in the tree.
The function is applied in a depth-first search (DFS) manner.
- Parameters
-
| func | The function to apply. |
◆ forEachCommand() [2/2]
| void cli::commands::CommandTree::forEachCommand |
( |
const std::function< void(Command *)> & |
func | ) |
const |
|
inline |
Apply a function to each command in the tree.
The function is applied in a depth-first search (DFS) manner.
- Parameters
-
| func | The function to apply. |
◆ getAllCommands()
| inline_t std::vector< Command * > cli::commands::CommandTree::getAllCommands |
( |
| ) |
const |
Get a vector of all commands in the tree.
Commands are collected in a depth-first search (DFS) manner.
- Returns
- A vector containing pointers to all commands in the tree.
◆ getAllCommandsConst()
| inline_t std::vector< const Command * > cli::commands::CommandTree::getAllCommandsConst |
( |
| ) |
const |
Get a vector of all commands in the tree (const version).
Commands are collected in a depth-first search (DFS) manner.
- Returns
- A vector containing pointers to all commands in the tree.
◆ getPathForCommand()
| inline_t std::string_view cli::commands::CommandTree::getPathForCommand |
( |
Command * |
cmd | ) |
const |
Get the path for a command in the tree.
- Note
- Uses a pre-built map for O(1) lookup internally that maps needs to be constructed first using the buildCommandPathMap function.
- Parameters
-
| cmd | The command to find the path for. |
- Returns
- The path to the command, or an empty string if not found.
◆ getRootCommand() [1/2]
| Command * cli::commands::CommandTree::getRootCommand |
( |
| ) |
|
|
inline |
Get the root command of the tree.
- Returns
- A pointer to the root command.
◆ getRootCommand() [2/2]
| const Command * cli::commands::CommandTree::getRootCommand |
( |
| ) |
const |
|
inline |
Get the root command of the tree.
- Returns
- A pointer to the root command.
◆ insert() [1/2]
| void cli::commands::CommandTree::insert |
( |
std::unique_ptr< Command > |
cmd | ) |
|
|
inline |
Insert a command into the tree.
- Parameters
-
| cmd | The command to insert. |
◆ insert() [2/2]
template<typename... Ids>
| void cli::commands::CommandTree::insert |
( |
std::unique_ptr< Command > |
cmd, |
|
|
std::string_view |
parentId, |
|
|
Ids &&... |
rest |
|
) |
| |
|
inline |
Insert a command into the tree.
- Template Parameters
-
| ...Ids | The types of the parent command IDs. |
- Parameters
-
| cmd | The command to insert. |
| parentId | The ID of the direct parent command (used to split first value of ...rest). |
| ...rest | The IDs of any additional parent commands. |
The documentation for this class was generated from the following files:
- src/chaincli/commands/command_tree.h
- src/chaincli/commands/command_tree.cpp