MOAB: Mesh Oriented datABase  (version 5.4.1)
Error.hpp
Go to the documentation of this file.
00001 /**
00002  * MOAB, a Mesh-Oriented datABase, is a software component for creating,
00003  * storing and accessing finite element mesh data.
00004  *
00005  * Copyright 2004 Sandia Corporation.  Under the terms of Contract
00006  * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
00007  * retains certain rights in this software.
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2.1 of the License, or (at your option) any later version.
00013  *
00014  */
00015 
00016 /*
00017  *
00018  *  File:      Error.hpp
00019  *
00020  *  Purpose:   To keep track of detail information about errors that occur
00021  *             in MB.
00022  *
00023  *  Date:      9-26-2002
00024  *
00025  *  Author:    Clinton Stimpson
00026  *
00027  */
00028 
00029 #ifndef MOAB_ERROR_HPP
00030 #define MOAB_ERROR_HPP
00031 
00032 #ifndef IS_BUILDING_MB
00033 #error "Error.hpp isn't supposed to be included into an application"
00034 #endif
00035 
00036 #include <string>
00037 #include <cstdarg>
00038 #include <cstdio>
00039 
00040 #include "moab/Types.hpp"
00041 #include "moab/Compiler.hpp"
00042 
00043 #ifdef WIN32
00044 #define VSNPRINTF _vsnprintf
00045 #else
00046 #define VSNPRINTF vsnprintf
00047 #endif
00048 
00049 namespace moab
00050 {
00051 
00052 class Error
00053 {
00054     //! string to hold the last error that occurred in MB
00055     std::string mLastError;
00056 
00057   public:
00058     Error() {}
00059     ~Error() {}
00060 
00061     ErrorCode set_last_error( const std::string& error )
00062     {
00063         mLastError = error;
00064         return MB_SUCCESS;
00065     }
00066 
00067     inline ErrorCode set_last_error( const char* fmt, ... ) MB_PRINTF( 1 );
00068 
00069     ErrorCode set_last_error( const char* fmt, va_list args )
00070     {
00071         char text[1024];
00072         VSNPRINTF( text, sizeof( text ), fmt, args );
00073         mLastError = text;
00074         return MB_SUCCESS;
00075     }
00076 
00077     ErrorCode get_last_error( std::string& error ) const
00078     {
00079         error = mLastError;
00080         return MB_SUCCESS;
00081     }
00082 };
00083 
00084 inline ErrorCode Error::set_last_error( const char* fmt, ... )
00085 {
00086     ErrorCode result = MB_FAILURE;
00087     if( fmt )
00088     {
00089         va_list args;
00090         va_start( args, fmt );
00091         result = set_last_error( fmt, args );
00092         va_end( args );
00093     }
00094     return result;
00095 }
00096 
00097 }  // namespace moab
00098 
00099 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines