command_parser.h
Go to the documentation of this file.
1 /**********************************************************************************/
2 /* MIT License */
3 /* */
4 /* Copyright (c) 2021 Analog Devices, Inc. */
5 /* */
6 /* Permission is hereby granted, free of charge, to any person obtaining a copy */
7 /* of this software and associated documentation files (the "Software"), to deal */
8 /* in the Software without restriction, including without limitation the rights */
9 /* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell */
10 /* copies of the Software, and to permit persons to whom the Software is */
11 /* furnished to do so, subject to the following conditions: */
12 /* */
13 /* The above copyright notice and this permission notice shall be included in all */
14 /* copies or substantial portions of the Software. */
15 /* */
16 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
17 /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
18 /* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
19 /* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
20 /* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
21 /* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
22 /* SOFTWARE. */
23 /**********************************************************************************/
24 
25 #include <map>
26 #include <string>
27 #include <vector>
28 
29 struct Argument {
34  bool has_value;
35 };
36 
38  public:
39  CommandParser() = default;
40  ~CommandParser() = default;
41 
42  public:
43  void addCommand(
44  const std::string &command, const std::string &value,
45  std::vector<std::pair<std::string, std::string>> &m_command_vector);
46  void
47  getMandatoryArgs(const int &argc,
48  const std::map<std::string, struct Argument> &command_map,
49  std::vector<std::pair<std::string, int>> &arg_position);
50  bool isHelpArg(const std::string &arg);
51  bool hasEqual(const std::string &arg);
52  bool nextArgIsCommand(const std::string &arg);
53  void processFlag(
54  const std::string &arg, int &arg_number,
55  std::vector<std::pair<std::string, std::string>> &m_command_vector);
56  void processEqualArg(
57  const std::string &arg, int &arg_number, const int &euqal_pos,
58  std::vector<std::pair<std::string, std::string>> &m_command_vector);
59  void processNonEqualArg(
60  const std::string &arg, const std::string &value, int &arg_number,
61  std::vector<std::pair<std::string, std::string>> &m_command_vector);
62  void processLongArg(
63  const std::string &arg, int &arg_number,
64  std::vector<std::pair<std::string, std::string>> &m_command_vector,
65  const std::map<std::string, struct Argument> &command_map);
66  void processShorArg(
67  const std::string &arg, int &arg_number,
68  std::vector<std::pair<std::string, std::string>> &m_command_vector,
69  const std::map<std::string, struct Argument> &command_map);
70  void parseArguments(int argc, char *argv[],
71  std::map<std::string, struct Argument> command_map);
72  int checkArgumentExist(std::map<std::string, struct Argument> &command_map,
73  std::string &arg_error);
74  int checkValue(std::map<std::string, struct Argument> &command_map,
75  std::string &arg_error);
76  int
77  checkMandatoryArguments(std::map<std::string, struct Argument> &command_map,
78  std::string &arg_error);
79  int
80  checkMandatoryPosition(std::map<std::string, struct Argument> &command_map,
81  std::string &arg_error);
82  int helpMenu();
83 
84  private:
85  std::vector<std::pair<std::string, std::string>> m_command_vector;
86 };
CommandParser::processFlag
void processFlag(const std::string &arg, int &arg_number, std::vector< std::pair< std::string, std::string >> &m_command_vector)
Definition: command_parser.cpp:62
CommandParser::checkMandatoryArguments
int checkMandatoryArguments(std::map< std::string, struct Argument > &command_map, std::string &arg_error)
Definition: command_parser.cpp:245
CommandParser::helpMenu
int helpMenu()
Definition: command_parser.cpp:204
command
ROSLIB_DECL std::string command(const std::string &cmd)
CommandParser
Definition: command_parser.h:37
CommandParser::nextArgIsCommand
bool nextArgIsCommand(const std::string &arg)
Definition: command_parser.cpp:57
string
GLsizei const GLchar *const * string
Definition: glcorearb.h:3083
Argument::long_option
std::string long_option
Definition: command_parser.h:30
CommandParser::m_command_vector
std::vector< std::pair< std::string, std::string > > m_command_vector
Definition: command_parser.h:85
CommandParser::processShorArg
void processShorArg(const std::string &arg, int &arg_number, std::vector< std::pair< std::string, std::string >> &m_command_vector, const std::map< std::string, struct Argument > &command_map)
Definition: command_parser.cpp:108
CommandParser::CommandParser
CommandParser()=default
CommandParser::addCommand
void addCommand(const std::string &command, const std::string &value, std::vector< std::pair< std::string, std::string >> &m_command_vector)
Definition: command_parser.cpp:27
Argument::position
std::string position
Definition: command_parser.h:32
CommandParser::checkMandatoryPosition
int checkMandatoryPosition(std::map< std::string, struct Argument > &command_map, std::string &arg_error)
Definition: command_parser.cpp:258
Argument
Definition: command_parser.h:29
CommandParser::parseArguments
void parseArguments(int argc, char *argv[], std::map< std::string, struct Argument > command_map)
Definition: command_parser.cpp:126
CommandParser::processEqualArg
void processEqualArg(const std::string &arg, int &arg_number, const int &euqal_pos, std::vector< std::pair< std::string, std::string >> &m_command_vector)
Definition: command_parser.cpp:69
CommandParser::~CommandParser
~CommandParser()=default
CommandParser::hasEqual
bool hasEqual(const std::string &arg)
Definition: command_parser.cpp:53
CommandParser::processNonEqualArg
void processNonEqualArg(const std::string &arg, const std::string &value, int &arg_number, std::vector< std::pair< std::string, std::string >> &m_command_vector)
Definition: command_parser.cpp:77
CommandParser::getMandatoryArgs
void getMandatoryArgs(const int &argc, const std::map< std::string, struct Argument > &command_map, std::vector< std::pair< std::string, int >> &arg_position)
Definition: command_parser.cpp:33
Argument::value
std::string value
Definition: command_parser.h:33
CommandParser::isHelpArg
bool isHelpArg(const std::string &arg)
Definition: command_parser.cpp:48
CommandParser::checkValue
int checkValue(std::map< std::string, struct Argument > &command_map, std::string &arg_error)
Definition: command_parser.cpp:217
CommandParser::checkArgumentExist
int checkArgumentExist(std::map< std::string, struct Argument > &command_map, std::string &arg_error)
Definition: command_parser.cpp:183
value
GLsizei const GLfloat * value
Definition: glcorearb.h:3093
CommandParser::processLongArg
void processLongArg(const std::string &arg, int &arg_number, std::vector< std::pair< std::string, std::string >> &m_command_vector, const std::map< std::string, struct Argument > &command_map)
Definition: command_parser.cpp:84
Argument::is_mandatory
bool is_mandatory
Definition: command_parser.h:31
Argument::has_value
bool has_value
Definition: command_parser.h:34


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:48