FFTextStream.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 
44 #include "FFTextStream.hpp"
45 
46 namespace gnsstk
47 {
50  {
51  init();
52  }
53 
54 
57  {
58  }
59 
60 
62  FFTextStream( const char* fn,
63  std::ios::openmode mode )
64  : FFStream(fn, mode)
65  {
66  init();
67  }
68 
69 
71  FFTextStream( const std::string& fn,
72  std::ios::openmode mode )
73  : FFStream( fn.c_str(), mode )
74  {
75  init();
76  }
77 
78 
79  void FFTextStream ::
80  open( const char* fn,
81  std::ios::openmode mode )
82  {
83  FFStream::open(fn, mode);
84  init();
85  }
86 
87 
88  void FFTextStream ::
89  open( const std::string& fn,
90  std::ios::openmode mode )
91  {
92  open(fn.c_str(), mode);
93  }
94 
95 
96  void FFTextStream ::
98  {
99  lineNumber = 0;
100  }
101 
102 
103  void FFTextStream ::
105  {
106  unsigned int initialLineNumber = lineNumber;
107 
108  try
109  {
111  }
112  catch(gnsstk::Exception& e)
113  {
114  e.addText( std::string("Near file line ") +
116  lineNumber = initialLineNumber;
119  }
120  }
121 
122 
123  void FFTextStream ::
125  {
126  unsigned int initialLineNumber = lineNumber;
127 
128  try
129  {
131  }
132  catch(gnsstk::Exception& e)
133  {
134  e.addText( std::string("Near file line ") +
136  lineNumber = initialLineNumber;
139  }
140  }
141 
142 
143  // the reason for checking ffs.eof() in the try AND catch block is
144  // because if the user enabled exceptions on the stream with exceptions()
145  // then eof could throw an exception, in which case we need to catch it
146  // and rethrow an EOF or FFStream exception. In any event, EndOfFile
147  // gets thrown whenever there's an EOF and expectEOF is true
148  void FFTextStream ::
149  formattedGetLine( std::string& line,
150  const bool expectEOF )
151  {
152  try
153  {
154  std::getline(*this, line);
155  // Remove CR characters left over in the buffer from windows files
156  size_t crpos = line.find_last_not_of('\r');
157  if ((crpos+1) < line.length())
158  line.erase(crpos+1);
159  for (int i=0; i<line.length(); i++)
160  {
161  if (!isprint(line[i]))
162  {
163  FFStreamError err("Non-text data in file.");
164  GNSSTK_THROW(err);
165  }
166  }
167 
168  lineNumber++;
169  if(fail() && !eof())
170  {
171  FFStreamError err("Line too long");
172  GNSSTK_THROW(err);
173  }
174  // catch EOF when stream exceptions are disabled
175  if ((line.size() == 0) && eof())
176  {
177  if (expectEOF)
178  {
179  EndOfFile err("EOF encountered");
180  GNSSTK_THROW(err);
181  }
182  else
183  {
184  FFStreamError err("Unexpected EOF encountered");
185  GNSSTK_THROW(err);
186  }
187  }
188  }
189  catch(std::exception &e)
190  {
191  // catch EOF when exceptions are enabled
192  if ( (line.size() == 0) && eof())
193  {
194  if (expectEOF)
195  {
196  EndOfFile err("EOF encountered");
197  GNSSTK_THROW(err);
198  }
199  else
200  {
201  FFStreamError err("Unexpected EOF");
202  GNSSTK_THROW(err);
203  }
204  }
205  else
206  {
207  FFStreamError err("Critical file error: " +
208  std::string(e.what()));
209  GNSSTK_THROW(err);
210  }
211  }
212  } // End of method 'FFTextStream::formattedGetLine()'
213 
214 } // End of namespace gnsstk
gnsstk::FFData
Definition: FFData.hpp:87
gnsstk::FFStream::tryFFStreamPut
virtual void tryFFStreamPut(const FFData &rec)
Definition: FFStream.cpp:284
gnsstk::FFStream
Definition: FFStream.hpp:119
gnsstk::FFTextStream::formattedGetLine
void formattedGetLine(std::string &line, const bool expectEOF=false)
Definition: FFTextStream.cpp:149
gnsstk::FFTextStream::tryFFStreamPut
virtual void tryFFStreamPut(const FFData &rec)
Definition: FFTextStream.cpp:124
gnsstk::FFTextStream::lineNumber
unsigned int lineNumber
Definition: FFTextStream.hpp:98
gnsstk::StringUtils::asString
std::string asString(IonexStoreStrategy e)
Convert a IonexStoreStrategy to a whitespace-free string name.
Definition: IonexStoreStrategy.cpp:46
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::FFStream::open
virtual void open(const char *fn, std::ios::openmode mode)
Definition: FFStream.cpp:100
gnsstk::FFTextStream::~FFTextStream
virtual ~FFTextStream()
Destructor.
Definition: FFTextStream.cpp:56
gnsstk::Exception
Definition: Exception.hpp:151
gnsstk::FFStream::mostRecentException
FFStreamError mostRecentException
This stores the most recently thrown exception.
Definition: FFStream.hpp:173
example4.err
err
Definition: example4.py:126
gnsstk::FFTextStream::init
void init()
Initialize internal data structures.
Definition: FFTextStream.cpp:97
FFTextStream.hpp
gnsstk::FFStream::tryFFStreamGet
virtual void tryFFStreamGet(FFData &rec)
Definition: FFStream.cpp:162
gnsstk::FFTextStream::open
virtual void open(const char *fn, std::ios::openmode mode)
Overrides open to reset the line number.
Definition: FFTextStream.cpp:80
gnsstk::Exception::addText
Exception & addText(const std::string &errorText)
Definition: Exception.cpp:133
GNSSTK_THROW
#define GNSSTK_THROW(exc)
Definition: Exception.hpp:366
example5.fn
string fn
Definition: example5.py:10
gnsstk::FFTextStream::tryFFStreamGet
virtual void tryFFStreamGet(FFData &rec)
Definition: FFTextStream.cpp:104
gnsstk::FFTextStream::FFTextStream
FFTextStream()
Default constructor.
Definition: FFTextStream.cpp:49
gnsstk::FFStream::conditionalThrow
void conditionalThrow(void)
Definition: FFStream.hpp:213


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