Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
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_ */
elm::ErrorBase
Definition: ErrorHandler.h:49
elm::ErrorHandler::QUIET
static ErrorHandler & QUIET
Definition: ErrorHandler.h:44
elm::ErrorHandler::~ErrorHandler
virtual ~ErrorHandler()
Definition: ErrorHandler.h:45
elm::ErrorBase::setErrorHandler
void setErrorHandler(ErrorHandler *error_handler)
Definition: ErrorHandler.h:53
elm::ErrorHandler::NO_INFO
static ErrorHandler & NO_INFO
Definition: ErrorHandler.h:44
elm::level_warning
@ level_warning
Definition: ErrorHandler.h:34
elm::level_error
@ level_error
Definition: ErrorHandler.h:35
elm::error_level_t
error_level_t
Definition: ErrorHandler.h:31
elm::CString
Definition: CString.h:17
elm::ErrorBase::onError
void onError(error_level_t level, const string &message)
Definition: ErrorHandler.h:58
elm::ErrorHandler::onError
virtual void onError(error_level_t level, const string &message)
Definition: util_ErrorHandler.cpp:60
elm
Definition: adapter.h:26
elm::ErrorHandler::DEFAULT
static ErrorHandler DEFAULT
Definition: ErrorHandler.h:44
elm::level_fatal
@ level_fatal
Definition: ErrorHandler.h:36
elm::ErrorHandler::getLevelString
static cstring getLevelString(error_level_t level)
Definition: util_ErrorHandler.cpp:42
elm::level_info
@ level_info
Definition: ErrorHandler.h:33
elm::ErrorBase::getErrorHandler
ErrorHandler * getErrorHandler(void) const
Definition: ErrorHandler.h:55
elm::ErrorBase::ErrorBase
ErrorBase(ErrorHandler *error_handler=&ErrorHandler::DEFAULT)
Definition: ErrorHandler.h:51
elm::ErrorHandler
Definition: ErrorHandler.h:40
elm::level_none
@ level_none
Definition: ErrorHandler.h:32