diff --git a/BaseLib/CMakeLists.txt b/BaseLib/CMakeLists.txt index c1b597236010f8fd97e535d0574a5407806bd21d..7ff7e6df19f5801e66eea0ffbbd43f2c0a0ed8bb 100644 --- a/BaseLib/CMakeLists.txt +++ b/BaseLib/CMakeLists.txt @@ -7,8 +7,8 @@ GET_SOURCE_FILES(SOURCES_IO_BASE_XML IO/XmlIO) set(SOURCES ${SOURCES} ${SOURCES_IO_BASE_XML}) if(QT4_FOUND) - GET_SOURCE_FILES(SOURCES_IO_QT_XML IO/XmlIO/Qt) - set(SOURCES ${SOURCES} ${SOURCES_IO_QT_XML}) + GET_SOURCE_FILES(SOURCES_IO_QT_XML IO/XmlIO/Qt) + set(SOURCES ${SOURCES} ${SOURCES_IO_QT_XML}) endif() list(APPEND SOURCES "${CMAKE_CURRENT_BINARY_DIR}/BuildInfo.cpp" BuildInfo.h) @@ -19,23 +19,23 @@ add_library(BaseLib ${SOURCES}) set_target_properties(BaseLib PROPERTIES LINKER_LANGUAGE CXX) target_link_libraries(BaseLib - logog + logog ) if(MSVC) - target_link_libraries(BaseLib WinMM) # needed for timeGetTime + target_link_libraries(BaseLib WinMM) # needed for timeGetTime endif() if(QT4_FOUND) - target_link_libraries(BaseLib Qt4::QtXml Qt4::QtXmlPatterns) - if(WIN32 AND CMAKE_CROSSCOMPILING AND OPENSSL_FOUND) - target_link_libraries(BaseLib Qt4::QtNetwork ${OPENSSL_LIBRARIES} ws2_32) - endif() + target_link_libraries(BaseLib Qt4::QtXml Qt4::QtXmlPatterns) + if(WIN32 AND CMAKE_CROSSCOMPILING AND OPENSSL_FOUND) + target_link_libraries(BaseLib Qt4::QtNetwork ${OPENSSL_LIBRARIES} ws2_32) + endif() endif() if(TARGET Eigen) - add_dependencies(BaseLib Eigen) + add_dependencies(BaseLib Eigen) endif() if(TARGET Boost) - add_dependencies(BaseLib Boost) + add_dependencies(BaseLib Boost) endif() diff --git a/BaseLib/Counter.h b/BaseLib/Counter.h index 44ffd84f7818e930700b45cc43b22505b60eb067..20d1c02ab6d715de0e61f2ffd9a5d99936cd4374 100644 --- a/BaseLib/Counter.h +++ b/BaseLib/Counter.h @@ -17,11 +17,11 @@ namespace BaseLib template <typename X> struct Counter { - Counter() - { - _counter_value++; - } - static std::size_t _counter_value; + Counter() + { + _counter_value++; + } + static std::size_t _counter_value; }; template <typename X> std::size_t Counter<X>::_counter_value(0); diff --git a/BaseLib/DateTools.cpp b/BaseLib/DateTools.cpp index e4a769a394578fc6bed4dafac53b0c7cde06201d..14624941badde4efb6dde4871a6353c04dacc7db 100644 --- a/BaseLib/DateTools.cpp +++ b/BaseLib/DateTools.cpp @@ -26,94 +26,94 @@ namespace BaseLib { int date2int(int y, int m, int d) { - if ( (y < 1000 || y > 9999) || (m < 1 || m > 12) || (d < 1 || d > 31) ) - { - WARN("date2int(): Input not in expected range."); - return 0; - } + if ( (y < 1000 || y > 9999) || (m < 1 || m > 12) || (d < 1 || d > 31) ) + { + WARN("date2int(): Input not in expected range."); + return 0; + } - int ddate(0); - ddate = y * 10000; - ddate += (m * 100); - ddate += d; + int ddate(0); + ddate = y * 10000; + ddate += (m * 100); + ddate += d; - return ddate; + return ddate; } std::string int2date(int date) { - if (date > 10000000 && date < 22000000) - { - int y = static_cast<int>(std::floor(date / 10000.0)); - int m = static_cast<int>(std::floor((date - (y * 10000)) / 100.0)); - int d = date - (y * 10000) - (m * 100); - std::stringstream ss; - if (d < 10) - ss << "0"; - ss << d << "."; - if (m < 10) - ss << "0"; - ss << m << "." << y; - return ss.str(); - } - return ""; + if (date > 10000000 && date < 22000000) + { + int y = static_cast<int>(std::floor(date / 10000.0)); + int m = static_cast<int>(std::floor((date - (y * 10000)) / 100.0)); + int d = date - (y * 10000) - (m * 100); + std::stringstream ss; + if (d < 10) + ss << "0"; + ss << d << "."; + if (m < 10) + ss << "0"; + ss << m << "." << y; + return ss.str(); + } + return ""; } std::string date2string(double ddate) { - if (ddate < 10000101 || ddate > 99991231) - { - WARN("date2String(): Input not in expected format."); - return "0.0.0000"; - } + if (ddate < 10000101 || ddate > 99991231) + { + WARN("date2String(): Input not in expected format."); + return "0.0.0000"; + } - int rest (static_cast<int>(ddate)); - int y = static_cast<int>(std::floor(rest / 10000.0)); - rest = rest % (y * 10000); - int m = static_cast<int>(std::floor(rest / 100.0)); - if (m < 1 || m > 12) - WARN("date2String(): month not in [1:12]."); - rest = rest % (m * 100); - int d = rest; - if (d < 1 || d > 31) - WARN("date2String(): day not in [1:31]."); + int rest (static_cast<int>(ddate)); + int y = static_cast<int>(std::floor(rest / 10000.0)); + rest = rest % (y * 10000); + int m = static_cast<int>(std::floor(rest / 100.0)); + if (m < 1 || m > 12) + WARN("date2String(): month not in [1:12]."); + rest = rest % (m * 100); + int d = rest; + if (d < 1 || d > 31) + WARN("date2String(): day not in [1:31]."); - std::string day = std::to_string(d); - if (d < 10) - day = "0" + day; - std::string month = std::to_string(m); - if (m < 10) - month = "0" + month; - std::string s = std::to_string(y) + "-" + month + "-" + day; - return s; + std::string day = std::to_string(d); + if (d < 10) + day = "0" + day; + std::string month = std::to_string(m); + if (m < 10) + month = "0" + month; + std::string s = std::to_string(y) + "-" + month + "-" + day; + return s; } int strDate2int(const std::string &s) { - std::string str(s); - if (s.length() > 10) - str = s.substr(0,10); - std::size_t sep ( str.find(".",0) ); - int d ( atoi(str.substr(0, sep).c_str()) ); - std::size_t sep2 ( str.find(".", sep + 1) ); - int m ( atoi(str.substr(sep + 1,sep2 - (sep + 1)).c_str()) ); - int y ( atoi(str.substr(sep2 + 1, s.length() - (sep2 + 1)).c_str()) ); - return date2int(y, m, d); + std::string str(s); + if (s.length() > 10) + str = s.substr(0,10); + std::size_t sep ( str.find(".",0) ); + int d ( atoi(str.substr(0, sep).c_str()) ); + std::size_t sep2 ( str.find(".", sep + 1) ); + int m ( atoi(str.substr(sep + 1,sep2 - (sep + 1)).c_str()) ); + int y ( atoi(str.substr(sep2 + 1, s.length() - (sep2 + 1)).c_str()) ); + return date2int(y, m, d); } int xmlDate2int(const std::string &s) { - if (s.length() == 10) - { - int d = atoi(s.substr(8,2).c_str()); - if (d < 1 || d > 31) - WARN("xmlDate2double(): day not in [1:31]."); - int m = atoi(s.substr(5,2).c_str()); - if (m < 1 || m > 12) - WARN("xmlDate2double(): month not in [1:12]."); - int y = atoi(s.substr(0,4).c_str()); - return date2int(y, m, d); - } - return 0; + if (s.length() == 10) + { + int d = atoi(s.substr(8,2).c_str()); + if (d < 1 || d > 31) + WARN("xmlDate2double(): day not in [1:31]."); + int m = atoi(s.substr(5,2).c_str()); + if (m < 1 || m > 12) + WARN("xmlDate2double(): month not in [1:12]."); + int y = atoi(s.substr(0,4).c_str()); + return date2int(y, m, d); + } + return 0; } } // end namespace BaseLib diff --git a/BaseLib/FileFinder.h b/BaseLib/FileFinder.h index 47688da36f371deceb64a49e4c02fb0bdccc75a6..f26e62d3c35ba5b493594f9e4184123f6cf693c9 100644 --- a/BaseLib/FileFinder.h +++ b/BaseLib/FileFinder.h @@ -32,54 +32,54 @@ namespace BaseLib class FileFinder { public: - /// Constructor - FileFinder() - { - addDirectory("."); - addDirectory(BuildInfo::source_path + "/FileIO"); - } + /// Constructor + FileFinder() + { + addDirectory("."); + addDirectory(BuildInfo::source_path + "/FileIO"); + } - /** - * \brief Adds another directory to the search-space. - * If the given directory does not end with a slash one will be appended. - */ - void addDirectory(std::string const& dir) - { - if (dir.empty()) - return; + /** + * \brief Adds another directory to the search-space. + * If the given directory does not end with a slash one will be appended. + */ + void addDirectory(std::string const& dir) + { + if (dir.empty()) + return; - if (dir[dir.size() - 1] != '/') - _directories.push_back(std::string(dir + "/")); - else - _directories.push_back(dir); - } + if (dir[dir.size() - 1] != '/') + _directories.push_back(std::string(dir + "/")); + else + _directories.push_back(dir); + } - /** - * Given a filename, this method will return the complete path where this file can be found. - * If the file is located in more than one of the directories in the search list, only the - * first location will be returned. - */ - std::string getPath(std::string const& filename) const - { - if (_directories.empty()) - ERR("FileFinder::getPath(): No directories set."); + /** + * Given a filename, this method will return the complete path where this file can be found. + * If the file is located in more than one of the directories in the search list, only the + * first location will be returned. + */ + std::string getPath(std::string const& filename) const + { + if (_directories.empty()) + ERR("FileFinder::getPath(): No directories set."); - for (auto it = _directories.begin(); it != _directories.end(); ++it) - { - std::string testDir(*it); - std::ifstream is(testDir.append(filename).c_str()); - if (is.good()) - { - is.close(); - return testDir; - } - } - ERR("FileFinder::getPath(): File not found."); - return filename; - } + for (auto it = _directories.begin(); it != _directories.end(); ++it) + { + std::string testDir(*it); + std::ifstream is(testDir.append(filename).c_str()); + if (is.good()) + { + is.close(); + return testDir; + } + } + ERR("FileFinder::getPath(): File not found."); + return filename; + } private: - std::vector<std::string> _directories; + std::vector<std::string> _directories; }; } // end namespace BaseLib diff --git a/BaseLib/FileTools.cpp b/BaseLib/FileTools.cpp index 484e5283189719b13d8c19a6be236014b0295830..a21b7d8d457003499c8213a64729ed0bd2b61be4 100644 --- a/BaseLib/FileTools.cpp +++ b/BaseLib/FileTools.cpp @@ -25,26 +25,26 @@ namespace BaseLib */ bool IsFileExisting(const std::string &strFilename) { - struct stat buffer; - return (stat (strFilename.c_str(), &buffer) == 0); + struct stat buffer; + return (stat (strFilename.c_str(), &buffer) == 0); } double swapEndianness(double const& v) { - union - { - double v; - char c[sizeof(double)]; - } a, b; + union + { + double v; + char c[sizeof(double)]; + } a, b; - a.v = v; - for (unsigned short i = 0; i < sizeof(double)/2; i++) - b.c[i] = a.c[sizeof(double)/2 - i - 1]; + a.v = v; + for (unsigned short i = 0; i < sizeof(double)/2; i++) + b.c[i] = a.c[sizeof(double)/2 - i - 1]; - for (unsigned short i = sizeof(double)/2; i < sizeof(double); i++) - b.c[i] = a.c[sizeof(double)+sizeof(double)/2 - i - 1]; + for (unsigned short i = sizeof(double)/2; i < sizeof(double); i++) + b.c[i] = a.c[sizeof(double)+sizeof(double)/2 - i - 1]; - return b.v; + return b.v; } /** @@ -52,8 +52,8 @@ double swapEndianness(double const& v) */ void truncateFile( std::string const& filename) { - std::ofstream ofs(filename.c_str(), std::ios_base::trunc); - ofs.close(); + std::ofstream ofs(filename.c_str(), std::ios_base::trunc); + ofs.close(); } namespace @@ -67,7 +67,7 @@ namespace static std::string::size_type findLastPathSeparator(std::string const& path) { - return path.find_last_of("/\\"); + return path.find_last_of("/\\"); } /** Finds the position of last dot. @@ -76,70 +76,70 @@ std::string::size_type findLastPathSeparator(std::string const& path) static std::string::size_type findLastDot(std::string const& path) { - return path.find_last_of("."); + return path.find_last_of("."); } } // end namespace std::string dropFileExtension(std::string const& filename) { - // Look for dots in filename. - auto const p = findLastDot(filename); - if (p == std::string::npos) - return filename; + // Look for dots in filename. + auto const p = findLastDot(filename); + if (p == std::string::npos) + return filename; - // Check position of the last path separator. - auto const s = findLastPathSeparator(filename); - if (s != std::string::npos && p < s) - return filename; + // Check position of the last path separator. + auto const s = findLastPathSeparator(filename); + if (s != std::string::npos && p < s) + return filename; - return filename.substr(0, p); + return filename.substr(0, p); } std::string extractBaseName(std::string const& pathname) { - auto const p = findLastPathSeparator(pathname); - if (p == std::string::npos) - return pathname; - return pathname.substr(p + 1); + auto const p = findLastPathSeparator(pathname); + if (p == std::string::npos) + return pathname; + return pathname.substr(p + 1); } std::string extractBaseNameWithoutExtension(std::string const& pathname) { - std::string basename = extractBaseName(pathname); - return dropFileExtension(basename); + std::string basename = extractBaseName(pathname); + return dropFileExtension(basename); } std::string getFileExtension(const std::string &path) { - const std::string str = extractBaseName(path); - auto const p = findLastDot(str); - if (p == std::string::npos) - return std::string(); - return str.substr(p + 1); + const std::string str = extractBaseName(path); + auto const p = findLastDot(str); + if (p == std::string::npos) + return std::string(); + return str.substr(p + 1); } bool hasFileExtension(std::string const& extension, std::string const& filename) { - return boost::iequals(extension, getFileExtension(filename)); + return boost::iequals(extension, getFileExtension(filename)); } std::string copyPathToFileName(const std::string &file_name, const std::string &source) { - // check if file_name already contains a full path - auto const pos = findLastPathSeparator(file_name); - if (pos != std::string::npos) - return file_name; + // check if file_name already contains a full path + auto const pos = findLastPathSeparator(file_name); + if (pos != std::string::npos) + return file_name; - return BaseLib::extractPath(source).append(file_name); + return BaseLib::extractPath(source).append(file_name); } std::string extractPath(std::string const& pathname) { - auto const pos = findLastPathSeparator(pathname); - if (pos == std::string::npos) - return ""; - return pathname.substr(0, pos + 1); + auto const pos = findLastPathSeparator(pathname); + if (pos == std::string::npos) + return ""; + return pathname.substr(0, pos + 1); } const char * pathSeparator = #ifdef _WIN32 @@ -150,19 +150,19 @@ const char * pathSeparator = std::string appendPathSeparator(std::string const& path) { - if(findLastPathSeparator(path) == path.length() - 1) - return path; - return path + pathSeparator; + if(findLastPathSeparator(path) == path.length() - 1) + return path; + return path + pathSeparator; } std::string joinPaths(std::string const& pathA, std::string const& pathB) { - std::string tmpB(pathB); - if(tmpB.substr(0, 1) == ".") - tmpB = tmpB.substr(1); - if(tmpB.substr(0, 1) == pathSeparator) - tmpB = tmpB.substr(1); - return appendPathSeparator(pathA) + tmpB; + std::string tmpB(pathB); + if(tmpB.substr(0, 1) == ".") + tmpB = tmpB.substr(1); + if(tmpB.substr(0, 1) == pathSeparator) + tmpB = tmpB.substr(1); + return appendPathSeparator(pathA) + tmpB; } } // end namespace BaseLib diff --git a/BaseLib/FileTools.h b/BaseLib/FileTools.h index a24f8aa25629668dbc78677e67940bb749ca52b5..51bba4ea836e36b91bd463e2db4f30b33089b81e 100644 --- a/BaseLib/FileTools.h +++ b/BaseLib/FileTools.h @@ -40,23 +40,23 @@ bool IsFileExisting(const std::string &strFilename); */ template <typename T> void writeValueBinary(std::ostream &out, T const& val) { - out.write(static_cast<const char*>(&val), sizeof(T)); + out.write(static_cast<const char*>(&val), sizeof(T)); } template <typename T> T swapEndianness(T const& v) { - union - { - T v; - char c[sizeof(T)]; - } a, b; + union + { + T v; + char c[sizeof(T)]; + } a, b; - a.v = v; - for (unsigned short i = 0; i < sizeof(T); i++) - b.c[i] = a.c[sizeof(T) - i - 1]; + a.v = v; + for (unsigned short i = 0; i < sizeof(T); i++) + b.c[i] = a.c[sizeof(T) - i - 1]; - return b.v; + return b.v; } double swapEndianness(double const& v); @@ -65,38 +65,38 @@ double swapEndianness(double const& v); template <typename T> T readBinaryValue(std::istream& in) { - T v; - in.read(reinterpret_cast<char*>(&v), sizeof(T)); - return v; + T v; + in.read(reinterpret_cast<char*>(&v), sizeof(T)); + return v; } template <typename T> std::vector<T> readBinaryArray(std::string const& filename, std::size_t const n) { - std::ifstream in(filename.c_str()); - if (!in) { - ERR("readBinaryArray(): Error while reading from file \"%s\".", filename.c_str()); - ERR("Could not open file \"%s\" for input.", filename.c_str()); - in.close(); - return std::vector<T>(); - } + std::ifstream in(filename.c_str()); + if (!in) { + ERR("readBinaryArray(): Error while reading from file \"%s\".", filename.c_str()); + ERR("Could not open file \"%s\" for input.", filename.c_str()); + in.close(); + return std::vector<T>(); + } - std::vector<T> result; - result.reserve(n); + std::vector<T> result; + result.reserve(n); - for (std::size_t p = 0; in && !in.eof() && p < n; ++p) - result.push_back(BaseLib::readBinaryValue<T>(in)); + for (std::size_t p = 0; in && !in.eof() && p < n; ++p) + result.push_back(BaseLib::readBinaryValue<T>(in)); - if (result.size() == n) - return result; + if (result.size() == n) + return result; - ERR("readBinaryArray(): Error while reading from file \"%s\".", filename.c_str()); - ERR("Read different number of values. Expected %d, got %d.", n, result.size()); + ERR("readBinaryArray(): Error while reading from file \"%s\".", filename.c_str()); + ERR("Read different number of values. Expected %d, got %d.", n, result.size()); - if (!in.eof()) - ERR("EOF reached.\n"); + if (!in.eof()) + ERR("EOF reached.\n"); - return std::vector<T>(); + return std::vector<T>(); } /** diff --git a/BaseLib/Histogram.h b/BaseLib/Histogram.h index cfdad1e6b9e1a7f745938dd0d00c31c703558511..de8a7edb7bec7a50e6735691e04c251426d80651 100644 --- a/BaseLib/Histogram.h +++ b/BaseLib/Histogram.h @@ -34,149 +34,149 @@ template <typename T> class Histogram { public: - typedef typename std::vector<T> Data; /// Underlying input data vector type. + typedef typename std::vector<T> Data; /// Underlying input data vector type. public: - /** Creates histogram of the given element in the range \c [first, last). - * - * Input data is copied into \c std::vector. - * - * \param data Range of elements to create histogram from. - * \param nr_bins Number of bins in histogram. - * \param computeHistogram Compute histogram if set. If not set user must - * call \c update() before accessing data. - */ - template <typename InputIterator> - Histogram(InputIterator first, InputIterator last, const int nr_bins = 16, - const bool computeHistogram = true ) - : _data(first, last), _nr_bins(nr_bins) - { - init(computeHistogram); - } - - /** Creates histogram from \c std::vector. - * \param data Input vector. - * \param nr_bins Number of bins in histogram. - * \param computeHistogram Compute histogram if set. If not set user must call - * \c update() before accessing data. - */ - Histogram(std::vector<T> const& data, const unsigned int nr_bins = 16, - const bool computeHistogram = true) - : _data(data), _nr_bins(nr_bins) - { - init(computeHistogram); - } - - /** Updates histogram using sorted \c _data vector. - * - * Start histogram creation with first element. Then find first element in - * the next histogram bin. Number of elments in the bin is the difference - * between these two iterators. - * \verbatim - [0.1, 0.2, ..., 0.7 , ..., 0.7+binWidth = 0.9, 1.0 , ..., last] - it itEnd - 1 itEnd - \endverbatim - */ - void update() - { - if (!_dirty) - return; - - _bin_width = (_max - _min) / _nr_bins; - - typedef typename Data::const_iterator DataCI; - DataCI it = _data.begin(); - DataCI itEnd; - for (unsigned int bin = 0; bin < _nr_bins; bin++) - { - itEnd = std::upper_bound(it, (DataCI)_data.end(), - _min + (bin + 1) * _bin_width); - _histogram[bin] = std::distance(it, itEnd); - it = itEnd; - } - _dirty = false; - } - - void setMinimum(const T& minimum) { _min = minimum; _dirty = true; } - void setMaximum(const T& maximum) { _max = maximum; _dirty = true; } - - const Data& getSortedData() const { return _data; } - const std::vector<std::size_t>& getBinCounts() const { return _histogram; } - const unsigned int& getNrBins() const { return _nr_bins; } - const T& getMinimum() const { return _min; } - const T& getMaximum() const { return _max; } - const T& getBinWidth() const { return _bin_width; } - - void - prettyPrint(std::ostream& os, const unsigned int line_width = 16) const - { - const std::size_t count_max = - *std::max_element(_histogram.begin(), _histogram.end()); - for (unsigned int bin = 0; bin < _nr_bins; ++bin) - { - os << "[" << _min + bin * _bin_width << ", " << _min + - (bin + 1) * _bin_width << ")\t"; - os << _histogram[bin] << "\t"; - - const int n_stars = - std::ceil(line_width * ((double)_histogram[bin] / count_max)); - for (int star = 0; star < n_stars; star++) - os << "*"; - os << "\n"; - } - } - - int write(std::string const& file_name, std::string const& data_set_name, std::string const& param_name) const - { - if (file_name.empty()) - { - ERR ("No file name specified."); - return 1; - } - - std::ofstream out (file_name); - if (!out) - { - ERR("Error writing histogram: Could not open file."); - return 1; - } - - out << "# Histogram for parameter " << param_name << " of data set " << data_set_name << "\n"; - std::size_t const n_bins = this->getNrBins(); - std::vector<std::size_t> const& bin_cnts(this->getBinCounts()); - double const min (this->getMinimum()); - double const bin_width (this->getBinWidth()); - - for (std::size_t k(0); k < n_bins; k++) - out << min+k*bin_width << " " << bin_cnts[k] << "\n"; - out.close (); - return 0; - } + /** Creates histogram of the given element in the range \c [first, last). + * + * Input data is copied into \c std::vector. + * + * \param data Range of elements to create histogram from. + * \param nr_bins Number of bins in histogram. + * \param computeHistogram Compute histogram if set. If not set user must + * call \c update() before accessing data. + */ + template <typename InputIterator> + Histogram(InputIterator first, InputIterator last, const int nr_bins = 16, + const bool computeHistogram = true ) + : _data(first, last), _nr_bins(nr_bins) + { + init(computeHistogram); + } + + /** Creates histogram from \c std::vector. + * \param data Input vector. + * \param nr_bins Number of bins in histogram. + * \param computeHistogram Compute histogram if set. If not set user must call + * \c update() before accessing data. + */ + Histogram(std::vector<T> const& data, const unsigned int nr_bins = 16, + const bool computeHistogram = true) + : _data(data), _nr_bins(nr_bins) + { + init(computeHistogram); + } + + /** Updates histogram using sorted \c _data vector. + * + * Start histogram creation with first element. Then find first element in + * the next histogram bin. Number of elments in the bin is the difference + * between these two iterators. + * \verbatim + [0.1, 0.2, ..., 0.7 , ..., 0.7+binWidth = 0.9, 1.0 , ..., last] + it itEnd - 1 itEnd + \endverbatim + */ + void update() + { + if (!_dirty) + return; + + _bin_width = (_max - _min) / _nr_bins; + + typedef typename Data::const_iterator DataCI; + DataCI it = _data.begin(); + DataCI itEnd; + for (unsigned int bin = 0; bin < _nr_bins; bin++) + { + itEnd = std::upper_bound(it, (DataCI)_data.end(), + _min + (bin + 1) * _bin_width); + _histogram[bin] = std::distance(it, itEnd); + it = itEnd; + } + _dirty = false; + } + + void setMinimum(const T& minimum) { _min = minimum; _dirty = true; } + void setMaximum(const T& maximum) { _max = maximum; _dirty = true; } + + const Data& getSortedData() const { return _data; } + const std::vector<std::size_t>& getBinCounts() const { return _histogram; } + const unsigned int& getNrBins() const { return _nr_bins; } + const T& getMinimum() const { return _min; } + const T& getMaximum() const { return _max; } + const T& getBinWidth() const { return _bin_width; } + + void + prettyPrint(std::ostream& os, const unsigned int line_width = 16) const + { + const std::size_t count_max = + *std::max_element(_histogram.begin(), _histogram.end()); + for (unsigned int bin = 0; bin < _nr_bins; ++bin) + { + os << "[" << _min + bin * _bin_width << ", " << _min + + (bin + 1) * _bin_width << ")\t"; + os << _histogram[bin] << "\t"; + + const int n_stars = + std::ceil(line_width * ((double)_histogram[bin] / count_max)); + for (int star = 0; star < n_stars; star++) + os << "*"; + os << "\n"; + } + } + + int write(std::string const& file_name, std::string const& data_set_name, std::string const& param_name) const + { + if (file_name.empty()) + { + ERR ("No file name specified."); + return 1; + } + + std::ofstream out (file_name); + if (!out) + { + ERR("Error writing histogram: Could not open file."); + return 1; + } + + out << "# Histogram for parameter " << param_name << " of data set " << data_set_name << "\n"; + std::size_t const n_bins = this->getNrBins(); + std::vector<std::size_t> const& bin_cnts(this->getBinCounts()); + double const min (this->getMinimum()); + double const bin_width (this->getBinWidth()); + + for (std::size_t k(0); k < n_bins; k++) + out << min+k*bin_width << " " << bin_cnts[k] << "\n"; + out.close (); + return 0; + } protected: - /** Initialize class members after constructor call. - */ - void init(const bool computeHistogram = true) - { - std::sort(_data.begin(), _data.end()); - _histogram.resize(_nr_bins); - _min = _data.front(); - _max = _data.back(); - _bin_width = (_max - _min) / _nr_bins; - - _dirty = true; - if (computeHistogram) - update(); - } - - Data _data; - const unsigned int _nr_bins; - std::vector<std::size_t> _histogram; - T _min, _max; ///< Minimum and maximum input data values. - T _bin_width; + /** Initialize class members after constructor call. + */ + void init(const bool computeHistogram = true) + { + std::sort(_data.begin(), _data.end()); + _histogram.resize(_nr_bins); + _min = _data.front(); + _max = _data.back(); + _bin_width = (_max - _min) / _nr_bins; + + _dirty = true; + if (computeHistogram) + update(); + } + + Data _data; + const unsigned int _nr_bins; + std::vector<std::size_t> _histogram; + T _min, _max; ///< Minimum and maximum input data values. + T _bin_width; private: - bool _dirty; ///< When set \c update() will recompute histogram. + bool _dirty; ///< When set \c update() will recompute histogram. }; /** Writes histogram to output stream. @@ -188,12 +188,12 @@ template <typename T> std::ostream& operator<<(std::ostream& os, const Histogram<T>& h) { - os << h.getNrBins() << " " - << h.getMinimum() << " " - << h.getMaximum() << " "; - std::copy(h.getBinCounts().begin(), h.getBinCounts().end(), - std::ostream_iterator<T>(os, " ")); - return os << std::endl; + os << h.getNrBins() << " " + << h.getMinimum() << " " + << h.getMaximum() << " "; + std::copy(h.getBinCounts().begin(), h.getBinCounts().end(), + std::ostream_iterator<T>(os, " ")); + return os << std::endl; } } // namespace BaseLib diff --git a/BaseLib/IO/Writer.cpp b/BaseLib/IO/Writer.cpp index 9ae1fe21c3b358003d1521834ece36e152675e55..a4abbaa2d756fdfd2563d9b87cbaaac33d41606d 100644 --- a/BaseLib/IO/Writer.cpp +++ b/BaseLib/IO/Writer.cpp @@ -26,52 +26,52 @@ namespace IO Writer::Writer() { - _out.precision(std::numeric_limits<double>::digits10); + _out.precision(std::numeric_limits<double>::digits10); } std::string Writer::writeToString() { - // Empty stream and clear error states. - _out.str(""); - _out.clear(); + // Empty stream and clear error states. + _out.str(""); + _out.clear(); - if (this->write()) - return _out.str(); - else - return std::string(""); + if (this->write()) + return _out.str(); + else + return std::string(""); } int Writer::writeToFile(std::string const& filename) { - std::string file_content = this->writeToString(); - if (!file_content.empty()) - { - std::ofstream fileStream; - fileStream.open (filename.c_str()); + std::string file_content = this->writeToString(); + if (!file_content.empty()) + { + std::ofstream fileStream; + fileStream.open (filename.c_str()); - // check file stream - if (!fileStream) - { - std::cerr << "Could not open file " << filename << " !\n"; - return 0; - } + // check file stream + if (!fileStream) + { + std::cerr << "Could not open file " << filename << " !\n"; + return 0; + } - fileStream << file_content; + fileStream << file_content; - fileStream.close(); - return 1; - } - return 0; + fileStream.close(); + return 1; + } + return 0; } void Writer::setPrecision(unsigned int precision) { - _out.precision(precision); + _out.precision(precision); } void Writer::setFormat(std::ios_base::fmtflags flags) { - _out.setf(flags); + _out.setf(flags); } } // namespace IO diff --git a/BaseLib/IO/Writer.h b/BaseLib/IO/Writer.h index 2a6652391205107a1b9a9fffea2d7dd02a2148d8..b2a5481dcb9c155f6f6867b0b2f269b270b5e2c7 100644 --- a/BaseLib/IO/Writer.h +++ b/BaseLib/IO/Writer.h @@ -32,29 +32,29 @@ namespace IO class Writer { public: - Writer(); - virtual ~Writer() {} + Writer(); + virtual ~Writer() {} - /// @brief Writes the object to a string. - std::string writeToString(); + /// @brief Writes the object to a string. + std::string writeToString(); - /// @brief Writes the object to the given file. - int writeToFile(std::string const& filename); + /// @brief Writes the object to the given file. + int writeToFile(std::string const& filename); - /// @brief Sets the decimal precision. - void setPrecision(unsigned int precision); + /// @brief Sets the decimal precision. + void setPrecision(unsigned int precision); - /// @brief Sets the format (either ios::scientific or ios::fixed); - void setFormat(std::ios_base::fmtflags flags); + /// @brief Sets the format (either ios::scientific or ios::fixed); + void setFormat(std::ios_base::fmtflags flags); protected: - /// @brief Writes the object to the internal stream. - /// This method must be implemented by a subclass. - /// The implementation should return true on success, else false - virtual bool write() = 0; + /// @brief Writes the object to the internal stream. + /// This method must be implemented by a subclass. + /// The implementation should return true on success, else false + virtual bool write() = 0; - /// @brief The stream to write to. - std::stringstream _out; + /// @brief The stream to write to. + std::stringstream _out; private: diff --git a/BaseLib/IO/XmlIO/Qt/XMLQtInterface.cpp b/BaseLib/IO/XmlIO/Qt/XMLQtInterface.cpp index 57374b0d5bae558c7f74fc219782d832e4db5d38..295cd8eb46c55d8a48fa6924b03b9f866248b99f 100644 --- a/BaseLib/IO/XmlIO/Qt/XMLQtInterface.cpp +++ b/BaseLib/IO/XmlIO/Qt/XMLQtInterface.cpp @@ -30,118 +30,118 @@ namespace IO { XMLQtInterface::XMLQtInterface(const std::string &schemaFile) : - _schemaName(schemaFile) + _schemaName(schemaFile) {} int XMLQtInterface::readFile(const QString &fileName) { - _fileName = fileName; - QFile file(fileName); - if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) - { - ERR("XMLQtInterface::readFile(): Can't open xml-file %s.", fileName.toStdString().c_str()); - return 0; - } - _fileData = file.readAll(); - file.close(); - - if (!checkHash()) - return 0; - - return 1; + _fileName = fileName; + QFile file(fileName); + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) + { + ERR("XMLQtInterface::readFile(): Can't open xml-file %s.", fileName.toStdString().c_str()); + return 0; + } + _fileData = file.readAll(); + file.close(); + + if (!checkHash()) + return 0; + + return 1; } int XMLQtInterface::isValid() const { - QXmlSchema schema; - if(_schemaName.length() > 0) - schema.load( QUrl::fromLocalFile((QString::fromStdString(_schemaName))) ); - - if ( schema.isValid() ) - { - QXmlSchemaValidator validator( schema ); - if ( validator.validate( _fileData ) ) - return 1; - else - { - INFO("XMLQtInterface::isValid(): XML file %s is invalid (in reference to schema %s).", - _fileName.toStdString().c_str(), _schemaName.c_str()); - } - } - else - { - // The following validator (without constructor arguments) automatically - // searches for the xsd given in the xml file. - QXmlSchemaValidator validator; - if ( validator.validate( _fileData ) ) - return 1; - else - { - INFO("XMLQtInterface::isValid(): XML file %s is invalid (in reference to its schema).", - _fileName.toStdString().c_str()); - } - } - return 0; + QXmlSchema schema; + if(_schemaName.length() > 0) + schema.load( QUrl::fromLocalFile((QString::fromStdString(_schemaName))) ); + + if ( schema.isValid() ) + { + QXmlSchemaValidator validator( schema ); + if ( validator.validate( _fileData ) ) + return 1; + else + { + INFO("XMLQtInterface::isValid(): XML file %s is invalid (in reference to schema %s).", + _fileName.toStdString().c_str(), _schemaName.c_str()); + } + } + else + { + // The following validator (without constructor arguments) automatically + // searches for the xsd given in the xml file. + QXmlSchemaValidator validator; + if ( validator.validate( _fileData ) ) + return 1; + else + { + INFO("XMLQtInterface::isValid(): XML file %s is invalid (in reference to its schema).", + _fileName.toStdString().c_str()); + } + } + return 0; } int XMLQtInterface::insertStyleFileDefinition(const QString &fileName) const { - std::string path = fileName.toStdString(); - std::fstream stream(path.c_str()); - std::string styleDef("\n<?xml-stylesheet type=\"text/xsl\" href=\"OpenGeoSysGLI.xsl\"?>"); - - if (!stream.is_open()) - { - WARN("XMLQtInterface::insertStyleFileDefinition(): Could not open file %s.", - path.c_str()); - return 0; - } - - stream.seekp(43 * sizeof(char),std::ios_base::beg); // go to the correct position in the stream - stream.write(styleDef.c_str(), 60 * sizeof(char)); // write new line with xml-stylesheet definition - stream.close(); - return 1; + std::string path = fileName.toStdString(); + std::fstream stream(path.c_str()); + std::string styleDef("\n<?xml-stylesheet type=\"text/xsl\" href=\"OpenGeoSysGLI.xsl\"?>"); + + if (!stream.is_open()) + { + WARN("XMLQtInterface::insertStyleFileDefinition(): Could not open file %s.", + path.c_str()); + return 0; + } + + stream.seekp(43 * sizeof(char),std::ios_base::beg); // go to the correct position in the stream + stream.write(styleDef.c_str(), 60 * sizeof(char)); // write new line with xml-stylesheet definition + stream.close(); + return 1; } bool XMLQtInterface::checkHash() const { - QString md5FileName(_fileName + ".md5"); - QByteArray fileHash = QCryptographicHash::hash(_fileData, QCryptographicHash::Md5); - - QFile file(md5FileName); - if (file.open(QIODevice::ReadOnly)) - { - QByteArray referenceHash = file.readAll(); - file.close(); - if(referenceHash == fileHash) - return true; - INFO("Hashfile does not match data ... checking file ..."); - } - - if (!this->isValid()) - return false; - - QFile fileMD5(md5FileName); - if(fileMD5.open(QIODevice::WriteOnly)) - { - fileMD5.write(fileHash); - fileMD5.close(); - INFO("File is valid, hashfile written."); - } - else - WARN("File is valid but could not write hashfile!"); - return true; + QString md5FileName(_fileName + ".md5"); + QByteArray fileHash = QCryptographicHash::hash(_fileData, QCryptographicHash::Md5); + + QFile file(md5FileName); + if (file.open(QIODevice::ReadOnly)) + { + QByteArray referenceHash = file.readAll(); + file.close(); + if(referenceHash == fileHash) + return true; + INFO("Hashfile does not match data ... checking file ..."); + } + + if (!this->isValid()) + return false; + + QFile fileMD5(md5FileName); + if(fileMD5.open(QIODevice::WriteOnly)) + { + fileMD5.write(fileHash); + fileMD5.close(); + INFO("File is valid, hashfile written."); + } + else + WARN("File is valid but could not write hashfile!"); + return true; } bool XMLQtInterface::isHashGood(const QByteArray &hash) const { - QByteArray fileHash = QCryptographicHash::hash(_fileData, QCryptographicHash::Md5); - if(hash != fileHash) - { - INFO("Hashfile does not match data ... checking file ..."); - return false; - } - return true; + QByteArray fileHash = QCryptographicHash::hash(_fileData, QCryptographicHash::Md5); + if(hash != fileHash) + { + INFO("Hashfile does not match data ... checking file ..."); + return false; + } + return true; } } // end namespace IO diff --git a/BaseLib/IO/XmlIO/Qt/XMLQtInterface.h b/BaseLib/IO/XmlIO/Qt/XMLQtInterface.h index fb52d5131a5b8a9d192f82b54e00b2522eaa9594..95a66a12e2909563d8372dc415281fbfb4ed425f 100644 --- a/BaseLib/IO/XmlIO/Qt/XMLQtInterface.h +++ b/BaseLib/IO/XmlIO/Qt/XMLQtInterface.h @@ -31,35 +31,35 @@ namespace IO class XMLQtInterface { public: - XMLQtInterface(const std::string &schemaFile = ""); - virtual ~XMLQtInterface() {} + XMLQtInterface(const std::string &schemaFile = ""); + virtual ~XMLQtInterface() {} - /// As QXMLStreamWriter seems currently unable to include style-file links into xml-files, this method will workaround this issue and include the stylefile link. - int insertStyleFileDefinition(const QString &fileName) const; + /// As QXMLStreamWriter seems currently unable to include style-file links into xml-files, this method will workaround this issue and include the stylefile link. + int insertStyleFileDefinition(const QString &fileName) const; - /// Reads the file. In an overriden function in the child class be sure to call - /// XMLQtInterface::readFile(fileName). - virtual int readFile(const QString &fileName); + /// Reads the file. In an overriden function in the child class be sure to call + /// XMLQtInterface::readFile(fileName). + virtual int readFile(const QString &fileName); protected: - /// Check if the given xml-file is valid considering the schema-file used in the constructor - int isValid() const; + /// Check if the given xml-file is valid considering the schema-file used in the constructor + int isValid() const; - /// Checks if a hash for the given data file exists to skip the time-consuming validation part. - /// If a hash file exists _and_ the hash of the data file is the same as the content of the hash file the validation is skipped - /// If no hash file exists, the xml-file is validated and a hash file is written if the xml-file was valid. - bool checkHash() const; + /// Checks if a hash for the given data file exists to skip the time-consuming validation part. + /// If a hash file exists _and_ the hash of the data file is the same as the content of the hash file the validation is skipped + /// If no hash file exists, the xml-file is validated and a hash file is written if the xml-file was valid. + bool checkHash() const; - /// Checks if the given file is conform to the given hash. - bool isHashGood(const QByteArray &hash) const; + /// Checks if the given file is conform to the given hash. + bool isHashGood(const QByteArray &hash) const; - std::string _schemaName; + std::string _schemaName; - /// Caches the actual file contents when reading. - QByteArray _fileData; + /// Caches the actual file contents when reading. + QByteArray _fileData; - /// The actual file name when reading. - QString _fileName; + /// The actual file name when reading. + QString _fileName; }; } // end namespace IO diff --git a/BaseLib/IO/XmlIO/XMLInterface.cpp b/BaseLib/IO/XmlIO/XMLInterface.cpp index 85f1d83fd09fb4083cc6e3d9ce42deec3b0f68c0..05d05e3aab266fb54f8fd9df75cac935f3df3ef6 100644 --- a/BaseLib/IO/XmlIO/XMLInterface.cpp +++ b/BaseLib/IO/XmlIO/XMLInterface.cpp @@ -20,7 +20,7 @@ namespace IO { XMLInterface::XMLInterface() : - _exportName("") + _exportName("") {} } diff --git a/BaseLib/IO/XmlIO/XMLInterface.h b/BaseLib/IO/XmlIO/XMLInterface.h index fabd4f7fb6d9edfaf4f13ffb33dd15d0bd38338e..891f001d2f2224746a1f4a7f67e15374d1c9ec34 100644 --- a/BaseLib/IO/XmlIO/XMLInterface.h +++ b/BaseLib/IO/XmlIO/XMLInterface.h @@ -29,14 +29,14 @@ namespace IO class XMLInterface : public BaseLib::IO::Writer { public: - XMLInterface(); - virtual ~XMLInterface() {} + XMLInterface(); + virtual ~XMLInterface() {} - void setNameForExport(std::string const& name) { _exportName = name; } - virtual bool readFile(std::string const& fname) = 0; + void setNameForExport(std::string const& name) { _exportName = name; } + virtual bool readFile(std::string const& fname) = 0; protected: - std::string _exportName; + std::string _exportName; }; } diff --git a/BaseLib/LogogCustomCout.h b/BaseLib/LogogCustomCout.h index b1a4172d34163e4820ceca5d4747fceaf9ff42c8..a386d85c523547c77861a6609b44c82892a52844 100644 --- a/BaseLib/LogogCustomCout.h +++ b/BaseLib/LogogCustomCout.h @@ -26,43 +26,43 @@ class LogogCustomCout : public logog::Target { public: #ifdef USE_MPI - /** - * Constructor when MPI is involved - * - * @param all_rank_output_level Minimum level to output messages from all MPI processes - * @param mpi_comm MPI communicator - */ - LogogCustomCout(LOGOG_LEVEL_TYPE all_rank_output_level = LOGOG_LEVEL_INFO, MPI_Comm mpi_comm = MPI_COMM_WORLD) - : _all_rank_output_level(all_rank_output_level), _is_rank0 (getRank(mpi_comm)==0) - {} + /** + * Constructor when MPI is involved + * + * @param all_rank_output_level Minimum level to output messages from all MPI processes + * @param mpi_comm MPI communicator + */ + LogogCustomCout(LOGOG_LEVEL_TYPE all_rank_output_level = LOGOG_LEVEL_INFO, MPI_Comm mpi_comm = MPI_COMM_WORLD) + : _all_rank_output_level(all_rank_output_level), _is_rank0 (getRank(mpi_comm)==0) + {} #endif - virtual int Receive( const logog::Topic &topic ) - { + virtual int Receive( const logog::Topic &topic ) + { #ifdef USE_MPI - if (topic.Level() > _all_rank_output_level && !_is_rank0) - return 0; + if (topic.Level() > _all_rank_output_level && !_is_rank0) + return 0; #endif - return logog::Target::Receive(topic); - } + return logog::Target::Receive(topic); + } - virtual int Output( const LOGOG_STRING &data ) - { - LOGOG_COUT << (const LOGOG_CHAR *)data << std::flush; - return 0; - } + virtual int Output( const LOGOG_STRING &data ) + { + LOGOG_COUT << (const LOGOG_CHAR *)data << std::flush; + return 0; + } private: #ifdef USE_MPI - int getRank(MPI_Comm mpi_comm) const - { - int rank = 0; - MPI_Comm_rank(mpi_comm, &rank); - return rank; - } + int getRank(MPI_Comm mpi_comm) const + { + int rank = 0; + MPI_Comm_rank(mpi_comm, &rank); + return rank; + } - const LOGOG_LEVEL_TYPE _all_rank_output_level; - const bool _is_rank0; + const LOGOG_LEVEL_TYPE _all_rank_output_level; + const bool _is_rank0; #endif }; diff --git a/BaseLib/LogogSimpleFormatter.h b/BaseLib/LogogSimpleFormatter.h index 9e3fc26b3cceacccc01f17b4a0730db735c0dbe6..56a4e264a8534926cf644670924b2b727d41fa30 100644 --- a/BaseLib/LogogSimpleFormatter.h +++ b/BaseLib/LogogSimpleFormatter.h @@ -26,11 +26,11 @@ namespace BaseLib **/ class LogogSimpleFormatter : public logog::FormatterMSVC { - virtual TOPIC_FLAGS GetTopicFlags(const logog::Topic& topic) - { - return (logog::Formatter::GetTopicFlags(topic) & - ~(TOPIC_FILE_NAME_FLAG | TOPIC_LINE_NUMBER_FLAG)); - } + virtual TOPIC_FLAGS GetTopicFlags(const logog::Topic& topic) + { + return (logog::Formatter::GetTopicFlags(topic) & + ~(TOPIC_FILE_NAME_FLAG | TOPIC_LINE_NUMBER_FLAG)); + } }; } // namespace BaseLib diff --git a/BaseLib/MemWatch.h b/BaseLib/MemWatch.h index 2b827df7e80d7a20f526b3f57bf94b2bcd8eff68..843159a5fe0e100dda4cec97d100dd85dec059d2 100644 --- a/BaseLib/MemWatch.h +++ b/BaseLib/MemWatch.h @@ -19,18 +19,18 @@ namespace BaseLib { class MemWatch { public: - MemWatch (); - unsigned long getVirtMemUsage (); - unsigned long getResMemUsage (); - unsigned long getShrMemUsage (); - unsigned long getCodeMemUsage (); + MemWatch (); + unsigned long getVirtMemUsage (); + unsigned long getResMemUsage (); + unsigned long getShrMemUsage (); + unsigned long getCodeMemUsage (); private: - unsigned updateMemUsage (); - unsigned long _vmem_size = 0; - unsigned long _rmem_size = 0; - unsigned long _smem_size = 0; - unsigned long _cmem_size = 0; + unsigned updateMemUsage (); + unsigned long _vmem_size = 0; + unsigned long _rmem_size = 0; + unsigned long _smem_size = 0; + unsigned long _cmem_size = 0; }; } diff --git a/BaseLib/RangeValidator-impl.h b/BaseLib/RangeValidator-impl.h index 4e94f49ff45f5ad9a963d0b676e9b49c777abafc..e0cd83aa3b7b1ce4bced66933c2b89a306920ffe 100644 --- a/BaseLib/RangeValidator-impl.h +++ b/BaseLib/RangeValidator-impl.h @@ -16,7 +16,7 @@ namespace BaseLib { template <typename NUMERIC_TYPE> RangeValidator<NUMERIC_TYPE>::RangeValidator(NUMERIC_TYPE lower_limit, NUMERIC_TYPE upper_limit) : - _lower_limit(lower_limit), _upper_limit(upper_limit) + _lower_limit(lower_limit), _upper_limit(upper_limit) { } @@ -27,25 +27,25 @@ RangeValidator<NUMERIC_TYPE>::~RangeValidator() template <typename NUMERIC_TYPE> void RangeValidator<NUMERIC_TYPE>::resetLowerLimits(NUMERIC_TYPE lower_limit) { - _lower_limit = lower_limit; + _lower_limit = lower_limit; } template <typename NUMERIC_TYPE> void RangeValidator<NUMERIC_TYPE>:: resetUpperLimits(NUMERIC_TYPE upper_limit) { - _upper_limit = upper_limit; + _upper_limit = upper_limit; } template <typename NUMERIC_TYPE> bool RangeValidator<NUMERIC_TYPE>::isValidValue (NUMERIC_TYPE test_value) const { - if (test_value < _lower_limit) - return false; + if (test_value < _lower_limit) + return false; - if (_upper_limit < test_value) - return false; + if (_upper_limit < test_value) + return false; - return true; + return true; } } // end namespace BaseLib diff --git a/BaseLib/RangeValidator.h b/BaseLib/RangeValidator.h index b2ff13988e824e23d2e3f33d191c9f54c5d7092e..6b52da3763306e31a3318167f01212b5e9878f26 100644 --- a/BaseLib/RangeValidator.h +++ b/BaseLib/RangeValidator.h @@ -20,14 +20,14 @@ namespace BaseLib { template <typename NUMERIC_TYPE> class RangeValidator { public: - RangeValidator(NUMERIC_TYPE lower_limit, NUMERIC_TYPE upper_limit); - void resetLowerLimits(NUMERIC_TYPE lower_limit); - void resetUpperLimits(NUMERIC_TYPE upper_limit); - bool isValidValue (NUMERIC_TYPE test_value) const; - virtual ~RangeValidator(); + RangeValidator(NUMERIC_TYPE lower_limit, NUMERIC_TYPE upper_limit); + void resetLowerLimits(NUMERIC_TYPE lower_limit); + void resetUpperLimits(NUMERIC_TYPE upper_limit); + bool isValidValue (NUMERIC_TYPE test_value) const; + virtual ~RangeValidator(); private: - NUMERIC_TYPE _lower_limit; - NUMERIC_TYPE _upper_limit; + NUMERIC_TYPE _lower_limit; + NUMERIC_TYPE _upper_limit; }; } diff --git a/BaseLib/StringTools.cpp b/BaseLib/StringTools.cpp index 7a658c8b15527b0285cf47d90e1e9e8508d07697..88a0e721863d478bc4dc5557776103c4b8625cc2 100644 --- a/BaseLib/StringTools.cpp +++ b/BaseLib/StringTools.cpp @@ -26,55 +26,55 @@ namespace BaseLib { std::list<std::string> splitString(const std::string &str, char delim) { - std::list<std::string> strList; - std::stringstream ss(str); - std::string item; - while(getline(ss, item, delim)) - strList.push_back(item); - return strList; + std::list<std::string> strList; + std::stringstream ss(str); + std::string item; + while(getline(ss, item, delim)) + strList.push_back(item); + return strList; } std::string replaceString(const std::string &searchString, const std::string &replaceString, std::string stringToReplace) { - boost::replace_all(stringToReplace, searchString, replaceString); - return stringToReplace; + boost::replace_all(stringToReplace, searchString, replaceString); + return stringToReplace; } void trim(std::string &str, char ch) { - std::string::size_type pos = str.find_last_not_of(ch); - if(pos != std::string::npos) - { - str.erase(pos + 1); - pos = str.find_first_not_of(ch); - if(pos != std::string::npos) - str.erase(0, pos); - } - else - str.erase(str.begin(), str.end()); + std::string::size_type pos = str.find_last_not_of(ch); + if(pos != std::string::npos) + { + str.erase(pos + 1); + pos = str.find_first_not_of(ch); + if(pos != std::string::npos) + str.erase(0, pos); + } + else + str.erase(str.begin(), str.end()); } void simplify(std::string &str) { - trim (str); - str.erase( - std::unique(str.begin(), str.end(), [](char a, char b) { return a == ' ' && b == ' '; }), - str.end() - ); + trim (str); + str.erase( + std::unique(str.begin(), str.end(), [](char a, char b) { return a == ' ' && b == ' '; }), + str.end() + ); } std::string padLeft(std::string const& str, int maxlen, char ch) { - std::stringstream ss(str); - ss << std::right << std::setw(maxlen) << std::setfill(ch) << str; - return ss.str(); + std::stringstream ss(str); + ss << std::right << std::setw(maxlen) << std::setfill(ch) << str; + return ss.str(); } std::string const& tostring(std::string const& value) { - return value; + return value; } } // end namespace BaseLib @@ -82,62 +82,62 @@ std::string const& tostring(std::string const& value) #ifdef MSVC void correctScientificNotation(std::string filename, std::size_t precision) { - std::ifstream stream; - std::ofstream outputStream; - - stream.open(filename.c_str()); - std::string tmpFilename = filename + ".tmp"; - outputStream.open(tmpFilename.c_str()); - - if (!stream) - { - WARN("correctScientificNotation: fstream is not open."); - return; - } - - std::string line; - - // Iterate over lines in stream - while (getline(stream, line)) - { - std::string word; - std::istringstream iss(line); - // Iterate over all words in line - while (iss >> word) - { - // Search for e+0 - std::size_t exponentPosition = word.find("e+0", precision); - if (exponentPosition == std::string::npos) - // If not found search for e-0 - exponentPosition = word.find("e-0", precision); - if (exponentPosition != std::string::npos) - { - std::size_t wordSize = word.size(); - std::size_t exponentSize = wordSize - exponentPosition; - - if(exponentSize > 4) - { - // Erase the leading zero considering trailing characters - int i = wordSize - 1; - while (!isdigit(word[i])) - --i; - - std::size_t erasePos = wordSize - 3 - (wordSize - 1 - i); - std::string eraseString = word.substr(erasePos, 1); - if (eraseString.find("0") != std::string::npos) - word.erase(erasePos, 1); - } - } - - outputStream << word << " "; - } - outputStream << "\n"; - } - - stream.close(); - outputStream.close(); - - remove(filename.c_str()); - rename(tmpFilename.c_str(), filename.c_str()); + std::ifstream stream; + std::ofstream outputStream; + + stream.open(filename.c_str()); + std::string tmpFilename = filename + ".tmp"; + outputStream.open(tmpFilename.c_str()); + + if (!stream) + { + WARN("correctScientificNotation: fstream is not open."); + return; + } + + std::string line; + + // Iterate over lines in stream + while (getline(stream, line)) + { + std::string word; + std::istringstream iss(line); + // Iterate over all words in line + while (iss >> word) + { + // Search for e+0 + std::size_t exponentPosition = word.find("e+0", precision); + if (exponentPosition == std::string::npos) + // If not found search for e-0 + exponentPosition = word.find("e-0", precision); + if (exponentPosition != std::string::npos) + { + std::size_t wordSize = word.size(); + std::size_t exponentSize = wordSize - exponentPosition; + + if(exponentSize > 4) + { + // Erase the leading zero considering trailing characters + int i = wordSize - 1; + while (!isdigit(word[i])) + --i; + + std::size_t erasePos = wordSize - 3 - (wordSize - 1 - i); + std::string eraseString = word.substr(erasePos, 1); + if (eraseString.find("0") != std::string::npos) + word.erase(erasePos, 1); + } + } + + outputStream << word << " "; + } + outputStream << "\n"; + } + + stream.close(); + outputStream.close(); + + remove(filename.c_str()); + rename(tmpFilename.c_str(), filename.c_str()); } #endif diff --git a/BaseLib/StringTools.h b/BaseLib/StringTools.h index 413fa5168e6e935b157997aa8ed9c22a4d066b6c..8c3790269588ed753baed78fc174023ef75d6990 100644 --- a/BaseLib/StringTools.h +++ b/BaseLib/StringTools.h @@ -47,10 +47,10 @@ std::string replaceString(const std::string &searchString, const std::string &re */ template<typename T> T str2number (const std::string &str) { - std::stringstream strs (str, std::stringstream::in | std::stringstream::out); - T v; - strs >> v; - return v; + std::stringstream strs (str, std::stringstream::in | std::stringstream::out); + T v; + strs >> v; + return v; } /** @@ -74,7 +74,7 @@ std::string padLeft(std::string const& str, int maxlen, char ch=' '); //! Method for handling conversion to string uniformly across all types and std::string; see std::string overload below. template<typename T> std::string tostring(T const& value) { - return std::to_string(value); + return std::to_string(value); } //! \overload std::string const& tostring(std::string const& value); diff --git a/BaseLib/Subdivision.h b/BaseLib/Subdivision.h index eebb7d309f15724448dc7b4bd830c84cfbd3f031..b2ad90ac135a380e6aeaad0a6766a3ed67ad46b1 100644 --- a/BaseLib/Subdivision.h +++ b/BaseLib/Subdivision.h @@ -21,10 +21,10 @@ namespace BaseLib class ISubdivision { public: - /// Returns a vector of subdivided points - virtual std::vector<double> operator()() const = 0; + /// Returns a vector of subdivided points + virtual std::vector<double> operator()() const = 0; - virtual ~ISubdivision() {} + virtual ~ISubdivision() {} }; /** @@ -33,28 +33,28 @@ public: class UniformSubdivision : public ISubdivision { public: - /** - * Configuration - * @param length total length to be subdivided - * @param n_subdivision the number of subdivision - */ - UniformSubdivision(double length, std::size_t n_subdivision) - : _length(length), _n_subdivision(n_subdivision) {} + /** + * Configuration + * @param length total length to be subdivided + * @param n_subdivision the number of subdivision + */ + UniformSubdivision(double length, std::size_t n_subdivision) + : _length(length), _n_subdivision(n_subdivision) {} - /// Returns a vector of subdivided points - std::vector<double> operator()() const - { - std::vector<double> x; - x.reserve(_n_subdivision+1); - const double dL = _length/static_cast<double>(_n_subdivision); - for (std::size_t i=0; i<_n_subdivision+1; i++) - x.push_back(i*dL); - return x; - } + /// Returns a vector of subdivided points + std::vector<double> operator()() const + { + std::vector<double> x; + x.reserve(_n_subdivision+1); + const double dL = _length/static_cast<double>(_n_subdivision); + for (std::size_t i=0; i<_n_subdivision+1; i++) + x.push_back(i*dL); + return x; + } private: - const double _length; - const std::size_t _n_subdivision; + const double _length; + const std::size_t _n_subdivision; }; /** @@ -63,48 +63,48 @@ private: class GradualSubdivision : public ISubdivision { public: - /** - * Constructor - * @param L total length to be subdivided - * @param dL0 initial cell length - * @param max_dL maximum cell length - * @param multiplier multiplier to cell length - */ - GradualSubdivision( - const double L, - const double dL0, - const double max_dL, - const double multiplier) - : _L(L), _dL0(dL0), _max_dL(max_dL), _multiplier(multiplier) {} + /** + * Constructor + * @param L total length to be subdivided + * @param dL0 initial cell length + * @param max_dL maximum cell length + * @param multiplier multiplier to cell length + */ + GradualSubdivision( + const double L, + const double dL0, + const double max_dL, + const double multiplier) + : _L(L), _dL0(dL0), _max_dL(max_dL), _multiplier(multiplier) {} - /// Returns a vector of subdivided points - std::vector<double> operator()() const - { - std::vector<double> vec_x; + /// Returns a vector of subdivided points + std::vector<double> operator()() const + { + std::vector<double> vec_x; - double x = 0; - unsigned i=0; - do { - vec_x.push_back(x); - x += std::min(_max_dL, _dL0*std::pow(_multiplier, static_cast<double>(i))); - i++; - } while (x<_L); + double x = 0; + unsigned i=0; + do { + vec_x.push_back(x); + x += std::min(_max_dL, _dL0*std::pow(_multiplier, static_cast<double>(i))); + i++; + } while (x<_L); - if (vec_x.back() < _L) { - double last_dx = vec_x[vec_x.size()-1] - vec_x[vec_x.size()-2]; - if (_L-vec_x.back()<last_dx) - vec_x[vec_x.size()-1] = _L; - else - vec_x.push_back(_L); - } - return vec_x; - } + if (vec_x.back() < _L) { + double last_dx = vec_x[vec_x.size()-1] - vec_x[vec_x.size()-2]; + if (_L-vec_x.back()<last_dx) + vec_x[vec_x.size()-1] = _L; + else + vec_x.push_back(_L); + } + return vec_x; + } private: - const double _L; - const double _dL0; - const double _max_dL; - const double _multiplier; + const double _L; + const double _dL0; + const double _max_dL; + const double _multiplier; }; } // BaseLib diff --git a/BaseLib/TCLAPCustomOutput.h b/BaseLib/TCLAPCustomOutput.h index fa32a4628c041a173990de6ac825b5aba9d37548..974052445e82b0ac83a3c072be385c7b897c96c0 100644 --- a/BaseLib/TCLAPCustomOutput.h +++ b/BaseLib/TCLAPCustomOutput.h @@ -31,151 +31,151 @@ namespace BaseLib class TCLAPCustomOutput : public TCLAP::StdOutput { public: - /** - * Prints the usage to stdout. Can be overridden to - * produce alternative behavior. - * \param c - The CmdLine object the output is generated for. - */ - virtual void usage(TCLAP::CmdLineInterface& c); - - /** - * Prints (to stderr) an error message, short usage - * Can be overridden to produce alternative behavior. - * \param c - The CmdLine object the output is generated for. - * \param e - The ArgException that caused the failure. - */ - virtual void failure(TCLAP::CmdLineInterface& c, - TCLAP::ArgException& e ); + /** + * Prints the usage to stdout. Can be overridden to + * produce alternative behavior. + * \param c - The CmdLine object the output is generated for. + */ + virtual void usage(TCLAP::CmdLineInterface& c); + + /** + * Prints (to stderr) an error message, short usage + * Can be overridden to produce alternative behavior. + * \param c - The CmdLine object the output is generated for. + * \param e - The ArgException that caused the failure. + */ + virtual void failure(TCLAP::CmdLineInterface& c, + TCLAP::ArgException& e ); protected: - /** - * Writes a brief usage message with short args. - * \param c - The CmdLine object the output is generated for. - * \param os - The stream to write the message to. - */ - void _shortUsage( TCLAP::CmdLineInterface& c, std::ostream& os ) const; - - /** - * Writes a longer usage message with long and short args, - * provides descriptions and prints message. - * \param c - The CmdLine object the output is generated for. - * \param os - The stream to write the message to. - */ - void _longUsage( TCLAP::CmdLineInterface& c, std::ostream& os ) const; + /** + * Writes a brief usage message with short args. + * \param c - The CmdLine object the output is generated for. + * \param os - The stream to write the message to. + */ + void _shortUsage( TCLAP::CmdLineInterface& c, std::ostream& os ) const; + + /** + * Writes a longer usage message with long and short args, + * provides descriptions and prints message. + * \param c - The CmdLine object the output is generated for. + * \param os - The stream to write the message to. + */ + void _longUsage( TCLAP::CmdLineInterface& c, std::ostream& os ) const; }; inline void TCLAPCustomOutput::usage(TCLAP::CmdLineInterface& _cmd ) { - std::cout << std::endl << "USAGE: " << std::endl << std::endl; + std::cout << std::endl << "USAGE: " << std::endl << std::endl; - _shortUsage( _cmd, std::cout ); + _shortUsage( _cmd, std::cout ); - std::cout << std::endl << std::endl << "Where: " << std::endl << std::endl; + std::cout << std::endl << std::endl << "Where: " << std::endl << std::endl; - _longUsage( _cmd, std::cout ); + _longUsage( _cmd, std::cout ); - std::cout << std::endl; + std::cout << std::endl; } inline void TCLAPCustomOutput::failure( TCLAP::CmdLineInterface& _cmd, - TCLAP::ArgException& e ) + TCLAP::ArgException& e ) { - std::string progName = _cmd.getProgramName(); + std::string progName = _cmd.getProgramName(); - std::cerr << "PARSE ERROR: " << e.argId() << std::endl - << " " << e.error() << std::endl << std::endl; + std::cerr << "PARSE ERROR: " << e.argId() << std::endl + << " " << e.error() << std::endl << std::endl; - if ( _cmd.hasHelpAndVersion() ) - { - std::cerr << "Brief USAGE: " << std::endl; + if ( _cmd.hasHelpAndVersion() ) + { + std::cerr << "Brief USAGE: " << std::endl; - _shortUsage( _cmd, std::cerr ); + _shortUsage( _cmd, std::cerr ); - std::cerr << std::endl << "For complete USAGE and HELP type: " - << std::endl << " " << progName << " --help" - << std::endl << std::endl; - } - else - usage(_cmd); + std::cerr << std::endl << "For complete USAGE and HELP type: " + << std::endl << " " << progName << " --help" + << std::endl << std::endl; + } + else + usage(_cmd); - throw TCLAP::ExitException(1); + throw TCLAP::ExitException(1); } inline void TCLAPCustomOutput::_shortUsage( TCLAP::CmdLineInterface& _cmd, - std::ostream& os ) const + std::ostream& os ) const { - std::list<TCLAP::Arg*> argList = _cmd.getArgList(); - std::string progName = _cmd.getProgramName(); - TCLAP::XorHandler xorHandler = _cmd.getXorHandler(); - std::vector< std::vector<TCLAP::Arg*> > xorList = xorHandler.getXorList(); - - std::string s = progName + " "; - - // first the xor - for ( int i = 0; static_cast<unsigned int>(i) < xorList.size(); i++ ) - { - s += " {"; - for ( TCLAP::ArgVectorIterator it = xorList[i].begin(); - it != xorList[i].end(); it++ ) - s += (*it)->shortID() + "|"; - - s[s.length()-1] = '}'; - } - - // then the rest - for (auto it = argList.rbegin(); it != argList.rend(); ++it) // here modified - if ( !xorHandler.contains( (*it) ) ) - s += " " + (*it)->shortID(); - - // if the program name is too long, then adjust the second line offset - int secondLineOffset = static_cast<int>(progName.length()) + 2; - if ( secondLineOffset > 75/2 ) - secondLineOffset = static_cast<int>(75/2); - - spacePrint( os, s, 75, 3, secondLineOffset ); + std::list<TCLAP::Arg*> argList = _cmd.getArgList(); + std::string progName = _cmd.getProgramName(); + TCLAP::XorHandler xorHandler = _cmd.getXorHandler(); + std::vector< std::vector<TCLAP::Arg*> > xorList = xorHandler.getXorList(); + + std::string s = progName + " "; + + // first the xor + for ( int i = 0; static_cast<unsigned int>(i) < xorList.size(); i++ ) + { + s += " {"; + for ( TCLAP::ArgVectorIterator it = xorList[i].begin(); + it != xorList[i].end(); it++ ) + s += (*it)->shortID() + "|"; + + s[s.length()-1] = '}'; + } + + // then the rest + for (auto it = argList.rbegin(); it != argList.rend(); ++it) // here modified + if ( !xorHandler.contains( (*it) ) ) + s += " " + (*it)->shortID(); + + // if the program name is too long, then adjust the second line offset + int secondLineOffset = static_cast<int>(progName.length()) + 2; + if ( secondLineOffset > 75/2 ) + secondLineOffset = static_cast<int>(75/2); + + spacePrint( os, s, 75, 3, secondLineOffset ); } inline void TCLAPCustomOutput::_longUsage( TCLAP::CmdLineInterface& _cmd, - std::ostream& os ) const + std::ostream& os ) const { - std::list<TCLAP::Arg*> argList = _cmd.getArgList(); - std::string message = _cmd.getMessage(); - TCLAP::XorHandler xorHandler = _cmd.getXorHandler(); - std::vector< std::vector<TCLAP::Arg*> > xorList = xorHandler.getXorList(); - - // first the xor - for ( int i = 0; static_cast<unsigned int>(i) < xorList.size(); i++ ) - { - for ( TCLAP::ArgVectorIterator it = xorList[i].begin(); - it != xorList[i].end(); - it++ ) - { - this->spacePrint( os, (*it)->longID(), 75, 3, 3 ); - spacePrint( os, (*it)->getDescription(), 75, 5, 0 ); - - if ( it+1 != xorList[i].end() ) - spacePrint(os, "-- OR --", 75, 9, 0); - } - os << std::endl << std::endl; - } - - // then the rest - for (auto it = argList.rbegin(); it != argList.rend(); it++) // here modified - if ( !xorHandler.contains( (*it) ) ) - { - spacePrint( os, (*it)->longID(), 75, 3, 3 ); - spacePrint( os, (*it)->getDescription(), 75, 5, 0 ); - os << std::endl; - } - - os << std::endl; - - spacePrint( os, message, 75, 3, 0 ); + std::list<TCLAP::Arg*> argList = _cmd.getArgList(); + std::string message = _cmd.getMessage(); + TCLAP::XorHandler xorHandler = _cmd.getXorHandler(); + std::vector< std::vector<TCLAP::Arg*> > xorList = xorHandler.getXorList(); + + // first the xor + for ( int i = 0; static_cast<unsigned int>(i) < xorList.size(); i++ ) + { + for ( TCLAP::ArgVectorIterator it = xorList[i].begin(); + it != xorList[i].end(); + it++ ) + { + this->spacePrint( os, (*it)->longID(), 75, 3, 3 ); + spacePrint( os, (*it)->getDescription(), 75, 5, 0 ); + + if ( it+1 != xorList[i].end() ) + spacePrint(os, "-- OR --", 75, 9, 0); + } + os << std::endl << std::endl; + } + + // then the rest + for (auto it = argList.rbegin(); it != argList.rend(); it++) // here modified + if ( !xorHandler.contains( (*it) ) ) + { + spacePrint( os, (*it)->longID(), 75, 3, 3 ); + spacePrint( os, (*it)->getDescription(), 75, 5, 0 ); + os << std::endl; + } + + os << std::endl; + + spacePrint( os, message, 75, 3, 0 ); } } //namespace BaseLib diff --git a/BaseLib/TemplateLogogFormatterSuppressedGCC-impl.h b/BaseLib/TemplateLogogFormatterSuppressedGCC-impl.h index 1462482007c40f63cbc2b3f6dd7197404d3f6cb2..335355a27f795c043863ade3d7247146ff4973e0 100644 --- a/BaseLib/TemplateLogogFormatterSuppressedGCC-impl.h +++ b/BaseLib/TemplateLogogFormatterSuppressedGCC-impl.h @@ -14,12 +14,12 @@ template <int T_SUPPPRESS_TOPIC_FLAG> TemplateLogogFormatterSuppressedGCC<T_SUPPPRESS_TOPIC_FLAG> ::TemplateLogogFormatterSuppressedGCC(MPI_Comm mpi_comm) { - int rank = 0; - MPI_Comm_rank(mpi_comm, &rank); - int size = 0; - MPI_Comm_size(mpi_comm, &size); - int digits = size/10 + 1; - _str_mpi_rank = "rank " + padLeft(std::to_string(rank), digits) + "| "; + int rank = 0; + MPI_Comm_rank(mpi_comm, &rank); + int size = 0; + MPI_Comm_size(mpi_comm, &size); + int digits = size/10 + 1; + _str_mpi_rank = "rank " + padLeft(std::to_string(rank), digits) + "| "; } #endif @@ -28,61 +28,61 @@ LOGOG_STRING & TemplateLogogFormatterSuppressedGCC<T_SUPPPRESS_TOPIC_FLAG> ::Format( const logog::Topic &topic, const logog::Target &target ) { - TOPIC_FLAGS flags; - flags = GetTopicFlags( topic ); + TOPIC_FLAGS flags; + flags = GetTopicFlags( topic ); - m_sMessageBuffer.clear(); + m_sMessageBuffer.clear(); #ifdef USE_MPI - m_sMessageBuffer.append(_str_mpi_rank.c_str()); + m_sMessageBuffer.append(_str_mpi_rank.c_str()); #endif - if ( flags & TOPIC_FILE_NAME_FLAG ) - { - m_sMessageBuffer.append( topic.FileName() ); - m_sMessageBuffer.append( ':' ); - } - - if ( flags & TOPIC_LINE_NUMBER_FLAG ) - { - m_sIntBuffer.assign( topic.LineNumber() ); - m_sMessageBuffer.append( m_sIntBuffer ); - - m_sMessageBuffer.append( LOGOG_CONST_STRING(": ")); - } - - RenderTimeOfDay(); - - if ( flags & TOPIC_LEVEL_FLAG ) - { - m_sMessageBuffer.append( ErrorDescription( topic.Level())); - m_sMessageBuffer.append( LOGOG_CONST_STRING(": ")); - } - - if ( flags & TOPIC_GROUP_FLAG ) - { - m_sMessageBuffer.append( LOGOG_CONST_STRING("{") ); - m_sMessageBuffer.append( topic.Group() ); - m_sMessageBuffer.append( LOGOG_CONST_STRING("} ") ); - } - - if ( flags & TOPIC_CATEGORY_FLAG ) - { - m_sMessageBuffer.append( LOGOG_CONST_STRING("[")); - m_sMessageBuffer.append( topic.Category() ); - m_sMessageBuffer.append( LOGOG_CONST_STRING("] ")); - } - - if ( flags & TOPIC_MESSAGE_FLAG ) - { - m_sMessageBuffer.append( topic.Message() ); - m_sMessageBuffer.append( (LOGOG_CHAR)'\n' ); - } - - if ( target.GetNullTerminatesStrings() ) - m_sMessageBuffer.append( (LOGOG_CHAR)NULL ); - - return m_sMessageBuffer; + if ( flags & TOPIC_FILE_NAME_FLAG ) + { + m_sMessageBuffer.append( topic.FileName() ); + m_sMessageBuffer.append( ':' ); + } + + if ( flags & TOPIC_LINE_NUMBER_FLAG ) + { + m_sIntBuffer.assign( topic.LineNumber() ); + m_sMessageBuffer.append( m_sIntBuffer ); + + m_sMessageBuffer.append( LOGOG_CONST_STRING(": ")); + } + + RenderTimeOfDay(); + + if ( flags & TOPIC_LEVEL_FLAG ) + { + m_sMessageBuffer.append( ErrorDescription( topic.Level())); + m_sMessageBuffer.append( LOGOG_CONST_STRING(": ")); + } + + if ( flags & TOPIC_GROUP_FLAG ) + { + m_sMessageBuffer.append( LOGOG_CONST_STRING("{") ); + m_sMessageBuffer.append( topic.Group() ); + m_sMessageBuffer.append( LOGOG_CONST_STRING("} ") ); + } + + if ( flags & TOPIC_CATEGORY_FLAG ) + { + m_sMessageBuffer.append( LOGOG_CONST_STRING("[")); + m_sMessageBuffer.append( topic.Category() ); + m_sMessageBuffer.append( LOGOG_CONST_STRING("] ")); + } + + if ( flags & TOPIC_MESSAGE_FLAG ) + { + m_sMessageBuffer.append( topic.Message() ); + m_sMessageBuffer.append( (LOGOG_CHAR)'\n' ); + } + + if ( target.GetNullTerminatesStrings() ) + m_sMessageBuffer.append( (LOGOG_CHAR)NULL ); + + return m_sMessageBuffer; } } // namespace BaseLib diff --git a/BaseLib/TemplateLogogFormatterSuppressedGCC.h b/BaseLib/TemplateLogogFormatterSuppressedGCC.h index e304233775b77907d35c9346b4422c5bcde9e739..c9a45ffff8291595c211ef8edb2461d6a3bcec6a 100644 --- a/BaseLib/TemplateLogogFormatterSuppressedGCC.h +++ b/BaseLib/TemplateLogogFormatterSuppressedGCC.h @@ -36,20 +36,20 @@ class TemplateLogogFormatterSuppressedGCC : public logog::FormatterGCC { public: #ifdef USE_MPI - TemplateLogogFormatterSuppressedGCC(MPI_Comm mpi_comm = MPI_COMM_WORLD); + TemplateLogogFormatterSuppressedGCC(MPI_Comm mpi_comm = MPI_COMM_WORLD); #endif - virtual TOPIC_FLAGS GetTopicFlags( const logog::Topic &topic ) - { - return ( logog::Formatter::GetTopicFlags( topic ) & - ~( T_SUPPPRESS_TOPIC_FLAG )); - } + virtual TOPIC_FLAGS GetTopicFlags( const logog::Topic &topic ) + { + return ( logog::Formatter::GetTopicFlags( topic ) & + ~( T_SUPPPRESS_TOPIC_FLAG )); + } - virtual LOGOG_STRING &Format( const logog::Topic &topic, const logog::Target &target ); + virtual LOGOG_STRING &Format( const logog::Topic &topic, const logog::Target &target ); private: #ifdef USE_MPI - std::string _str_mpi_rank; + std::string _str_mpi_rank; #endif }; diff --git a/BaseLib/excludeObjectCopy.h b/BaseLib/excludeObjectCopy.h index 1baca53b8001f14f69a5567fd0ef2139b97dc65e..c3871e55b7ff9314c6910c2bda2e791725355dd9 100644 --- a/BaseLib/excludeObjectCopy.h +++ b/BaseLib/excludeObjectCopy.h @@ -27,36 +27,36 @@ namespace BaseLib /// @return vector that contains the copied objects template <typename T> std::vector<T> excludeObjectCopy(std::vector<T> const& src_vec, - std::vector<std::size_t> const& exclude_positions) + std::vector<std::size_t> const& exclude_positions) { - std::vector<T> dest_vec; - if (exclude_positions.empty()) { - dest_vec = src_vec; - return dest_vec; - } + std::vector<T> dest_vec; + if (exclude_positions.empty()) { + dest_vec = src_vec; + return dest_vec; + } - assert (exclude_positions.back() < src_vec.size()); + assert (exclude_positions.back() < src_vec.size()); - std::copy_n(src_vec.cbegin(), exclude_positions[0], std::back_inserter(dest_vec)); - for (std::size_t i=1; i<exclude_positions.size(); ++i) { - std::copy_n( - src_vec.cbegin()+exclude_positions[i-1]+1, - exclude_positions[i]-(exclude_positions[i-1]+1), - std::back_inserter(dest_vec) - ); - } - std::copy(src_vec.cbegin()+exclude_positions.back()+1, - src_vec.cend(), std::back_inserter(dest_vec)); + std::copy_n(src_vec.cbegin(), exclude_positions[0], std::back_inserter(dest_vec)); + for (std::size_t i=1; i<exclude_positions.size(); ++i) { + std::copy_n( + src_vec.cbegin()+exclude_positions[i-1]+1, + exclude_positions[i]-(exclude_positions[i-1]+1), + std::back_inserter(dest_vec) + ); + } + std::copy(src_vec.cbegin()+exclude_positions.back()+1, + src_vec.cend(), std::back_inserter(dest_vec)); - return dest_vec; + return dest_vec; } template <typename T> void excludeObjectCopy(std::vector<T> const& src_vec, - std::vector<std::size_t> const& exclude_positions, - std::vector<T> & dest_vec) + std::vector<std::size_t> const& exclude_positions, + std::vector<T> & dest_vec) { - dest_vec = excludeObjectCopy(src_vec, exclude_positions); + dest_vec = excludeObjectCopy(src_vec, exclude_positions); } diff --git a/BaseLib/quicksort.h b/BaseLib/quicksort.h index d2641ea11e7b3af6cbbc9df7dd474be050750181..1c4f63de5779c785c3093f2d696eaa29bc69a7ef 100644 --- a/BaseLib/quicksort.h +++ b/BaseLib/quicksort.h @@ -25,73 +25,73 @@ namespace BaseLib template <typename T1, typename T2 = std::size_t> void quicksort(T1* array, std::size_t beg, std::size_t end, T2* perm) { - assert (beg <= end); + assert (beg <= end); - // Zip input arrays. - std::vector<std::pair<T1, T2>> data; - data.reserve(end-beg); - std::transform(array+beg, array+end, perm+beg, - std::back_inserter(data), - [](T1 const& t1, T2 const& t2) - { - return std::make_pair(t1, t2); - }); + // Zip input arrays. + std::vector<std::pair<T1, T2>> data; + data.reserve(end-beg); + std::transform(array+beg, array+end, perm+beg, + std::back_inserter(data), + [](T1 const& t1, T2 const& t2) + { + return std::make_pair(t1, t2); + }); - // Sort data using first element of the pair. - std::sort(data.begin(), data.end(), - [](std::pair<T1, T2> const& a, std::pair<T1, T2> const& b) - { - return (a.first < b.first); - }); + // Sort data using first element of the pair. + std::sort(data.begin(), data.end(), + [](std::pair<T1, T2> const& a, std::pair<T1, T2> const& b) + { + return (a.first < b.first); + }); - // Unzip sorted data. - for (std::size_t i = 0; i < data.size(); i++) - { - array[beg+i] = data[i].first; - perm[beg+i] = data[i].second; - } + // Unzip sorted data. + for (std::size_t i = 0; i < data.size(); i++) + { + array[beg+i] = data[i].first; + perm[beg+i] = data[i].second; + } } template <typename T1, typename T2 = std::size_t> void quicksort(std::vector<T1>& array, std::size_t beg, std::size_t end, std::vector<T2>& perm) { - assert (beg<=end); - assert (end<=array.size()); - assert (perm.size()==array.size()); + assert (beg<=end); + assert (end<=array.size()); + assert (perm.size()==array.size()); - quicksort(array.data(), beg, end, perm.data()); + quicksort(array.data(), beg, end, perm.data()); } template <typename T1, typename T2 = std::size_t> void quicksort(std::vector<T1*>& array, std::size_t beg, std::size_t end, std::vector<T2>& perm) { - assert (beg<=end); - assert (end<=array.size()); - assert (perm.size()==array.size()); + assert (beg<=end); + assert (end<=array.size()); + assert (perm.size()==array.size()); - // Zip input arrays. - std::vector<std::pair<T1*, T2>> data; - data.reserve(end-beg); - std::transform(array.begin()+beg, array.begin()+end, perm.begin()+beg, - std::back_inserter(data), - [](T1* const& t1, T2 const& t2) - { - return std::make_pair(t1, t2); - }); + // Zip input arrays. + std::vector<std::pair<T1*, T2>> data; + data.reserve(end-beg); + std::transform(array.begin()+beg, array.begin()+end, perm.begin()+beg, + std::back_inserter(data), + [](T1* const& t1, T2 const& t2) + { + return std::make_pair(t1, t2); + }); - // Sort data using first element of the pair. - std::sort(data.begin(), data.end(), - [](std::pair<T1*, T2> const& a, std::pair<T1*, T2> const& b) - { - return (*a.first < *b.first); - }); + // Sort data using first element of the pair. + std::sort(data.begin(), data.end(), + [](std::pair<T1*, T2> const& a, std::pair<T1*, T2> const& b) + { + return (*a.first < *b.first); + }); - // Unzip sorted data. - for (std::size_t i = 0; i < data.size(); i++) - { - array[beg+i] = data[i].first; - perm[beg+i] = data[i].second; - } + // Unzip sorted data. + for (std::size_t i = 0; i < data.size(); i++) + { + array[beg+i] = data[i].first; + perm[beg+i] = data[i].second; + } } } // end namespace BaseLib diff --git a/BaseLib/uniqueInsert.h b/BaseLib/uniqueInsert.h index 047509e9e7250ec9d6a829e9eea7b5e552d46da7..2db9220bfb2bd17413c94b60d40807a357358ecf 100644 --- a/BaseLib/uniqueInsert.h +++ b/BaseLib/uniqueInsert.h @@ -34,14 +34,14 @@ void uniquePushBack(Container& container, typename Container::value_type const& //! program is aborted. template<typename Map, typename Key, typename Value> void insertIfKeyUniqueElseError( - Map& map, Key const& key, Value&& value, - std::string const& error_message) + Map& map, Key const& key, Value&& value, + std::string const& error_message) { - auto const inserted = map.emplace(key, std::forward<Value>(value)); - if (!inserted.second) { // insertion failed, i.e., key already exists - ERR("%s Key `%s' already exists.", error_message.c_str(), tostring(key).c_str()); - std::abort(); - } + auto const inserted = map.emplace(key, std::forward<Value>(value)); + if (!inserted.second) { // insertion failed, i.e., key already exists + ERR("%s Key `%s' already exists.", error_message.c_str(), tostring(key).c_str()); + std::abort(); + } } //! Inserts the given \c key with the given \c value into the \c map if neither an entry @@ -49,24 +49,24 @@ void insertIfKeyUniqueElseError( //! otherwise an \c error_message is printed and the program is aborted. template<typename Map, typename Key, typename Value> void insertIfKeyValueUniqueElseError( - Map& map, Key const& key, Value&& value, - std::string const& error_message) + Map& map, Key const& key, Value&& value, + std::string const& error_message) { - auto value_compare = [&value](typename Map::value_type const& elem) { - return value == elem.second; - }; + auto value_compare = [&value](typename Map::value_type const& elem) { + return value == elem.second; + }; - if (std::find_if(map.cbegin(), map.cend(), value_compare) != map.cend()) - { - ERR("%s Value `%s' already exists.", error_message.c_str(), tostring(value).c_str()); - std::abort(); - } + if (std::find_if(map.cbegin(), map.cend(), value_compare) != map.cend()) + { + ERR("%s Value `%s' already exists.", error_message.c_str(), tostring(value).c_str()); + std::abort(); + } - auto const inserted = map.emplace(key, std::forward<Value>(value)); - if (!inserted.second) { // insertion failed, i.e., key already exists - ERR("%s Key `%s' already exists.", error_message.c_str(), tostring(key).c_str()); - std::abort(); - } + auto const inserted = map.emplace(key, std::forward<Value>(value)); + if (!inserted.second) { // insertion failed, i.e., key already exists + ERR("%s Key `%s' already exists.", error_message.c_str(), tostring(key).c_str()); + std::abort(); + } } //! Returns the value of \c key from the given \c map if such an entry exists; @@ -76,31 +76,31 @@ void insertIfKeyValueUniqueElseError( template<typename Map, typename Key> typename Map::mapped_type& getOrError( - Map& map, Key const& key, - std::string const& error_message) + Map& map, Key const& key, + std::string const& error_message) { - auto it = map.find(key); - if (it == map.end()) { - ERR("%s Key `%s' does not exist.", error_message.c_str(), tostring(key).c_str()); - std::abort(); - } + auto it = map.find(key); + if (it == map.end()) { + ERR("%s Key `%s' does not exist.", error_message.c_str(), tostring(key).c_str()); + std::abort(); + } - return it->second; + return it->second; } //! \overload template<typename Map, typename Key> typename Map::mapped_type const& getOrError( - Map const& map, Key const& key, - std::string const& error_message) + Map const& map, Key const& key, + std::string const& error_message) { - auto it = map.find(key); - if (it == map.end()) { - ERR("%s Key `%s' does not exist.", error_message.c_str(), tostring(key).c_str()); - std::abort(); - } + auto it = map.find(key); + if (it == map.end()) { + ERR("%s Key `%s' does not exist.", error_message.c_str(), tostring(key).c_str()); + std::abort(); + } - return it->second; + return it->second; } } // end namespace BaseLib diff --git a/BaseLib/wait.h b/BaseLib/wait.h index 483cf6e877ed0bc4c6845d6b89aff425826a93a4..bd748c998048bdbf4aafba8e0738eba50e7da852 100644 --- a/BaseLib/wait.h +++ b/BaseLib/wait.h @@ -22,14 +22,14 @@ namespace BaseLib { void wait(int seconds) { - time_t start_time, cur_time; - - time(&start_time); - do - { - time(&cur_time); - } - while((cur_time - start_time) < seconds); + time_t start_time, cur_time; + + time(&start_time); + do + { + time(&cur_time); + } + while((cur_time - start_time) < seconds); } } // end namespace BaseLib