ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/utils/FileLocation.hpp
Revision: 1501
Committed: Wed Sep 15 19:32:10 2010 UTC (14 years, 7 months ago) by gezelter
File size: 3580 byte(s)
Log Message:
Starting migration of Morse to C++

File Contents

# Content
1 /*******************************************************************\
2
3 Copyright (C) 2003 Joseph Coffland
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18 02111-1307, USA.
19
20 For information regarding this software email
21 jcofflan@users.sourceforge.net
22
23 \*******************************************************************/
24
25
26 #ifndef UTILS_FILELOCATION_H
27 #define UTILS_FILELOCATION_H
28
29 #include <string>
30
31 namespace OpenMD {
32
33 /**
34 * This class is mainly used by Exception, but can be used
35 * as a general class for recording a line and column location
36 * with in a file.
37 */
38 class FileLocation {
39 std::string filename;
40 std::string function;
41 long line;
42 long col;
43 bool empty;
44
45 public:
46 /**
47 * Construct a default FileLocation with an empty value.
48 */
49 FileLocation() : line(-1), col(-1), empty(true) {}
50
51 /**
52 * Copy constructor.
53 */
54 FileLocation(const FileLocation &x) :
55 filename(x.filename), function(x.function), line(x.line), col(x.col),
56 empty(x.empty) {}
57
58 /**
59 * @param filename The name of the file.
60 * @param line The line with that file.
61 * @param col The column on that line.
62 */
63 FileLocation(const std::string filename, const long line,
64 const long col) :
65 filename(filename), line(line), col(col), empty(false) {}
66
67 FileLocation(const std::string filename, const std::string function,
68 const long line, const long col) :
69 filename(filename), function(function), line(line), col(col),
70 empty(false) {}
71
72 virtual ~FileLocation() {}
73
74 const std::string getFilename() const {return filename;}
75
76 const std::string getFunction() const {return function;}
77
78 /**
79 * @return -1 if no line was set the line number otherwise.
80 */
81 const long getLine() const {return line;}
82
83 /**
84 * @return -1 of no column was set the column number otherwise.
85 */
86 const long getCol() const {return col;}
87
88 /**
89 * @return True of no filename, line, or column have been set.
90 */
91 bool isEmpty() const {return empty;}
92
93 friend std::ostream &operator<<(std::ostream &stream,
94 const FileLocation &fl);
95 };
96
97 /**
98 * Print a file location to a stream. The format is as follows.
99 *
100 * filename[:line[:col]]
101 *
102 * If no line or column has been set then they will not be displayed.
103 *
104 * @return A reference to the passed stream.
105 */
106 std::ostream &operator<<(std::ostream &stream, const FileLocation &fl);
107 }
108
109 #if defined(__STDC__)
110 # if __STDC_VERSION__ < 199901L
111 # if __GNUC__ >= 2
112 # define __func__ __FUNCTION__
113 # else
114 # define __func__ "<unknown>"
115 # endif
116 # endif
117 #endif
118
119 #ifndef FILE_LOCATION
120 #define FILE_LOCATION OpenMD::FileLocation(__FILE__, __func__, __LINE__, -1)
121 #endif
122
123 #endif