Mesh Oriented datABase  (version 5.5.0)
An array-based unstructured mesh library
Error.hpp
Go to the documentation of this file.
1 /**
2  * MOAB, a Mesh-Oriented datABase, is a software component for creating,
3  * storing and accessing finite element mesh data.
4  *
5  * Copyright 2004 Sandia Corporation. Under the terms of Contract
6  * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
7  * retains certain 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  */
15 
16 /*
17  *
18  * File: Error.hpp
19  *
20  * Purpose: To keep track of detail information about errors that occur
21  * in MB.
22  *
23  * Date: 9-26-2002
24  *
25  * Author: Clinton Stimpson
26  *
27  */
28 
29 #ifndef MOAB_ERROR_HPP
30 #define MOAB_ERROR_HPP
31 
32 #ifndef IS_BUILDING_MB
33 #error "Error.hpp isn't supposed to be included into an application"
34 #endif
35 
36 #include <string>
37 #include <cstdarg>
38 #include <cstdio>
39 
40 #include "moab/Types.hpp"
41 #include "moab/Compiler.hpp"
42 
43 #ifdef WIN32
44 #define VSNPRINTF _vsnprintf
45 #else
46 #define VSNPRINTF vsnprintf
47 #endif
48 
49 namespace moab
50 {
51 
52 class Error
53 {
54  //! string to hold the last error that occurred in MB
55  std::string mLastError;
56 
57  public:
58  Error() {}
59  ~Error() {}
60 
61  ErrorCode set_last_error( const std::string& error )
62  {
63  mLastError = error;
64  return MB_SUCCESS;
65  }
66 
67  inline ErrorCode set_last_error( const char* fmt, ... ) MB_PRINTF( 1 );
68 
69  ErrorCode set_last_error( const char* fmt, va_list args )
70  {
71  char text[1024];
72  VSNPRINTF( text, sizeof( text ), fmt, args );
73  mLastError = text;
74  return MB_SUCCESS;
75  }
76 
77  ErrorCode get_last_error( std::string& error ) const
78  {
79  error = mLastError;
80  return MB_SUCCESS;
81  }
82 };
83 
84 inline ErrorCode Error::set_last_error( const char* fmt, ... )
85 {
86  ErrorCode result = MB_FAILURE;
87  if( fmt )
88  {
89  va_list args;
90  va_start( args, fmt );
91  result = set_last_error( fmt, args );
92  va_end( args );
93  }
94  return result;
95 }
96 
97 } // namespace moab
98 
99 #endif