BasicFrameworkHelp_T.cpp
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 
39 #include "BasicFramework.hpp"
40 #include <cerrno>
41 
47 {
48 public:
50  : CommandOptionHelp(noArgument, 'x', "xhelp", "Print x help")
51  {}
53  virtual void printHelp(std::ostream& out, bool pretty = true)
54  {
55  out << "Welcome to the help for x" << std::endl;
56  }
57 };
58 
61 {
62 public:
64  : CommandOptionHelp(hasArgument, 'y', "yhelp", "Print y help")
65  {}
67  virtual void printHelp(std::ostream& out, bool pretty = true)
68  {
69  out << "Welcome to the help for y." << std::endl
70  << "Values:" << std::endl;
71  for (unsigned i = 0; i < value.size(); i++)
72  out << " " << value[i] << std::endl;
73  }
74 };
75 
76 
78 {
79 public:
80  BasicFrameworkHelp_T(const std::string& applName) noexcept;
81  bool initialize(int argc, char *argv[], bool pretty = true) noexcept;
83  { delete reqOpt; }
88  std::string execName;
89 };
90 
91 
93 BasicFrameworkHelp_T(const std::string& applName)
94  noexcept
95  : BasicFramework(applName, "Facilitate testing of help-like options"),
96  sOpt('w', "whelp", "It was just a coincidence, I swear.",
97  "Odd groups got left, even groups got right. That means 1, 3, 5,\n"
98  " 7 left; 2, 4, 6, 8 right. 7 & 8 are whelp groups.\n"),
99  reqOpt(nullptr)
100 {
101  execName = applName;
102  std::string::size_type p = std::string::npos;
103  // find and remove the path
104  p = execName.find_last_of("/\\");
105  if (p != std::string::npos)
106  {
107  execName.erase(0, p+1);
108  }
109  // remove windows extension if any
110  p = execName.find_last_of('.');
111  if (p != std::string::npos)
112  {
113  execName.erase(p);
114  }
115 }
116 
117 
119 initialize(int argc, char *argv[], bool pretty)
120  noexcept
121 {
122  // Change behavior slightly based on the application name. This
123  // is neither unusual nor unprecedented.
124  if (execName == "BasicFrameworkHelp_T")
125  {
126  // Do nothing extra, use default behavior of no additional options.
127  }
128  else if (execName == "BasicFrameworkHelpReq_T")
129  {
130  // Add a required option to make sure behavior is appropriate
131  // in that case
132  reqOpt = new gnsstk::CommandOptionNoArg('z', "zreq", "Random required opt",
133  true);
134  }
135  else
136  {
137  std::cerr << "Executable name \"" << execName << "\" is not known"
138  << std::endl;
139  }
140  return BasicFramework::initialize(argc, argv, pretty);
141 }
142 
143 
144 int main(int argc, char *argv[])
145 {
146  try
147  {
148  BasicFrameworkHelp_T app(argv[0]);
149 
150  if (!app.initialize(argc, argv))
151  return app.exitCode;
152 
153  app.run();
154  return app.exitCode;
155  }
156  catch (gnsstk::Exception &exc)
157  {
158  std::cerr << exc << std::endl;
159  }
160  catch (std::exception &exc)
161  {
162  std::cerr << "Caught std::exception " << exc.what() << std::endl;
163  }
164  catch (...)
165  {
166  std::cerr << "Caught unknown exception";
167  if (errno)
168  {
169  std::cerr << ": " << std::strerror(errno);
170  }
171  std::cerr << std::endl;
172  }
173 
175 }
CommandOptionHelpTest::~CommandOptionHelpTest
virtual ~CommandOptionHelpTest()
Definition: BasicFrameworkHelp_T.cpp:52
BasicFrameworkHelp_T::execName
std::string execName
Definition: BasicFrameworkHelp_T.cpp:88
BasicFrameworkHelp_T
Definition: BasicFrameworkHelp_T.cpp:77
CommandOptionHelpTest::CommandOptionHelpTest
CommandOptionHelpTest()
Definition: BasicFrameworkHelp_T.cpp:49
gnsstk::Exception::what
std::string what() const
Dump to a string.
Definition: Exception.cpp:193
gnsstk::BasicFramework::EXCEPTION_ERROR
static const int EXCEPTION_ERROR
Definition: BasicFramework.hpp:392
gnsstk::CommandOptionNoArg
Definition: CommandOption.hpp:295
gnsstk::CommandOptionHelp::CommandOptionHelp
CommandOptionHelp(const CommandOption::CommandOptionFlag of, const char shOpt, const std::string &loOpt, const std::string &desc)
Definition: CommandOption.hpp:749
CommandOptionHelpTestArg
Specialized help-like option that takes an argument.
Definition: BasicFrameworkHelp_T.cpp:60
BasicFrameworkHelp_T::yOpt
CommandOptionHelpTestArg yOpt
Definition: BasicFrameworkHelp_T.cpp:85
gnsstk::Exception
Definition: Exception.hpp:151
initialize
int initialize(string &errors)
Definition: RinEdit.cpp:513
gnsstk::BasicFramework
Definition: BasicFramework.hpp:387
BasicFrameworkHelp_T::~BasicFrameworkHelp_T
virtual ~BasicFrameworkHelp_T()
Definition: BasicFrameworkHelp_T.cpp:82
CommandOptionHelpTestArg::CommandOptionHelpTestArg
CommandOptionHelpTestArg()
Definition: BasicFrameworkHelp_T.cpp:63
CommandOptionHelpTest::printHelp
virtual void printHelp(std::ostream &out, bool pretty=true)
Definition: BasicFrameworkHelp_T.cpp:53
gnsstk::CommandOption::value
std::vector< std::string > value
Any arguments passed with this option get put in here.
Definition: CommandOption.hpp:250
BasicFrameworkHelp_T::reqOpt
gnsstk::CommandOptionNoArg * reqOpt
Definition: BasicFrameworkHelp_T.cpp:87
BasicFrameworkHelp_T::initialize
bool initialize(int argc, char *argv[], bool pretty=true) noexcept
Definition: BasicFrameworkHelp_T.cpp:119
BasicFrameworkHelp_T::xOpt
CommandOptionHelpTest xOpt
Definition: BasicFrameworkHelp_T.cpp:84
BasicFrameworkHelp_T::BasicFrameworkHelp_T
BasicFrameworkHelp_T(const std::string &applName) noexcept
Definition: BasicFrameworkHelp_T.cpp:93
gnsstk::CommandOption::hasArgument
@ hasArgument
option requires an argument
Definition: CommandOption.hpp:126
gnsstk::CommandOptionHelpSimple
Definition: CommandOption.hpp:801
gnsstk::CommandOption::noArgument
@ noArgument
option requires no arguments
Definition: CommandOption.hpp:125
gnsstk::BasicFramework::run
bool run() noexcept
Definition: BasicFramework.cpp:126
main
int main(int argc, char *argv[])
Definition: BasicFrameworkHelp_T.cpp:144
BasicFrameworkHelp_T::sOpt
gnsstk::CommandOptionHelpSimple sOpt
Definition: BasicFrameworkHelp_T.cpp:86
CommandOptionHelpTestArg::~CommandOptionHelpTestArg
virtual ~CommandOptionHelpTestArg()
Definition: BasicFrameworkHelp_T.cpp:66
CommandOptionHelpTestArg::printHelp
virtual void printHelp(std::ostream &out, bool pretty=true)
Definition: BasicFrameworkHelp_T.cpp:67
BasicFramework.hpp
gnsstk::BasicFramework::exitCode
int exitCode
Definition: BasicFramework.hpp:450
gnsstk::CommandOptionHelp
Definition: CommandOption.hpp:735
CommandOptionHelpTest
Specialized help-like command-line option.
Definition: BasicFrameworkHelp_T.cpp:46


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