CommandOption_example_5.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 //
28 // This software was developed by Applied Research Laboratories at the
29 // University of Texas at Austin, under contract to an agency or agencies
30 // within the U.S. Department of Defense. The U.S. Government retains all
31 // rights to use, duplicate, distribute, disclose, or release this software.
32 //
33 // Pursuant to DoD Directive 523024
34 //
35 // DISTRIBUTION STATEMENT A: This software has been approved for public
36 // release, distribution is unlimited.
37 //
38 //==============================================================================
39 #include <iostream>
40 #include <fstream>
41 #include <BasicFramework.hpp>
42 #include <StringUtils.hpp>
44 #include <TimeString.hpp>
45 
46 using namespace std;
47 using namespace gnsstk;
48 
49 // Given that Doxygen removes Doxygen comments when rendering
50 // examples, please do not consider the absence of comments in the
51 // HTML rendering to be representative. Refer to the file in the
52 // depot instead.
53 
54 // Interesting examples:
55 // CommandOption5
56 // CommandOption5 --scream
57 // CommandOption5 --hush
58 // CommandOption5 -x
59 // CommandOption5 -xxxxyyz
60 // CommandOption5 -xxxxyyz --hush
61 
64 {
65 public:
67  CommandOption5Example(const string& applName);
69  bool initialize(int argc, char *argv[], bool pretty = true) noexcept override;
71  void process() override;
73  void shutDown() override;
82 
91 };
92 
93 
95 CommandOption5Example(const string& applName)
96  : BasicFramework(applName, "Example application for CommandOption"),
97  xOpt('x', "", "you say you want an x"),
98  yOpt('y', "", "you say you want an y"),
99  zOpt('z', "", "you say you want an z"),
100  screamOpt(0, "scream", "print a message very loudly"),
101  hushOpt(0, "hush", "don't print a message very loudly"),
102  hushAndXYZOpt(&xyzOpts, &hushOpt)
103 {
104  // One of these options must be used if hush is used
108  // Only one of these options may be specified.
111 }
112 
113 
115 initialize(int argc, char *argv[], bool pretty) noexcept
116 {
117  if (!BasicFramework::initialize(argc, argv, pretty))
118  return false;
119  if (screamOpt)
120  {
121  cout << "HELLO WORLD x" << screamOpt.getCount() << endl;
122  }
123  if (hushOpt)
124  {
125  cout << "ok i'll be quiet x" << hushOpt.getCount() << endl;
126  }
127  // whichOne returns the option that was used
128  CommandOption *which = hushOrScreamOpt.whichOne();
129  if (which != nullptr)
130  {
131  cout << "You used " << which->getFullOptionString() << endl;
132  }
133  cout << "You specified x,y, and/or z a total of " << xyzOpts.getCount()
134  << " times" << endl;
135  return true;
136 }
137 
138 
141 {
142  cout << "Nothing to do" << endl;
143 }
144 
145 
148 {
149  cout << "Shutting down" << endl;
150 }
151 
152 
153 int main(int argc, char *argv[])
154 {
155  try
156  {
157  CommandOption5Example app(argv[0]);
158  if (app.initialize(argc, argv))
159  {
160  app.run();
161  }
162  return app.exitCode;
163  }
164  catch (gnsstk::Exception& e)
165  {
166  cerr << e << endl;
167  }
168  catch (std::exception& e)
169  {
170  cerr << e.what() << endl;
171  }
172  catch (...)
173  {
174  cerr << "Caught unknown exception" << endl;
175  }
177 }
CommandOption5Example::xOpt
CommandOptionNoArg xOpt
generic option x
Definition: CommandOption_example_5.cpp:75
StringUtils.hpp
gnsstk::CommandOptionOneOf::addOption
void addOption(CommandOption *opt)
Add an option to the list of mutually exclusive options.
Definition: CommandOption.cpp:396
main
int main(int argc, char *argv[])
Definition: CommandOption_example_5.cpp:153
gnsstk::Exception::what
std::string what() const
Dump to a string.
Definition: Exception.cpp:193
CommandOption5Example::CommandOption5Example
CommandOption5Example(const string &applName)
Initialize command-line arguments.
Definition: CommandOption_example_5.cpp:95
gnsstk::CommandOptionMutex
Definition: CommandOption.hpp:607
CommandOption5Example::shutDown
void shutDown() override
Clean up.
Definition: CommandOption_example_5.cpp:147
gnsstk::BasicFramework::EXCEPTION_ERROR
static const int EXCEPTION_ERROR
Definition: BasicFramework.hpp:392
gnsstk::CommandOptionNoArg
Definition: CommandOption.hpp:295
gnsstk::CommandOptionDependent
Definition: CommandOption.hpp:641
CommandOption5Example::xyzOpts
CommandOptionGroupOr xyzOpts
Virtual option that is "set" if x y or z are in use.
Definition: CommandOption_example_5.cpp:81
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::Exception
Definition: Exception.hpp:151
initialize
int initialize(string &errors)
Definition: RinEdit.cpp:513
gnsstk::BasicFramework
Definition: BasicFramework.hpp:387
CommandOption5Example::zOpt
CommandOptionNoArg zOpt
generic option z
Definition: CommandOption_example_5.cpp:79
CommandOption5Example::process
void process() override
Do the processing.
Definition: CommandOption_example_5.cpp:140
gnsstk::CommandOption
Definition: CommandOption.hpp:115
gnsstk::BasicFramework::run
bool run() noexcept
Definition: BasicFramework.cpp:126
gnsstk::CommandOptionGroupOr
Definition: CommandOption.hpp:678
CommandOption5Example::yOpt
CommandOptionNoArg yOpt
generic option y
Definition: CommandOption_example_5.cpp:77
CommandOptionWithCommonTimeArg.hpp
CommandOption5Example::hushOpt
CommandOptionNoArg hushOpt
Option for demonstrating CommandOptionOneOf.
Definition: CommandOption_example_5.cpp:86
CommandOption5Example::hushAndXYZOpt
CommandOptionDependent hushAndXYZOpt
Make sure that if xyz options are used, hush is specified.
Definition: CommandOption_example_5.cpp:90
CommandOption5Example
Example of using CommandOptionNOf in an application.
Definition: CommandOption_example_5.cpp:63
gnsstk::CommandOption::getFullOptionString
std::string getFullOptionString() const
Definition: CommandOption.cpp:115
BasicFramework.hpp
std
Definition: Angle.hpp:142
gnsstk::BasicFramework::exitCode
int exitCode
Definition: BasicFramework.hpp:450
CommandOption5Example::screamOpt
CommandOptionNoArg screamOpt
Option for demonstrating CommandOptionOneOf.
Definition: CommandOption_example_5.cpp:84
CommandOption5Example::hushOrScreamOpt
CommandOptionMutex hushOrScreamOpt
Make sure only one of hushOpt or screamOpt are used.
Definition: CommandOption_example_5.cpp:88
TimeString.hpp
CommandOption5Example::initialize
bool initialize(int argc, char *argv[], bool pretty=true) noexcept override
Process command-line arguments.
Definition: CommandOption_example_5.cpp:115


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