Exception.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 <sstream>
45 #include "Exception.hpp"
46 
47 using std::ostream;
48 using std::ostringstream;
49 using std::streambuf;
50 using std::string;
51 using std::endl;
52 
53 namespace gnsstk
54 {
55 
56  void ExceptionLocation::dump(ostream& s) const
57  {
58  s << getFileName() << ":"
59 #ifdef __FUNCTION__
60  << getFunctionName() << ":"
61 #endif
62  << getLineNumber();
63  }
64 
66  {
67  }
68 
69  Exception::Exception(const std::string& errorText,
70  const unsigned long& errId,
71  const Severity& sever)
72  {
73  text.push_back(errorText);
74  errorId = errId;
75  severity = sever;
76  }
77 
78  Exception::Exception(const char* errorText,
79  const unsigned long& errId,
80  const Severity& sever)
81  {
82  text.push_back(string(errorText));
83  errorId = errId;
84  severity = sever;
85  }
86 
88  : errorId(e.errorId),
89  locations(e.locations),
90  severity(e.severity),
91  text(e.text),
92  streamBuffer(e.streamBuffer)
93  {}
94 
96  {
97  errorId = e.errorId;
98  locations = e.locations;
99  severity = e.severity;
100  text = e.text;
101  // reuse existing stream objects, no matter.
102  //streambuf(), ostream((streambuf*)this),
104 
105  return *this;
106  }
107 
109  const ExceptionLocation& location)
110  {
111  locations.push_back(location);
112  return *this;
113  }
114 
116  const size_t& index) const
117  {
118  if (index>=getLocationCount())
119  {
120  return ExceptionLocation();
121  }
122  else
123  {
124  return locations[index];
125  }
126  }
127 
129  {
130  return locations.size();
131  }
132 
133  Exception& Exception::addText(const string& errorText)
134  {
135  text.push_back(errorText);
136  return *this;
137  }
138 
139  string Exception::getText(const size_t& index) const
140  {
141  if (index>=getTextCount())
142  {
143  string tmp;
144  return tmp;
145  }
146  else
147  {
148  return text[index];
149  }
150  }
151 
152  size_t Exception::getTextCount() const
153  {
154  return text.size();
155  }
156 
157  void Exception::dump(ostream& s) const
158  {
159  size_t i;
160  for (i=0; i<getTextCount(); i++)
161  {
162  s << "text " << i << ":" << this->getText(i) << endl;
163  }
164  for (i=0; i<getLocationCount(); i++)
165  {
166  s << "location " << i << ":" << getLocation(i).what() << endl;
167  }
168  }
169 
171  {
172  if (c == '\n' || !c)
173  {
174  if (streamBuffer.length() == 0)
175  {
176  return c;
177  }
179  streamBuffer = "";
180  return c;
181  }
182  streamBuffer.append(1, (char)c);
183  return c;
184  }
185 
186  string ExceptionLocation::what() const
187  {
188  ostringstream oss;
189  this->dump(oss);
190  return oss.str();
191  }
192 
193  string Exception::what() const
194  {
195  ostringstream oss;
196  this->dump(oss);
197  return oss.str();
198  }
199 
200  ostream& operator<<( ostream& s,
201  const Exception& e )
202  {
203  e.dump(s);
204  return s;
205  }
206 
207  ostream& operator<<( ostream& s,
208  const ExceptionLocation& e )
209  {
210  e.dump(s);
211  return s;
212  }
213 
214 } // namespace gnsstk
gnsstk::Exception::overflow
int overflow(int c)
Definition: Exception.cpp:170
gnsstk::Exception::errorId
unsigned long errorId
Error code.
Definition: Exception.hpp:312
gnsstk::Exception::operator=
Exception & operator=(const Exception &e)
Assignment operator.
Definition: Exception.cpp:95
gnsstk::ExceptionLocation::dump
void dump(std::ostream &s) const
Definition: Exception.cpp:56
gnsstk::Exception::locations
std::vector< ExceptionLocation > locations
Stack of exception locations (where it was thrown).
Definition: Exception.hpp:314
gnsstk::Exception::Exception
Exception()
Definition: Exception.cpp:65
gnsstk::Exception::what
std::string what() const
Dump to a string.
Definition: Exception.cpp:193
gnsstk::Exception::getTextCount
size_t getTextCount() const
Returns the number of text strings in the exception text stack.
Definition: Exception.cpp:152
gnsstk::ExceptionLocation::getLineNumber
unsigned long getLineNumber() const
Accessor for line of source file where exception occurred.
Definition: Exception.hpp:97
gnsstk::Exception::addLocation
Exception & addLocation(const ExceptionLocation &location)
Definition: Exception.cpp:108
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::Exception
Definition: Exception.hpp:151
gnsstk::Exception::getText
std::string getText(const size_t &index=0) const
Definition: Exception.cpp:139
gnsstk::Exception::getLocationCount
size_t getLocationCount() const
Definition: Exception.cpp:128
gnsstk::Exception::Severity
Severity
Exception severity classes.
Definition: Exception.hpp:155
gnsstk::operator<<
std::ostream & operator<<(std::ostream &s, const ObsEpoch &oe) noexcept
Definition: ObsEpochMap.cpp:54
gnsstk::Exception::dump
void dump(std::ostream &s) const
Definition: Exception.cpp:157
Exception.hpp
gnsstk::ExceptionLocation::what
std::string what() const
Dump to a string.
Definition: Exception.cpp:186
gnsstk::Exception::getLocation
const ExceptionLocation getLocation(const size_t &index=0) const
Definition: Exception.cpp:115
gnsstk::Exception::addText
Exception & addText(const std::string &errorText)
Definition: Exception.cpp:133
gnsstk::ExceptionLocation::getFileName
std::string getFileName() const
Accessor for name of source file where exception occurred.
Definition: Exception.hpp:91
gnsstk::Exception::streamBuffer
std::string streamBuffer
Buffer for stream output.
Definition: Exception.hpp:332
gnsstk::Exception::severity
Severity severity
Severity of exception.
Definition: Exception.hpp:316
gnsstk::Exception::text
std::vector< std::string > text
Text stack describing exception condition.
Definition: Exception.hpp:318
gnsstk::ExceptionLocation
Definition: Exception.hpp:69
gnsstk::ExceptionLocation::getFunctionName
std::string getFunctionName() const
Accessor for name of function where exception occurred.
Definition: Exception.hpp:94


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