Elm  1.0
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ErrorHandler.h
1 /*
2  * $Id$
3  * ErrorHandler and ErrorBase class interface
4  *
5  * This file is part of OTAWA
6  * Copyright (c) 2009, IRIT UPS.
7  *
8  * OTAWA is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * OTAWA is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with OTAWA; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 #ifndef ELM_UTIL_ERRORHANDLER_H_
23 #define ELM_UTIL_ERRORHANDLER_H_
24 
25 #include <elm/assert.h>
26 #include <elm/string.h>
27 
28 namespace elm {
29 
30 // error level type
31 typedef enum error_level_t {
38 
39 // ErrorHandler class
40 class ErrorHandler {
41 public:
42  virtual void onError(error_level_t level, const string& message);
43  static cstring getLevelString(error_level_t level);
45  virtual ~ErrorHandler() {};
46 };
47 
48 // ErrorBase class
49 class ErrorBase {
50 public:
51  inline ErrorBase(ErrorHandler *error_handler = &ErrorHandler::DEFAULT)
52  { setErrorHandler(error_handler); }
53  inline void setErrorHandler(ErrorHandler *error_handler)
54  { ASSERTP(error_handler, "null error handler"); handler = error_handler; }
55  inline ErrorHandler *getErrorHandler(void) const { return handler; }
56 
57 protected:
58  inline void onError(error_level_t level, const string& message) { handler->onError(level, message); }
59 
60 private:
61  ErrorHandler *handler;
62 };
63 
64 } // elm
65 
66 #endif /* ELM_UTIL_ERRORHANDLER_H_ */
Definition: CString.h:17
virtual ~ErrorHandler()
Definition: ErrorHandler.h:45
error_level_t
Definition: ErrorHandler.h:31
Definition: ErrorHandler.h:49
static cstring getLevelString(error_level_t level)
Definition: util_ErrorHandler.cpp:42
Definition: ErrorHandler.h:32
Definition: ErrorHandler.h:34
void setErrorHandler(ErrorHandler *error_handler)
Definition: ErrorHandler.h:53
Definition: ErrorHandler.h:40
ErrorHandler * getErrorHandler(void) const
Definition: ErrorHandler.h:55
ErrorBase(ErrorHandler *error_handler=&ErrorHandler::DEFAULT)
Definition: ErrorHandler.h:51
virtual void onError(error_level_t level, const string &message)
Definition: util_ErrorHandler.cpp:60
void onError(error_level_t level, const string &message)
Definition: ErrorHandler.h:58
Definition: ErrorHandler.h:35
static ErrorHandler DEFAULT
Definition: ErrorHandler.h:44
Definition: ErrorHandler.h:33
static ErrorHandler STD
Definition: ErrorHandler.h:44
Definition: ErrorHandler.h:36