Commit | Line | Data |
---|---|---|
0e23f538 TJ |
1 | /* |
2 | The software in this package is distributed under the GNU General | |
3 | Public License version 2 (with a special exception described below). | |
4 | ||
5 | A copy of GNU General Public License (GPL) is included in this distribution, | |
6 | in the file COPYING.GPL. | |
7 | ||
8 | As a special exception, if other files instantiate templates or use macros | |
9 | or inline functions from this file, or you compile this file and link it | |
10 | with other works to produce a work based on this file, this file | |
11 | does not by itself cause the resulting work to be covered | |
12 | by the GNU General Public License. | |
13 | ||
14 | However the source code for this file must still be made available | |
15 | in accordance with section (3) of the GNU General Public License. | |
16 | ||
17 | This exception does not invalidate any other reasons why a work based | |
18 | on this file might be covered by the GNU General Public License. | |
19 | */ | |
b6fb82a2 RP |
20 | /** @file |
21 | * | |
22 | * @copyright © Copyright 2007-2008 by Intra2net AG | |
b6fb82a2 RP |
23 | */ |
24 | ||
25 | #ifndef __I2N_COMMON_SOURCE_TRACK_BASICS_HPP__ | |
26 | #define __I2N_COMMON_SOURCE_TRACK_BASICS_HPP__ | |
27 | ||
28 | #include <string> | |
29 | #include <boost/current_function.hpp> | |
30 | ||
31 | /* | |
32 | ** some helper macros | |
33 | */ | |
34 | ||
35 | /** | |
36 | * macro which encapsulates the construction of a source location. | |
37 | */ | |
38 | #define HERE ::I2n::SourceLocation(__FILE__,__LINE__,BOOST_CURRENT_FUNCTION) | |
39 | ||
40 | ||
41 | namespace I2n | |
42 | { | |
43 | ||
44 | ||
45 | /** | |
46 | * (helper) struct for providing a source location. | |
47 | * Construction should be done with appropriate macros (like @a HERE) | |
48 | */ | |
49 | struct SourceLocation | |
50 | { | |
51 | std::string File; | |
52 | long Line; | |
53 | std::string FunctionName; | |
54 | ||
55 | SourceLocation(); | |
56 | ||
57 | SourceLocation( | |
58 | const std::string& file, | |
59 | long line, | |
60 | const std::string& funcname); | |
61 | ||
62 | operator bool() const | |
63 | { | |
64 | return Line>0 and not File.empty() and not FunctionName.empty(); | |
65 | } // eo operator bool | |
66 | ||
67 | std::string get_function_name() const { return FunctionName; } | |
68 | std::string get_filename() const { return File; } | |
69 | long get_line_number() const { return Line; } | |
70 | ||
71 | std::string get_location_tag() const; | |
72 | ||
73 | private: | |
74 | ||
75 | mutable std::string LocationTag; | |
76 | ||
77 | }; // eo struct SourceLocation | |
78 | ||
79 | ||
80 | ||
81 | ||
82 | } // eo namepsace I2n | |
83 | ||
84 | #endif |