usb: getting string descriptors, minor improvements
[quarnos.git] / manes / error.h
blobd42eb6a6cb8b28e4c48fef5be6ed6aafaa6a6f4b
1 /* Quarn OS
3 * Error messages
5 * Copyright (C) 2008-2009 Pawel Dziepak
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #ifndef _ERROR_H_
24 #define _ERROR_H_
26 #include "libs/pointer.h"
27 #include "libs/string.h"
28 #include "libs/colors.h"
29 #include "libs/stream.h"
31 namespace manes {
32 class error {
33 private:
34 static p<resources::stream> msg_output;
36 p<error> base_err;
37 const string er_message;
39 void er_print(const string&, color::color);
40 public:
41 error(const string&);
42 explicit error(p<error>);
43 error(p<error>, const string&);
45 void debug();
46 void assertion();
47 void critical() __attribute__((noreturn));
51 #define on_stack(x) ((unsigned int)(x) < 0x2fffff && (unsigned int)(x) > 0x200000)
53 static inline void critical(const string&) __attribute__((noreturn));
55 static inline void critical(const string &info) {
56 p<manes::error> er = new manes::error(info);
57 er->critical();
58 while(1);
61 static inline void debug(const string &info) {
62 p<manes::error> er = new manes::error(info);
63 er->debug();
66 #define _QUOTE(x) #x
67 #define QUOTE(x) _QUOTE(x)
69 #if DEBUG_MODE == CONF_YES
70 #define assert(msg, cond) \
71 if (cond) { \
72 p<manes::error> er = new manes::error((string)msg + " @" + __FILE__ + ":" + QUOTE(__LINE__) ); \
73 er->assertion(); \
75 #else
76 #define assert(msg, cond)
77 #endif
79 #endif