1 ///////////////////////////////////////////////////////////////////////////
5 // This file is part of starlight.
7 // starlight is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
12 // starlight is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with starlight. If not, see <http://www.gnu.org/licenses/>.
20 ///////////////////////////////////////////////////////////////////////////
22 // File and Version Information:
23 // $Rev:: $: revision of last commit
24 // $Author:: $: author of last commit
25 // $Date:: $: date of last commit
28 // some simple streams for reporting plus some stream operators
29 // for common STL classes
32 ///////////////////////////////////////////////////////////////////////////
35 #ifndef REPORTINGUTILS_H
36 #define REPORTINGUTILS_H
45 //////////////////////////////////////////////////////////////////////////////
46 // macros for printing errors, warnings, and infos
48 // cuts out block "className::methodName" from __PRETTY_FUNCTION__ output
51 getClassMethod__(std::string prettyFunction)
53 size_t pos = prettyFunction.find("(");
54 if (pos == std::string::npos)
55 return prettyFunction; // something is not right
56 prettyFunction.erase(pos); // cut away signature
57 pos = prettyFunction.rfind(" ");
58 if (pos == std::string::npos)
59 return prettyFunction; // something is not right
60 prettyFunction.erase(0, pos + 1); // cut away return type
61 return prettyFunction;
64 #define printErr std::cerr << "!!! " << __PRETTY_FUNCTION__ << " [" << __FILE__ << ":" << __LINE__ << "]: error: " << std::flush
65 #define printWarn std::cerr << "??? " << __PRETTY_FUNCTION__ << " [" << __FILE__ << ":" << __LINE__ << "]: warning: " << std::flush
66 #define printInfo std::cout << ">>> " << getClassMethod__(__PRETTY_FUNCTION__) << "(): info: " << std::flush
69 //////////////////////////////////////////////////////////////////////////////
70 // functions to print version and compilation info
72 #ifndef SVN_VERSION // SVN_VERSION set by Makefile
73 #define SVN_VERSION "undefined"
75 inline std::string svnVersion() { return SVN_VERSION; }
81 const std::string ver = svnVersion();
83 printInfo << "subversion repository revision is unknown." << std::endl;
85 printInfo << "subversion repository revision is '" << ver << "'" << std::endl;
89 #ifndef CMAKE_SOURCE_DIR // CMAKE_SOURCE_DIR set by Makefile
90 #define CMAKE_SOURCE_DIR "undefined"
92 inline std::string compileDir() { return CMAKE_SOURCE_DIR; }
98 const std::string date = __DATE__;
99 const std::string time = __TIME__;
100 const std::string ver = __VERSION__;
101 const std::string dir = compileDir();
102 printInfo << "this executable was compiled in ";
104 std::cout << "'" << dir << "'";
106 std::cout << "unknown directory";
107 std::cout << " on " << date << " " << time << " by compiler " << ver << std::endl;
111 //////////////////////////////////////////////////////////////////////////////
112 // simple stream operators for some STL classes
114 template<typename T1, typename T2>
117 operator << (std::ostream& out,
118 const std::pair<T1, T2>& pair)
120 return out << "(" << pair.first << ", " << pair.second << ")";
127 operator << (std::ostream& out,
128 const std::vector<T>& vec)
131 for (unsigned int i = 0; i < (vec.size() - 1); ++i)
132 out << "[" << i << "] = " << vec[i] << ", ";
133 return out << "[" << vec.size() - 1 << "] = " << vec[vec.size() - 1] << "}";
137 //////////////////////////////////////////////////////////////////////////////
140 // indicates progess by printing relative or absolute progress in regular intervals
143 progressIndicator(const unsigned int currentPos,
144 const unsigned int nmbTotal,
145 const bool absolute = false,
146 const unsigned int fieldWidth = 3,
147 const unsigned int nmbSteps = 10,
148 std::ostream& out = std::cout)
150 const double step = nmbTotal / (double)nmbSteps;
151 if ((int)(currentPos / step) - (int)((currentPos - 1) / step) != 0) {
153 out << " " << std::setw(fieldWidth) << currentPos << " of " << nmbTotal << std::endl;
155 out << " " << std::setw(fieldWidth) << (int)(currentPos / step) * nmbSteps << " %" << std::endl;
161 // converts bool to "true"/"false" string
163 std::string trueFalse(const bool val)
171 // converts bool to "yes"/"no" string
173 std::string yesNo(const bool val)
181 // converts bool to "on"/"off" string
183 std::string onOff(const bool val)
191 // converts bool to "enabled"/"disabled" string
193 std::string enDisabled(const bool val)
202 #endif // REPORTINGUTILS_H