Commit 9e997ad9 authored by anonymous's avatar anonymous

Merge branch 'development' of git.hemio.de:xerus/xerus into development

parents 700ee798 8dd67869
Pipeline #1953 failed with stages
in 13 minutes and 17 seconds
......@@ -45,4 +45,3 @@
#include "misc/fileIO.h"
#include "misc/stringFromTo.h"
#include "misc/random.h"
#include "misc/fileUtilities.h"
......@@ -37,32 +37,40 @@ namespace xerus {
class generic_error : public std::exception {
public:
///@brief String containing all relevant information concerning this error.
std::string error_info;
std::string errorInfo;
/// @brief: Normal constructor without preset error_info.
generic_error();
/// @brief Standard copy constructor.
generic_error(const generic_error &_other) noexcept;
const char* what() const noexcept override;
const char* what() const noexcept override { return errorInfo.c_str(); }
};
/// @brief The pipe operator allows to add everything that can be converted to string to the error_info and derived exceptions.
template<typename error_t, class T>
typename std::enable_if<std::is_base_of<generic_error, error_t>::value, error_t&>::type
operator<< (error_t &o, const T &_info) noexcept {
o.error_info += to_string(_info);
operator<<(error_t& o, const T& _info) noexcept {
std::ostringstream errorStream(o.errorInfo, std::ios_base::ate | std::ios_base::out);
errorStream << _info;
o.errorInfo = errorStream.str();
return o;
}
/// @brief The pipe operator allows to add everything that can be converted to string to the error_info and derived exceptions.
template<typename error_t, class T>
typename std::enable_if<std::is_base_of<generic_error, error_t>::value, error_t&>::type
operator<< (error_t &&o, const T &_info) noexcept {
o.error_info += to_string(_info);
operator<<(error_t&& o, const T& _info) noexcept {
std::ostringstream errorStream(o.errorInfo, std::ios_base::ate | std::ios_base::out);
errorStream << _info;
o.errorInfo = errorStream.str();
return o;
}
// Once we have C++20... :-/
// /// @brief The pipe operator allows to add everything that can be converted to string to the error_info and derived exceptions.
// template<typename error_t, class T, typename std::enable_if<std::is_base_of<generic_error, std::remove_cvref_t<error_t>>::value, int>::type = 0>
// std::remove_cvref_t<error_t>& operator<<(error_t&& o, const T& _info) noexcept {
// std::ostringstream errorStream(o.errorInfo, std::ios_base::ate | std::ios_base::out);
// errorStream << _info;
// o.errorInfo = errorStream.str();
// return o;
// }
}
}
......
......@@ -43,6 +43,12 @@ namespace xerus {
return (_value < 0 ) ? -_value : _value;
}
///@brief: Calculates the absolute difference between the given values.
template<class T>
constexpr T abs_diff(const T& _a, const T& _b) noexcept {
return (_a > _b) ? (_a - _b) : (_b - _a);
}
///@brief: Calculates _a*_a.
template<class T>
......
......@@ -39,7 +39,6 @@ else ifdef USE_GCC
WARNINGS += -Wlogical-op # Warn about suspicious uses of logical operators in expressions
WARNINGS += -Wtrampolines # Warn about trampolines
# WARNINGS += -Wzero-as-null-pointer-constant # Warn when a literal '0' is used as null pointer constant.
WARNINGS += -Wnoexcept # Warn when a noexcept-expression evaluates to false because of a call to a function that does not have noexcept but is known by the compiler to never throw.
WARNINGS += -Wsuggest-override # Suggest functions that do override
ifdef SUGGEST_ATTRIBUTES
......@@ -55,6 +54,8 @@ else ifdef USE_GCC
WARNINGS += -Wno-error=suggest-attribute=format # Do not promote to Error
WARNINGS += -Wno-error=suggest-final-methods # Do not promote to Error
WARNINGS += -Wno-error=suggest-final-types # Do not promote to Error
WARNINGS += -Wnoexcept # Warn when a noexcept-expression evaluates to false because of a call to a function that does not have noexcept but is known by the compiler to never throw.
endif
endif
......
// Xerus - A General Purpose Tensor Library
// Copyright (C) 2014-2019 Benjamin Huber and Sebastian Wolf.
//
// Xerus is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License,
// or (at your option) any later version.
//
// Xerus is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with Xerus. If not, see <http://www.gnu.org/licenses/>.
//
// For further information on Xerus visit https://libXerus.org
// or contact us at contact@libXerus.org.
/**
* @file
* @brief Implementation of the generic_error class.
*/
#include <xerus/misc/exceptions.h>
namespace xerus {
namespace misc {
generic_error::generic_error() {}
generic_error::generic_error(const generic_error &_other) noexcept
: error_info(_other.error_info) { }
const char* generic_error::what() const noexcept {
return error_info.c_str();
}
} // namespace misc
} // namespace xerus
......@@ -39,11 +39,17 @@
#pragma GCC diagnostic pop
namespace xerus { namespace misc {
void create_directories_for_file(const std::string& _path) {
if(_path.find('/') != std::string::npos) {
const std::string folder = _path.substr(0, _path.find_last_of('/'));
boost::filesystem::create_directories(folder);
std::string folder = _path.substr(0, _path.find_last_of('/'));
// Remove trailing / (can appear e.g. in "folder//file.dat").
while(folder.back() == '/') { folder.pop_back(); }
if(folder != ".") { // Boost doesn't like being called with ".".
boost::filesystem::create_directories(folder);
}
}
}
......
......@@ -27,10 +27,6 @@
#include <chrono>
#include <fstream>
#ifdef XERUS_LOG_BUFFER
#include <fstream>
#endif
#include <xerus/misc/namedLogger.h>
#include <xerus/misc/stringUtilities.h>
......@@ -67,15 +63,15 @@ namespace xerus { namespace misc { namespace internal {
void log_timestamp(std::ostream &_out, const char* _file, int _line, const char* _lvl) {
log_timestamp(_out);
_out << std::setfill(' ') << std::setw(20) << std::left << xerus::misc::explode(_file, '/').back() << ':' \
_out << std::setfill(' ') << std::setw(25) << std::left << xerus::misc::explode(_file, '/').back() << ':' \
<< std::right << std::setfill(' ') << std::setw(4) <<_line << " : " \
<< std::setfill(' ') << std::setw(12) << std::left \
<< std::setfill(' ') << std::setw(15) << std::left \
<< std::string(_lvl) << ": ";
}
void log_timestamp(std::ostream &_out, const char* _lvl) {
log_timestamp(_out);
_out << std::setfill(' ') << std::setw(12) << std::left \
_out << std::setfill(' ') << std::setw(15) << std::left \
<< std::string(_lvl) << ": ";
}
......
......@@ -37,7 +37,7 @@ namespace xerus {
if (realname) {
return std::string(realname.get());
}
}
return "";
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment