rapid
A ROS robotics library.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
command_line.h
Go to the documentation of this file.
1 #ifndef _RAPID_UTILS_COMMAND_LINE_H_
2 #define _RAPID_UTILS_COMMAND_LINE_H_
3 
4 #include <string>
5 #include <vector>
6 
7 #include "command_interface.h"
8 
9 namespace rapid {
10 namespace utils {
11 class ExitCommand : public CommandInterface {
12  public:
13  void Execute(const std::vector<std::string>& args);
14  std::string name() const;
15  std::string description() const;
16 };
17 
18 class CommandLine {
19  public:
20  CommandLine();
21  CommandLine(const std::string& name);
22 
23  // Add a command to this command line.
24  void AddCommand(CommandInterface* command);
25 
26  // Runs one loop of the command line, and returns whether there should be
27  // another loop. Each loop shows the command list, parses the given command,
28  // and executes the command. If the command is invalid, it does nothing and
29  // returns true. If the user types "exit" or Ctrl+D, this returns false.
30  bool Next();
31 
32  private:
33  void ShowCommands() const;
34  bool ParseLine(const std::string& line, CommandInterface** command_pp,
35  std::vector<std::string>* args) const;
36  int ParseCommand(const std::vector<std::string>& tokens,
37  const std::string& name) const;
38  std::string name_;
39  std::vector<CommandInterface*> commands_;
40 };
41 } // namespace utils
42 } // namespace rapid
43 
44 #endif // _RAPID_UTILS_COMMAND_LINE_H_
void AddCommand(CommandInterface *command)
void Execute(const std::vector< std::string > &args)
std::string name() const
std::string description() const