iash  v0.5
Library to provide a bash-like shell in an application
CommandDispatcher.h
1 /*
2  * CommandDispatcher.h
3  *
4  * Created on: Oct 7, 2016
5  * Author: paul
6  */
7 
8 #ifndef SRC_COMMANDDISPATCHER_H_
9 #define SRC_COMMANDDISPATCHER_H_
10 
11 #include <string>
12 #include <map>
13 #include <iostream>
14 #include <utility>
15 
16 class iash;
17 class Command;
18 class UserCommand;
19 
31 public:
37  CommandDispatcher(iash *parent);
38  virtual ~CommandDispatcher();
39 
63  void registerCommand (Command *cmd);
64 
82  template <typename ExtCommand, typename... Args>
83  void registerCommand (Args&&... args)
84  {
85  registerCommand(new ExtCommand(std::forward<Args>(args)...));
86  }
87 
97  Command* unregisterCommand (const std::string& name);
98 
107  const Command* unregisterCommand (const Command *cmd);
108 
117  int dispatch (const UserCommand *userCmd);
118 private:
119  iash *m_parent;
120  std::map<std::string,Command*> m_registry;
121  std::map<std::string,Command*> m_aliasRegistry;
122 };
123 
124 #endif /* SRC_COMMANDDISPATCHER_H_ */
void registerCommand(Command *cmd)
Registers a given Command with this CommandDispatcher instance.
Definition: CommandDispatcher.cpp:23
Command * unregisterCommand(const std::string &name)
Removes the command with the given name from the registry, and removes any of its registered aliases...
Class to register and execute Commands in an iash shell.
Definition: CommandDispatcher.h:30
int dispatch(const UserCommand *userCmd)
Searches the command and alias registries and calls the appropriate Command.
Definition: CommandDispatcher.cpp:77
The main shell class for iash.
Definition: iash.h:56
void registerCommand(Args &&... args)
Registers the given Command type with this CommandDispatcher instance.
Definition: CommandDispatcher.h:83
Abstract interface for a command registered with the shell.
Definition: Command.h:56
Used to retain command arguments and the proper input and output streams for a command call...
Definition: UserCommand.h:28
CommandDispatcher(iash *parent)
Initializes a CommandDispatcher with the given shell parent.
Definition: CommandDispatcher.cpp:16