Webmaster  |  Imprint 
C++ Server Pages
Main  |  License  |  Documentation  |  Download 

/home/tommi/cxxtools/include/cxxtools/sourceinfo.h

00001 /*
00002  * Copyright (C) 2004-2007 Marc Boris Duerner
00003  * Copyright (C)      2006 Aloysius Indrayanto
00004  * 
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Lesser General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2.1 of the License, or (at your option) any later version.
00009  * 
00010  * As a special exception, you may use this file as part of a free
00011  * software library without restriction. Specifically, if other files
00012  * instantiate templates or use macros or inline functions from this
00013  * file, or you compile this file and link it with other files to
00014  * produce an executable, this file does not by itself cause the
00015  * resulting executable to be covered by the GNU General Public
00016  * License. This exception does not however invalidate any other
00017  * reasons why the executable file might be covered by the GNU Library
00018  * General Public License.
00019  * 
00020  * This library is distributed in the hope that it will be useful,
00021  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00023  * Lesser General Public License for more details.
00024  * 
00025  * You should have received a copy of the GNU Lesser General Public
00026  * License along with this library; if not, write to the Free Software
00027  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00028  */
00029 #ifndef cxxtools_SourceInfo_h
00030 #define cxxtools_SourceInfo_h
00031 
00032 #include <string>
00033 
00034 // GNU C++ compiler
00035 #ifdef __GNUC__
00036     #define CXXTOOLS_FUNCTION __PRETTY_FUNCTION__
00037 // Borland C++
00038 #elif defined(__BORLANDC__)
00039     #define CXXTOOLS_FUNCTION __FUNC__
00040 // Microsoft C++ compiler
00041 #elif defined(_MSC_VER)
00042     // .NET 2003 support's demangled function names
00043     #if _MSC_VER >= 1300
00044         #define CXXTOOLS_FUNCTION __FUNCDNAME__
00045     #else
00046         #define CXXTOOLS_FUNCTION __FUNCTION__
00047     #endif
00048 // otherwise use standard macro
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 } // namespace cxxtools
00142 
00143 #endif
Copyright © 2008 The Tntnet Development Team
Tntnet 1.6