InOutFramework.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 
45 #ifndef INOUTFRAMEWORK_HPP
46 #define INOUTFRAMEWORK_HPP
47 
48 #include "LoopedFramework.hpp"
49 
50 
51 namespace gnsstk
52 {
54 
55 
68  template<class IType, class OType>
70  {
71  public:
73  static const int OUTPUT_ERROR = 1;
74 
81  InOutFramework( const std::string& applName,
82  const std::string& applDesc )
83  noexcept
84  : LoopedFramework(applName, applDesc)
85  {};
86 
87 
89  virtual ~InOutFramework() {};
90 
91 
92  bool initialize( int argc,
93  char *argv[],
94  bool pretty = true )
95  noexcept
96  {
97  using std::ios;
98 
100  inputOpt('i', "input",
101  "A file to take the input from. The default is stdin."),
102  outputOpt('o', "output",
103  "A file to receive the output. The default is stdout.");
104 
105  if (!LoopedFramework::initialize(argc, argv, pretty))
106  return false;
107 
108  if (inputOpt.getCount())
109  inputFn = inputOpt.getValue()[0];
110 
111 
112  if (inputFn=="-" || inputFn=="")
113  {
114  input.copyfmt(std::cin);
115  input.clear(std::cin.rdstate());
116  input.ios::rdbuf(std::cin.rdbuf());
117  inputFn = "<stdin>";
118  }
119  else
120  {
121  input.open(inputFn.c_str(), std::ios::in);
122  }
123 
124 
125  if (!input)
126  {
127  std::cerr << "Could not open: " << inputFn << std::endl;
129  return false;
130  }
131 
132  if (outputOpt.getCount())
133  outputFn = outputOpt.getValue()[0];
134 
135  if (outputFn=="-" || outputFn=="")
136  {
137  output.copyfmt(std::cout);
138  output.clear(std::cout.rdstate());
139  output.ios::rdbuf(std::cout.rdbuf());
140  outputFn = "<stdout>";
141  }
142  else
143  {
144  output.open(outputFn.c_str(), std::ios::out);
145  }
146 
147  if (!output)
148  {
149  std::cerr << "Could not open: " << outputFn << std::endl;
151  return false;
152  }
153 
154  if (debugLevel)
155  std::cerr << "Sending output to " << outputFn << std::endl
156  << "Reading input from " << inputFn << std::endl;
157 
158  return true;
159  } // End of method 'InOutFramework::initialize()'
160 
161 
162  IType input;
163 
164  OType output;
165 
166  std::string inputFn, outputFn;
167 
168 
169  private:
170 
171 
172  // Do not allow the use of the default constructor.
173  InOutFramework();
174 
175 
176  }; // End of class 'InOutFramework'
177 
179 
180 } // End of namespace gnsstk
181 #endif // INOUTFRAMEWORK_HPP
gnsstk::InOutFramework::input
IType input
Definition: InOutFramework.hpp:162
gnsstk::InOutFramework::output
OType output
Definition: InOutFramework.hpp:164
gnsstk::InOutFramework::inputFn
std::string inputFn
Definition: InOutFramework.hpp:166
gnsstk::InOutFramework::InOutFramework
InOutFramework(const std::string &applName, const std::string &applDesc) noexcept
Definition: InOutFramework.hpp:81
gnsstk::LoopedFramework
Definition: LoopedFramework.hpp:69
gnsstk::BasicFramework::debugLevel
int debugLevel
Debug level for this run of the program.
Definition: BasicFramework.hpp:455
gnsstk::InOutFramework::~InOutFramework
virtual ~InOutFramework()
Destructor.
Definition: InOutFramework.hpp:89
gnsstk::CommandOption::getCount
virtual unsigned long getCount() const
Definition: CommandOption.hpp:188
gnsstk::CommandOptionWithAnyArg
Definition: CommandOption.hpp:342
LoopedFramework.hpp
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::LoopedFramework::LoopedFramework
LoopedFramework()
gnsstk::InOutFramework::OUTPUT_ERROR
static const int OUTPUT_ERROR
Exit code used when the output file can't be opened.
Definition: InOutFramework.hpp:73
gnsstk::BasicFramework::EXIST_ERROR
static const int EXIST_ERROR
Definition: BasicFramework.hpp:402
gnsstk::InOutFramework::outputFn
std::string outputFn
Definition: InOutFramework.hpp:166
gnsstk::BasicFramework::exitCode
int exitCode
Definition: BasicFramework.hpp:450
gnsstk::CommandOption::getValue
const std::vector< std::string > & getValue() const
Definition: CommandOption.hpp:194
gnsstk::InOutFramework::InOutFramework
InOutFramework()
gnsstk::InOutFramework
Definition: InOutFramework.hpp:69
gnsstk::BasicFramework::initialize
virtual bool initialize(int argc, char *argv[], bool pretty=true) noexcept
Definition: BasicFramework.cpp:71
gnsstk::InOutFramework::initialize
bool initialize(int argc, char *argv[], bool pretty=true) noexcept
Definition: InOutFramework.hpp:92


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