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  *
19  *  File:      Error.hpp
20  *
21  *  Purpose:   To keep track of detail information about errors that occur
22  *             in MB.
23  *
24  *  Date:      9-26-2002
25  *
26  *  Author:    Clinton Stimpson
27  *
28  */
29 
30 
31 
32 #ifndef MOAB_ERROR_HPP
33 #define MOAB_ERROR_HPP
34 
35 #ifndef IS_BUILDING_MB
36 #error "Error.hpp isn't supposed to be included into an application"
37 #endif
38 
39 #include <string>
40 #include <stdarg.h>
41 #include <stdio.h>
42 
43 #include "moab/Types.hpp"
44 #include "moab/Compiler.hpp"
45 
46 #ifdef WIN32
47 #define VSNPRINTF _vsnprintf
48 #else
49 #define VSNPRINTF vsnprintf
50 #endif
51 
52 namespace moab {
53 
54 class Error
55 {
56   //! string to hold the last error that occurred in MB
57   std::string mLastError;
58 
59 public:
60 
Error()61   Error() {}
~Error()62   ~Error(){}
63 
set_last_error(const std::string & error)64   ErrorCode set_last_error(const std::string& error)
65   {
66     mLastError = error;
67     return MB_SUCCESS;
68   }
69 
70   inline ErrorCode set_last_error(const char* fmt, ...) MB_PRINTF(1);
71 
set_last_error(const char * fmt,va_list args)72   ErrorCode set_last_error( const char* fmt, va_list args )
73   {
74     char text[1024];
75     VSNPRINTF( text, sizeof(text), fmt, args );
76     mLastError = text;
77     return MB_SUCCESS;
78   }
79 
get_last_error(std::string & error) const80   ErrorCode get_last_error(std::string& error) const
81   {
82     error = mLastError;
83     return MB_SUCCESS;
84   }
85 
86 };
87 
set_last_error(const char * fmt,...)88 inline ErrorCode Error::set_last_error(const char* fmt, ...)
89 {
90   ErrorCode result = MB_FAILURE;
91   if (fmt)
92   {
93     va_list args;
94     va_start( args, fmt );
95     result = set_last_error( fmt, args );
96     va_end( args );
97   }
98   return result;
99 }
100 
101 } // namespace moab
102 
103 #endif
104 
105 
106