Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
includeLinks/MsqError.hpp
Go to the documentation of this file.
1 /* *****************************************************************
2  MESQUITE -- The Mesh Quality Improvement Toolkit
3 
4  Copyright 2004 Sandia Corporation and Argonne National
5  Laboratory. Under the terms of Contract DE-AC04-94AL85000
6  with Sandia Corporation, the U.S. Government retains certain
7  rights in this software.
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public License
20  (lgpl.txt) along with this library; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 
23  ***************************************************************** */
24 
25 #ifndef MSQ_ERROR_HPP
26 #define MSQ_ERROR_HPP
27 
28 #include "Mesquite.hpp"
29 
30 #ifdef MSQ_USE_OLD_IO_HEADERS
31 class ostream;
32 #else
33 #include <iosfwd>
34 #endif
35 
36 #ifdef MSQ_USE_OLD_STD_HEADERS
37 # include <list.h>
38 #else
39 # include <list>
40 #endif
41 
42 #include <string>
43 
44 namespace Mesquite
45 {
46 
50 
51 #ifndef MSQ_FUNCTION
52 # define MSQ_FUNCTION ""
53 #endif
54 
55 
62 #define MSQ_CHKERR(err) (err.error() && err.push(MSQ_FUNCTION,__FILE__,__LINE__))
63 
68 #define MSQ_ERRRTN(err) if (MSQ_CHKERR(err)) return
69 
72 #define MSQ_ERRZERO(err) if (MSQ_CHKERR(err)) return 0
73 
83 #define MSQ_SETERR(err) \
84 Mesquite::MsqError::setter(err, MSQ_FUNCTION,__FILE__,__LINE__).set
85 
106 class MsqError {
107 public:
108 
109  /* NOTE: If you add an error to this list, make sure
110  a) you add it *before* LAST_ERROR_CODE
111  b) you add the corresponding string in MsqError.cpp
112  */
115  enum ErrorCode {
116  NO_ERROR = 0,
134  };
135 
137  void clear();
138 
140  inline bool error() const { return NO_ERROR != errorCode; }
142  inline operator bool() const { return NO_ERROR != errorCode; }
143 
146 
148  virtual ~MsqError();
149 
150  /* ************************************************************ *
151  * Low-level access to error data
152  * ************************************************************ */
153 
155  inline ErrorCode error_code() const { return errorCode; }
156 
159  struct Trace {
160  msq_std::string function;
161  msq_std::string file;
162  int line;
163 
164  Trace( const char* fun, const char* fil, int lin )
165  : function(fun), file(fil), line(lin) {}
166  };
167 
169  const char* error_message() const;
170 
173  typedef msq_std::list<Trace> StackTrace;
174 
176  inline const StackTrace& stack() const { return stackTrace; }
177 
178 
179  /* ************************************************************ *
180  * Set error data
181  * ************************************************************ */
182 
185  virtual bool push( const char* function, const char* file, int line );
186 
188  virtual bool set_error( ErrorCode num, const char* msg = 0 );
189 
193  class Setter {
194  public:
195  Setter(MsqError& err, const char* function, const char* file, int line)
196  : mErr(err), functionName(function), fileName(file), lineNumber(line) {}
197 
198  bool set( ErrorCode num );
199  bool set( const char* message, ErrorCode num );
200  bool set( const msq_std::string& message, ErrorCode num );
201  bool set( ErrorCode num, const char* format, ... )
202  #ifdef __GNUC__
203  __attribute__ ((format (printf, 3, 4)))
204  #endif
205  ; // ending semicolon for set( ErrorCode num, const char* format, ... )
206  private:
208  const char* functionName;
209  const char* fileName;
211  };
212 
213  static inline Setter setter( MsqError& err, const char* function, const char* file, int line )
214  { return Setter( err, function, file, line ); }
215 
216 private:
217 
219  msq_std::string errorMessage;
221 };
222 
223 
225 msq_stdio::ostream& operator<<( msq_stdio::ostream&, const MsqError& );
227 msq_stdio::ostream& operator<<( msq_stdio::ostream&, const MsqError::Trace& );
228 
241 class MsqPrintError : public MsqError
242 {
243  public:
245  MsqPrintError( msq_stdio::ostream& stream )
246  : outputStream(stream) {}
247 
249  virtual ~MsqPrintError( );
250 
251  private:
252 
253  msq_std::ostream& outputStream;
254 };
255 
258 } // namespace
259 
260 
261 #endif
262 
263 
An I/O error occured (e.g.
unable to allocate the necessary memory
Used to hold the error state and return it to the application.
ErrorCode error_code() const
Get error code.
virtual bool push(const char *function, const char *file, int line)
Add to back-trace of call stack.
MsqPrintError(msq_stdio::ostream &stream)
Initialize with ostream to print error data to.
requested functionality is not (yet) implemented
Attempt to create tag that already exists.
subroutine function
Definition: TEMPLATE.F90:43
virtual bool set_error(ErrorCode num, const char *msg=0)
Initialize the error object with the passed data.
One line of stack trace data.
MsqError()
Initialize to cleared state.
invalid function argument passed
bool error() const
Check if an error has occured.
msq_std::list< Trace > StackTrace
Container type used to store stack trace.
bool set(ErrorCode num)
Setter(MsqError &err, const char *function, const char *file, int line)
static Setter setter(MsqError &err, const char *function, const char *file, int line)
Application or user interrupted operation.
const char * error_message() const
Get error message.
File cannot be opened/created.
Specified tag does not exist.
Utility class for printing error data - used in Mesquite tests.
object is in an invalid state
void clear()
resets error object to non-active state (no error).
virtual ~MsqError()
Destructor - empty but must declar virtual destrucor if virtual functions.
msq_stdio::ostream & operator<<(msq_stdio::ostream &s, const Matrix3D &A)
virtual ~MsqPrintError()
On destruction, conditionally prints error data.
const StackTrace & stack() const
Get stack trace.
no storage mode chosen within PatchData
Error parsing input (or input file)
Trace(const char *fun, const char *fil, int lin)