File indexing completed on 2024-09-27 07:03:38
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 #ifndef REPORTINGUTILS_H
0036 #define REPORTINGUTILS_H
0037
0038
0039 #include <iostream>
0040 #include <iomanip>
0041 #include <string>
0042 #include <vector>
0043
0044
0045
0046
0047
0048
0049 inline
0050 std::string
0051 getClassMethod__(std::string prettyFunction)
0052 {
0053 size_t pos = prettyFunction.find("(");
0054 if (pos == std::string::npos)
0055 return prettyFunction;
0056 prettyFunction.erase(pos);
0057 pos = prettyFunction.rfind(" ");
0058 if (pos == std::string::npos)
0059 return prettyFunction;
0060 prettyFunction.erase(0, pos + 1);
0061 return prettyFunction;
0062 }
0063
0064 #define printErr std::cerr << "!!! " << __PRETTY_FUNCTION__ << " [" << __FILE__ << ":" << __LINE__ << "]: ERROR: " << std::flush
0065 #define printWarn std::cerr << ">>> " << __PRETTY_FUNCTION__ << " [" << __FILE__ << ":" << __LINE__ << "]: "<<std::endl<<"Warning: " << std::flush
0066 #define printInfo std::cout << ">>> " << getClassMethod__(__PRETTY_FUNCTION__) << "(): Info: " << std::flush
0067
0068
0069
0070
0071
0072 #ifndef SVN_VERSION
0073 #define SVN_VERSION "undefined"
0074 #endif
0075 inline std::string svnVersion() { return SVN_VERSION; }
0076
0077 inline
0078 void
0079 printSvnVersion()
0080 {
0081 const std::string ver = svnVersion();
0082 if (ver == "")
0083 printInfo << "subversion repository revision is unknown." << std::endl;
0084 else
0085 printInfo << "subversion repository revision is '" << ver << "'" << std::endl;
0086 }
0087
0088
0089 #ifndef CMAKE_SOURCE_DIR
0090 #define CMAKE_SOURCE_DIR "undefined"
0091 #endif
0092 inline std::string compileDir() { return CMAKE_SOURCE_DIR; }
0093
0094 inline
0095 void
0096 printCompilerInfo()
0097 {
0098 const std::string date = __DATE__;
0099 const std::string time = __TIME__;
0100 const std::string ver = __VERSION__;
0101 const std::string dir = compileDir();
0102 printInfo << "this executable was compiled in ";
0103 if (dir != "")
0104 std::cout << "'" << dir << "'";
0105 else
0106 std::cout << "unknown directory";
0107 std::cout << " on " << date << " " << time << " by compiler " << ver << std::endl;
0108 }
0109
0110
0111
0112
0113
0114 template<typename T1, typename T2>
0115 inline
0116 std::ostream&
0117 operator << (std::ostream& out,
0118 const std::pair<T1, T2>& pair)
0119 {
0120 return out << "(" << pair.first << ", " << pair.second << ")";
0121 }
0122
0123
0124 template<typename T>
0125 inline
0126 std::ostream&
0127 operator << (std::ostream& out,
0128 const std::vector<T>& vec)
0129 {
0130 out << "{";
0131 for (unsigned int i = 0; i < (vec.size() - 1); ++i)
0132 out << "[" << i << "] = " << vec[i] << ", ";
0133 return out << "[" << vec.size() - 1 << "] = " << vec[vec.size() - 1] << "}";
0134 }
0135
0136
0137
0138
0139 inline
0140 std::ostream&
0141 progressIndicator(const unsigned int currentPos,
0142 const unsigned int nmbTotal,
0143 const bool absolute = false,
0144 const unsigned int fieldWidth = 3,
0145 const unsigned int nmbSteps = 10,
0146 std::ostream& out = std::cout)
0147 {
0148 const double step = nmbTotal / (double)nmbSteps;
0149 if ((int)(currentPos / step) - (int)((currentPos - 1) / step) != 0) {
0150 if (absolute)
0151 out << " " << std::setw(fieldWidth) << currentPos << " of " << nmbTotal << std::endl;
0152 else
0153 out << " " << std::setw(fieldWidth) << (int)(currentPos / step) * nmbSteps << " %" << std::endl;
0154 }
0155 return out;
0156 }
0157
0158
0159
0160 inline
0161 std::string trueFalse(const bool val)
0162 {
0163 if (val)
0164 return "true";
0165 else
0166 return "false";
0167 }
0168
0169
0170 inline
0171 std::string yesNo(const bool val)
0172 {
0173 if (val)
0174 return "yes";
0175 else
0176 return "no";
0177 }
0178
0179
0180 inline
0181 std::string onOff(const bool val)
0182 {
0183 if (val)
0184 return "on";
0185 else
0186 return "off";
0187 }
0188
0189
0190 inline
0191 std::string enDisabled(const bool val)
0192 {
0193 if (val)
0194 return "enabled";
0195 else
0196 return "disabled";
0197 }
0198
0199
0200 #endif