|
Revision 2, 2.2 kB
(checked in by nextime, 2 years ago)
|
Initial import, branching from morphix svn
|
| Line | |
|---|
| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
#ifndef __EXCEPT_H |
|---|
| 22 |
#define __EXCEPT_H |
|---|
| 23 |
|
|---|
| 24 |
#include <string> |
|---|
| 25 |
#include <iostream> |
|---|
| 26 |
#include <sstream> |
|---|
| 27 |
|
|---|
| 28 |
class error { |
|---|
| 29 |
std::string function; |
|---|
| 30 |
std::string file; |
|---|
| 31 |
unsigned line; |
|---|
| 32 |
std::string desc; |
|---|
| 33 |
bool ignore; |
|---|
| 34 |
public: |
|---|
| 35 |
error() : line(0), ignore(false) |
|---|
| 36 |
{ |
|---|
| 37 |
} |
|---|
| 38 |
|
|---|
| 39 |
error(bool Aignore) : line(0), ignore(Aignore) |
|---|
| 40 |
{ |
|---|
| 41 |
} |
|---|
| 42 |
|
|---|
| 43 |
error(const char* Afunction, const char* Afile, unsigned Aline) : function(Afunction), file(Afile), line(Aline), ignore(false) |
|---|
| 44 |
{ |
|---|
| 45 |
} |
|---|
| 46 |
|
|---|
| 47 |
const std::string& desc_get() const |
|---|
| 48 |
{ |
|---|
| 49 |
return desc; |
|---|
| 50 |
} |
|---|
| 51 |
|
|---|
| 52 |
const std::string& function_get() const |
|---|
| 53 |
{ |
|---|
| 54 |
return function; |
|---|
| 55 |
} |
|---|
| 56 |
|
|---|
| 57 |
const std::string& file_get() const |
|---|
| 58 |
{ |
|---|
| 59 |
return file; |
|---|
| 60 |
} |
|---|
| 61 |
|
|---|
| 62 |
unsigned line_get() const |
|---|
| 63 |
{ |
|---|
| 64 |
return line; |
|---|
| 65 |
} |
|---|
| 66 |
|
|---|
| 67 |
bool ignore_get() const |
|---|
| 68 |
{ |
|---|
| 69 |
return ignore; |
|---|
| 70 |
} |
|---|
| 71 |
|
|---|
| 72 |
error& operator<<(const char* A) |
|---|
| 73 |
{ |
|---|
| 74 |
desc += A; |
|---|
| 75 |
return *this; |
|---|
| 76 |
} |
|---|
| 77 |
|
|---|
| 78 |
error& operator<<(const std::string& A) |
|---|
| 79 |
{ |
|---|
| 80 |
desc += A; |
|---|
| 81 |
return *this; |
|---|
| 82 |
} |
|---|
| 83 |
|
|---|
| 84 |
error& operator<<(const unsigned A) |
|---|
| 85 |
{ |
|---|
| 86 |
std::ostringstream s; |
|---|
| 87 |
s << A; |
|---|
| 88 |
desc += s.str(); |
|---|
| 89 |
return *this; |
|---|
| 90 |
} |
|---|
| 91 |
|
|---|
| 92 |
}; |
|---|
| 93 |
|
|---|
| 94 |
class error_ignore : public error { |
|---|
| 95 |
public: |
|---|
| 96 |
error_ignore() : error(true) |
|---|
| 97 |
{ |
|---|
| 98 |
} |
|---|
| 99 |
}; |
|---|
| 100 |
|
|---|
| 101 |
#ifndef NDEBUG |
|---|
| 102 |
#define error_trace() \ |
|---|
| 103 |
error(__PRETTY_FUNCTION__,__FILE__,__LINE__) |
|---|
| 104 |
#else |
|---|
| 105 |
#define error_trace() \ |
|---|
| 106 |
error() |
|---|
| 107 |
#endif |
|---|
| 108 |
|
|---|
| 109 |
static inline std::ostream& operator<<(std::ostream& os, const error& e) |
|---|
| 110 |
{ |
|---|
| 111 |
os << e.desc_get(); |
|---|
| 112 |
|
|---|
| 113 |
if (e.function_get().length() || e.file_get().length() || e.line_get()) |
|---|
| 114 |
os << " [at " << e.function_get() << ":" << e.file_get() << ":" << e.line_get() << "]"; |
|---|
| 115 |
|
|---|
| 116 |
return os; |
|---|
| 117 |
} |
|---|
| 118 |
|
|---|
| 119 |
#endif |
|---|
| 120 |
|
|---|