BasicFramework.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 
45 #include "Exception.hpp"
46 #include "BasicFramework.hpp"
47 #include "StringUtils.hpp"
48 
49 
50 namespace gnsstk
51 {
52 
53  using namespace std;
54 
55 
56  BasicFramework :: BasicFramework( const std::string& applName,
57  const std::string& applDesc )
58  noexcept
59  : debugLevel(0),
60  verboseLevel(0),
61  exitCode(0),
62  argv0(applName),
63  appDesc(applDesc),
64  debugOption('d', "debug", "Increase debug level"),
65  verboseOption('v', "verbose", "Increase verbosity"),
66  helpOption('h', "help", "Print help usage")
67  {} // End of constructor 'BasicFramework::BasicFramework()'
68 
69 
70 
72  char *argv[],
73  bool pretty )
74  noexcept
75  {
76 
77  // Creating the parser here ensures that all the subclasses'
78  // option objects are constructed.
79  try
80  {
81  CommandOptionParser cop(appDesc);
82 
83  cop.parseOptions(argc, argv);
84 
85  if (cop.helpRequested())
86  {
87  cop.printHelp(cerr, pretty);
88  return false;
89  }
90 
91  if (cop.hasErrors())
92  {
93  cop.dumpErrors(cerr);
94  cop.displayUsage(cerr, pretty);
95  exitCode = OPTION_ERROR;
96  return false;
97  }
98 
99  debugLevel = debugOption.getCount();
100  verboseLevel = verboseOption.getCount();
101  }
102  catch (gnsstk::Exception &exc)
103  {
104  cerr << exc << endl;
105  exitCode=OPTION_ERROR;
106  return false;
107  }
108  catch (std::exception &exc)
109  {
110  cerr << "BasicFramework::initialize caught " << exc.what() << endl;
111  exitCode=OPTION_ERROR;
112  return false;
113  }
114  catch (...)
115  {
116  cerr << "BasicFramework::initialize caught unknown exception" << endl;
117  exitCode=OPTION_ERROR;
118  return false;
119  }
120 
121  return true;
122 
123  } // End of method 'BasicFramework::initialize()'
124 
125 
127  noexcept
128  {
129 
130  try
131  {
132  completeProcessing();
133  }
134  catch (Exception& exc)
135  {
136  cerr << exc;
137  exitCode = EXCEPTION_ERROR;
138  return false;
139  }
140  catch (...)
141  {
142  cerr << "Caught unknown exception" << endl;
143  exitCode = EXCEPTION_ERROR;
144  return false;
145  }
146 
147  shutDown();
148 
149  return true;
150 
151  } // End of method 'BasicFramework::run()'
152 
153 
154 
156  {
157  additionalSetup();
158 
159  spinUp();
160 
161  process();
162 
163  } // End of method 'BasicFramework::completeProcessing()'
164 
165 
166 } // End of namespace gnsstk
gnsstk::BasicFramework::BasicFramework
BasicFramework()
gnsstk::CommandOptionParser::helpRequested
bool helpRequested()
Returns true if any help was requested.
Definition: CommandOptionParser.hpp:118
StringUtils.hpp
gnsstk::Exception::what
std::string what() const
Dump to a string.
Definition: Exception.cpp:193
gnsstk::CommandOptionParser::dumpErrors
std::ostream & dumpErrors(std::ostream &out)
Writes the errors to out.
Definition: CommandOptionParser.cpp:346
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::Exception
Definition: Exception.hpp:151
gnsstk::BasicFramework::completeProcessing
virtual void completeProcessing()
Definition: BasicFramework.cpp:155
gnsstk::BasicFramework::run
bool run() noexcept
Definition: BasicFramework.cpp:126
gnsstk::CommandOptionParser::parseOptions
void parseOptions(int argc, char *argv[])
Parses the command line.
Definition: CommandOptionParser.cpp:115
Exception.hpp
BasicFramework.hpp
std
Definition: Angle.hpp:142
gnsstk::CommandOptionParser
Definition: CommandOptionParser.hpp:86
gnsstk::BasicFramework::initialize
virtual bool initialize(int argc, char *argv[], bool pretty=true) noexcept
Definition: BasicFramework.cpp:71
gnsstk::CommandOptionParser::displayUsage
std::ostream & displayUsage(std::ostream &out, bool doPretty=true)
Definition: CommandOptionParser.cpp:375
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