g2o
command_args.h
Go to the documentation of this file.
1 // g2o - General Graph Optimization
2 // Copyright (C) 2011 R. Kuemmerle, G. Grisetti, W. Burgard
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright notice,
10 // this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the distribution.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18 // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 
27 #ifndef G2O_COMMAND_ARGS_H
28 #define G2O_COMMAND_ARGS_H
29 
30 #include <string>
31 #include <vector>
32 #include <iostream>
33 #include <sstream>
34 
35 #include "g2o_stuff_api.h"
36 
37 namespace g2o {
38 
47 {
48  public:
50  {
51  std::string name;
52  std::string description;
53  int type;
54  void* data;
55  bool parsed;
56  bool optional;
57  CommandArgument() : name(""), description(""), type(0), data(0), parsed(false), optional(false)
58  {}
59  };
60  public:
61  CommandArgs();
62  virtual ~CommandArgs();
63 
71  bool parseArgs(int argc, char** argv, bool exitOnError = true);
72 
74  void param(const std::string& name, bool& p, bool defValue, const std::string& desc);
76  void param(const std::string& name, int& p, int defValue, const std::string& desc);
78  void param(const std::string& name, float& p, float defValue, const std::string& desc);
80  void param(const std::string& name, double& p, double defValue, const std::string& desc);
82  void param(const std::string& name, std::string& p, const std::string& defValue, const std::string& desc);
84  void param(const std::string& name, std::vector<int>& p, const std::vector<int>& defValue, const std::string& desc);
86  void param(const std::string& name, std::vector<double>& p, const std::vector<double>& defValue, const std::string& desc);
88  void paramLeftOver(const std::string& name, std::string& p, const std::string& defValue, const std::string& desc, bool optional = false);
89 
93  void printParams(std::ostream& os);
94 
96  const std::string& getBanner() const { return _banner; }
97  void setBanner(const std::string& banner);
98 
102  void printHelp(std::ostream& os);
103 
107  bool parsedParam(const std::string& paramFlag) const;
108 
109  protected:
110  std::vector<CommandArgument> _args;
111  std::vector<CommandArgument> _leftOvers;
112  std::vector<CommandArgument> _leftOversOptional;
113  std::string _banner;
114  std::string _progName;
115 
116  const char* type2str(int t) const;
117  void str2arg(const std::string& input, CommandArgument& ca) const;
118  std::string arg2str(const CommandArgument& ca) const;
119 
120  std::string trim(const std::string& s) const;
121 };
122 
123 } // end namespace
124 
125 #endif
Command line parsing of argc and argv.
Definition: command_args.h:46
std::string _banner
Definition: command_args.h:113
std::string trim(const std::string &s)
std::vector< CommandArgument > _args
Definition: command_args.h:110
std::vector< CommandArgument > _leftOvers
Definition: command_args.h:111
std::string _progName
Definition: command_args.h:114
#define G2O_STUFF_API
Definition: g2o_stuff_api.h:30
std::vector< CommandArgument > _leftOversOptional
Definition: command_args.h:112
const std::string & getBanner() const
return the banner string
Definition: command_args.h:96