moab
|
00001 00017 /* 00018 * 00019 * File: Error.hpp 00020 * 00021 * Purpose: To keep track of detail information about errors that occur 00022 * in MB. 00023 * 00024 * Date: 9-26-2002 00025 * 00026 * Author: Clinton Stimpson 00027 * 00028 */ 00029 00030 00031 00032 #ifndef MOAB_ERROR_HPP 00033 #define MOAB_ERROR_HPP 00034 00035 #ifndef IS_BUILDING_MB 00036 #error "Error.hpp isn't supposed to be included into an application" 00037 #endif 00038 00039 #include <string> 00040 #include <stdarg.h> 00041 #include <stdio.h> 00042 00043 #include "moab/Types.hpp" 00044 #include "moab/Compiler.hpp" 00045 00046 #ifdef WIN32 00047 #define VSNPRINTF _vsnprintf 00048 #else 00049 #define VSNPRINTF vsnprintf 00050 #endif 00051 00052 namespace moab { 00053 00054 class Error 00055 { 00057 std::string mLastError; 00058 00059 public: 00060 00061 Error() {} 00062 ~Error(){} 00063 00064 ErrorCode set_last_error(const std::string& error) 00065 { 00066 mLastError = error; 00067 return MB_SUCCESS; 00068 } 00069 00070 inline ErrorCode set_last_error(const char* fmt, ...) MB_PRINTF(1); 00071 00072 ErrorCode set_last_error( const char* fmt, va_list args ) 00073 { 00074 char text[1024]; 00075 VSNPRINTF( text, sizeof(text), fmt, args ); 00076 mLastError = text; 00077 return MB_SUCCESS; 00078 } 00079 00080 ErrorCode get_last_error(std::string& error) const 00081 { 00082 error = mLastError; 00083 return MB_SUCCESS; 00084 } 00085 00086 }; 00087 00088 inline ErrorCode Error::set_last_error(const char* fmt, ...) 00089 { 00090 ErrorCode result = MB_FAILURE; 00091 if (fmt) 00092 { 00093 va_list args; 00094 va_start( args, fmt ); 00095 result = set_last_error( fmt, args ); 00096 va_end( args ); 00097 } 00098 return result; 00099 } 00100 00101 } // namespace moab 00102 00103 #endif 00104 00105