| 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 | */ |
| 20 | /** @file |
| 21 | * |
| 22 | * @copyright © Copyright 2007-2008 by Intra2net AG |
| 23 | */ |
| 24 | |
| 25 | #include "source_track_basics.hpp" |
| 26 | |
| 27 | #include <list> |
| 28 | #include <containerfunc.hpp> |
| 29 | #include <stringfunc.hxx> |
| 30 | #include <filefunc.hxx> |
| 31 | |
| 32 | |
| 33 | namespace I2n |
| 34 | { |
| 35 | |
| 36 | /* |
| 37 | ** implementation of SourceLocation |
| 38 | */ |
| 39 | |
| 40 | SourceLocation::SourceLocation() |
| 41 | : Line ( 0 ) |
| 42 | { |
| 43 | } // eo SourceLocation::SourceLocation() |
| 44 | |
| 45 | |
| 46 | SourceLocation::SourceLocation ( |
| 47 | const std::string& file, |
| 48 | long line, |
| 49 | const std::string& funcname |
| 50 | ) |
| 51 | : File( file ) |
| 52 | , Line( line ) |
| 53 | , FunctionName( funcname ) |
| 54 | { |
| 55 | } // eo SourceLocation::SourceLocation(const std::string&,long,const std::string&) |
| 56 | |
| 57 | |
| 58 | /** |
| 59 | * @brief returns a "location tag"; i.e. a string which can be used to identify |
| 60 | * the source location. |
| 61 | * @return the location tag. |
| 62 | */ |
| 63 | std::string SourceLocation::get_location_tag() const |
| 64 | { |
| 65 | static std::list< std::string > suffixes= TransientPushBackFiller< std::string, std::list >() |
| 66 | ( ".cpp" ) ( ".cxx" ) ( ".cc" ) ( ".C" ) ( ".c++" ) |
| 67 | ( ".hpp" ) ( ".hxx" ) ( ".hh" ) ( ".H" ) ( ".h++" ) ( ".h" ) |
| 68 | ; |
| 69 | if ( LocationTag.empty() and not File.empty() ) |
| 70 | { |
| 71 | std::string str= basename( File ); |
| 72 | for( std::list< std::string >::const_iterator it= suffixes.begin(); |
| 73 | it != suffixes.end(); |
| 74 | ++it ) |
| 75 | { |
| 76 | if ( has_suffix(str,*it) ) |
| 77 | { |
| 78 | str= remove_suffix(str,*it); |
| 79 | break; |
| 80 | } |
| 81 | } |
| 82 | LocationTag= str; |
| 83 | LocationTag+= "#"; |
| 84 | LocationTag+= to_string( Line ); |
| 85 | } |
| 86 | return LocationTag; |
| 87 | } // eo SourceLocation::get_location_tag() |
| 88 | |
| 89 | |
| 90 | |
| 91 | } // eo namespace I2n |