root/morphix/trunk/cloop/advancecomp-1.9_create_compressed_fs/except.h

Revision 2, 2.2 kB (checked in by nextime, 2 years ago)

Initial import, branching from morphix svn

Line 
1 /*
2  * This file is part of the Advance project.
3  *
4  * Copyright (C) 2002 Andrea Mazzoleni
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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
Note: See TracBrowser for help on using the browser.