CommandOptionParser.hpp
Go to the documentation of this file.
1 //==============================================================================
2 //
3 // This file is part of GNSSTk, the ARL:UT GNSS Toolkit.
4 //
5 // The GNSSTk is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published
7 // by the Free Software Foundation; either version 3.0 of the License, or
8 // any later version.
9 //
10 // The GNSSTk is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with GNSSTk; if not, write to the Free Software Foundation,
17 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 //
19 // This software was developed by Applied Research Laboratories at the
20 // University of Texas at Austin.
21 // Copyright 2004-2022, The Board of Regents of The University of Texas System
22 //
23 //==============================================================================
24 
25 //==============================================================================
26 //
27 // This software was developed by Applied Research Laboratories at the
28 // University of Texas at Austin, under contract to an agency or agencies
29 // within the U.S. Department of Defense. The U.S. Government retains all
30 // rights to use, duplicate, distribute, disclose, or release this software.
31 //
32 // Pursuant to DoD Directive 523024
33 //
34 // DISTRIBUTION STATEMENT A: This software has been approved for public
35 // release, distribution is unlimited.
36 //
37 //==============================================================================
38 
44 #ifndef COMMANDOPTIONPARSER_HPP
45 #define COMMANDOPTIONPARSER_HPP
46 
47 #include "CommandOption.hpp"
48 
49 #include <cstring>
50 #include <vector>
51 #include <map>
52 #include <ostream>
53 
54 namespace gnsstk
55 {
57 
58 
87  {
88  public:
91  typedef std::map<std::string, gnsstk::CommandOption*> CommandOptionMap;
92 
100  CommandOptionParser(const std::string& description,
101  const CommandOptionVec& optList =
103 
109 
111  void parseOptions(int argc, char* argv[]);
112 
114  bool hasErrors() { return !errorStrings.empty(); }
116  std::ostream& dumpErrors(std::ostream& out);
118  bool helpRequested() { return !helpOptions.empty(); }
128  std::ostream& printHelp(std::ostream& out, bool doPretty = true,
129  bool firstOnly = true);
130 
135  std::ostream& displayUsage(std::ostream& out, bool doPretty=true);
136 
143  std::ostream& displayUsageDoxygen(std::ostream& out);
144 
145  private:
147  void resizeOptionArray(struct option* &oldArray, unsigned long& oldSize);
148 
152  std::vector<std::string> errorStrings;
154  //std::vector<std::string> remainingArguments;
155 
160 
162  std::string text;
163 
165  std::string progName;
166 
170  std::vector<CommandOptionHelp*> helpOptions;
171  };
173 }
174 
175 #endif
gnsstk::CommandOptionParser::addOption
CommandOptionParser & addOption(gnsstk::CommandOption &co)
Definition: CommandOptionParser.cpp:80
gnsstk::CommandOptionParser::displayUsageDoxygen
std::ostream & displayUsageDoxygen(std::ostream &out)
Definition: CommandOptionParser.cpp:440
gnsstk::defaultCommandOptionList
CommandOptionVec defaultCommandOptionList
Definition: CommandOption.cpp:55
gnsstk::CommandOptionParser::helpRequested
bool helpRequested()
Returns true if any help was requested.
Definition: CommandOptionParser.hpp:118
gnsstk::CommandOptionParser::dumpErrors
std::ostream & dumpErrors(std::ostream &out)
Writes the errors to out.
Definition: CommandOptionParser.cpp:346
gnsstk::CommandOptionParser::progName
std::string progName
the name of this program
Definition: CommandOptionParser.hpp:165
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::CommandOptionParser::helpOptions
std::vector< CommandOptionHelp * > helpOptions
Definition: CommandOptionParser.hpp:170
CommandOption.hpp
gnsstk::CommandOptionParser::optionVec
CommandOptionVec optionVec
The vector of CommandOptions for the parser.
Definition: CommandOptionParser.hpp:150
gnsstk::CommandOptionVec
std::vector< CommandOption * > CommandOptionVec
Definition: CommandOption.hpp:66
gnsstk::CommandOptionParser::hasRequiredArguments
bool hasRequiredArguments
The vector of unprocessed command line arguments.
Definition: CommandOptionParser.hpp:157
gnsstk::CommandOptionParser::hasOptionalArguments
bool hasOptionalArguments
whether or not this command line has optional options
Definition: CommandOptionParser.hpp:159
gnsstk::CommandOption
Definition: CommandOption.hpp:115
gnsstk::CommandOptionParser::CommandOptionParser
CommandOptionParser(const std::string &description, const CommandOptionVec &optList=defaultCommandOptionList)
Definition: CommandOptionParser.cpp:62
gnsstk::CommandOptionParser::resizeOptionArray
void resizeOptionArray(struct option *&oldArray, unsigned long &oldSize)
changes the size of the option array for getopt_long.
Definition: CommandOptionParser.cpp:556
option
Definition: getopt.h:94
gnsstk::CommandOptionParser::parseOptions
void parseOptions(int argc, char *argv[])
Parses the command line.
Definition: CommandOptionParser.cpp:115
gnsstk::CommandOptionParser
Definition: CommandOptionParser.hpp:86
gnsstk::CommandOptionParser::displayUsage
std::ostream & displayUsage(std::ostream &out, bool doPretty=true)
Definition: CommandOptionParser.cpp:375
gnsstk::CommandOptionParser::CommandOptionMap
std::map< std::string, gnsstk::CommandOption * > CommandOptionMap
Definition: CommandOptionParser.hpp:91
gnsstk::CommandOptionParser::text
std::string text
the description of this program
Definition: CommandOptionParser.hpp:162
gnsstk::CommandOptionParser::errorStrings
std::vector< std::string > errorStrings
The vector of error strings for displaying to the user.
Definition: CommandOptionParser.hpp:152
gnsstk::CommandOptionParser::hasErrors
bool hasErrors()
Returns true if any processing errors occurred.
Definition: CommandOptionParser.hpp:114
gnsstk::CommandOptionParser::printHelp
std::ostream & printHelp(std::ostream &out, bool doPretty=true, bool firstOnly=true)
Definition: CommandOptionParser.cpp:354


gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:38