Command.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 #include <map>
5 #include <replxx.hxx>
6 
7 namespace swarmio::tool
8 {
15  class Command final
16  {
17  private:
18 
23  std::string _verb;
24 
29  std::string _path;
30 
35  std::map<std::string, std::string> _parameters;
36 
42  Command(const std::string& verb)
43  {
44  _verb = verb;
45  }
46 
47  public:
48 
55  static Command Parse(std::string command);
56 
64  static void HighlighterCallback(const std::string& input, replxx::Replxx::colors_t& colors, void* unused);
65 
72  bool Is(const char* pattern) const;
73 
79  bool HasPath() const
80  {
81  return !_path.empty();
82  }
83 
89  bool HasParameters() const
90  {
91  return !_parameters.empty();
92  }
93 
99  const std::string& GetVerb() const
100  {
101  return _verb;
102  }
103 
109  const std::string& GetPath() const
110  {
111  return _path;
112  }
113 
119  const std::map<std::string, std::string>& GetParameters() const
120  {
121  return _parameters;
122  }
123  };
124 
125 }
static void HighlighterCallback(const std::string &input, replxx::Replxx::colors_t &colors, void *unused)
Highlighter callback for commands.
Definition: Command.cpp:8
bool HasPath() const
Does the command have a path specified?
Definition: Command.h:79
std::string _verb
Verb.
Definition: Command.h:23
static Command Parse(std::string command)
Parse a string as a command.
Definition: Command.cpp:108
Command(const std::string &verb)
Construct a new Command object.
Definition: Command.h:42
ROSLIB_DECL std::string command(const std::string &cmd)
const std::map< std::string, std::string > & GetParameters() const
Get the map of parameters.
Definition: Command.h:119
const std::string & GetPath() const
Get the path.
Definition: Command.h:109
Parser for commands of the default form.
Definition: Command.h:15
const std::string & GetVerb() const
Get the verb.
Definition: Command.h:99
std::string _path
Path.
Definition: Command.h:29
bool HasParameters() const
Does the command have parameters?
Definition: Command.h:89
bool Is(const char *pattern) const
Do a case insensitive regex match on the verb.
Definition: Command.cpp:229
std::map< std::string, std::string > _parameters
Parameters.
Definition: Command.h:35


swarmros
Author(s):
autogenerated on Fri Apr 3 2020 03:42:47