00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef cxxtools_SourceInfo_h
00030 #define cxxtools_SourceInfo_h
00031
00032 #include <string>
00033
00034
00035 #ifdef __GNUC__
00036 #define CXXTOOLS_FUNCTION __PRETTY_FUNCTION__
00037
00038 #elif defined(__BORLANDC__)
00039 #define CXXTOOLS_FUNCTION __FUNC__
00040
00041 #elif defined(_MSC_VER)
00042
00043 #if _MSC_VER >= 1300
00044 #define CXXTOOLS_FUNCTION __FUNCDNAME__
00045 #else
00046 #define CXXTOOLS_FUNCTION __FUNCTION__
00047 #endif
00048
00049 #else
00050 #define CXXTOOLS_FUNCTION "unknown symbol"
00051 #endif
00052
00053 #define CXXTOOLS_STRINGIFY(x) #x
00054 #define CXXTOOLS_TOSTRING(x) CXXTOOLS_STRINGIFY(x)
00055
00056 #define CXXTOOLS_SOURCEINFO_STR __FILE__ ":" CXXTOOLS_TOSTRING(__LINE__)
00057
00060 #define CXXTOOLS_ERROR_MSG(msg) __FILE__ ":" CXXTOOLS_TOSTRING(__LINE__) ": " #msg
00061
00064 #define CXXTOOLS_SOURCEINFO cxxtools::SourceInfo(__FILE__, CXXTOOLS_TOSTRING(__LINE__), CXXTOOLS_FUNCTION)
00065
00066 namespace cxxtools {
00067
00087 class SourceInfo {
00088 public:
00095 inline SourceInfo(const char* file, const char* line, const char* func)
00096 : _file(file), _line(line), _func(func)
00097 { }
00098
00101 inline const char* file() const
00102 { return _file; }
00103
00106 inline const char* line() const
00107 { return _line; }
00108
00111 inline const char* func() const
00112 { return _func; }
00113
00114 private:
00115 const char* _file;
00116 const char* _line;
00117 const char* _func;
00118 };
00119
00120
00121 inline std::string operator+(const std::string& what, const SourceInfo& info)
00122 {
00123 return std::string( info.file() ) + ':' + info.line() + ": " += what;
00124 }
00125
00126 inline std::string operator+(const char* what, const SourceInfo& info)
00127 {
00128 return std::string( info.file() ) + ':' + info.line() + ": " += what;
00129 }
00130
00131 inline std::string operator+( const SourceInfo& info, const std::string& what)
00132 {
00133 return std::string( info.file() ) + ':' + info.line() + ": " += what;
00134 }
00135
00136 inline std::string operator+(const SourceInfo& info, const char* what)
00137 {
00138 return std::string( info.file() ) + ':' + info.line() + ": " += what;
00139 }
00140
00141 }
00142
00143 #endif