diff --git a/.clang-format b/.clang-format index 15d70a4c..f4e10c28 100644 --- a/.clang-format +++ b/.clang-format @@ -39,7 +39,7 @@ BraceWrapping: SplitEmptyNamespace: false BreakBeforeBinaryOperators: None BreakBeforeTernaryOperators: true -BreakConstructorInitializers: BeforeColon +BreakConstructorInitializers: AfterColon BreakInheritanceList: BeforeColon ColumnLimit: 0 CompactNamespaces: false diff --git a/src/filesink.cpp b/src/filesink.cpp index ebbe45d0..057262f0 100644 --- a/src/filesink.cpp +++ b/src/filesink.cpp @@ -14,8 +14,8 @@ namespace g3 { using namespace internal; - FileSink::FileSink(const std::string& log_prefix, const std::string& log_directory, const std::string& logger_id, size_t write_to_log_every_x_message) - : _log_details_func(&LogMessage::DefaultLogDetailsToString), _log_file_with_path(log_directory), _log_prefix_backup(log_prefix), _outptr(new std::ofstream), _header("\t\tLOG format: [YYYY/MM/DD hh:mm:ss uuu* LEVEL FILE->FUNCTION:LINE] message\n\n\t\t(uuu*: microseconds fractions of the seconds value)\n\n"), _firstEntry(true), _write_counter(0), _write_to_log_every_x_message(write_to_log_every_x_message) { + FileSink::FileSink(const std::string& log_prefix, const std::string& log_directory, const std::string& logger_id, size_t write_to_log_every_x_message) : + _log_details_func(&LogMessage::DefaultLogDetailsToString), _log_file_with_path(log_directory), _log_prefix_backup(log_prefix), _outptr(new std::ofstream), _header("\t\tLOG format: [YYYY/MM/DD hh:mm:ss uuu* LEVEL FILE->FUNCTION:LINE] message\n\n\t\t(uuu*: microseconds fractions of the seconds value)\n\n"), _firstEntry(true), _write_counter(0), _write_to_log_every_x_message(write_to_log_every_x_message) { _log_prefix_backup = prefixSanityFix(log_prefix); if (!isValidFilename(_log_prefix_backup)) { std::cerr << "g3log: forced abort due to illegal log prefix [" << log_prefix << "]" << std::endl; diff --git a/src/g3log/active.hpp b/src/g3log/active.hpp index 23d53079..3711f9d5 100644 --- a/src/g3log/active.hpp +++ b/src/g3log/active.hpp @@ -29,8 +29,8 @@ namespace kjellkod { class Active { private: - Active() - : done_(false) {} // Construction ONLY through factory createActive(); + Active() : + done_(false) {} // Construction ONLY through factory createActive(); Active(const Active&) = delete; Active& operator=(const Active&) = delete; diff --git a/src/g3log/atomicbool.hpp b/src/g3log/atomicbool.hpp index db1d3de9..d6e51fb7 100644 --- a/src/g3log/atomicbool.hpp +++ b/src/g3log/atomicbool.hpp @@ -17,14 +17,14 @@ namespace g3 { std::atomic value_; public: - atomicbool() - : value_{false} {} - atomicbool(bool value) - : value_{value} {} - atomicbool(const std::atomic& value) - : value_{value.load(std::memory_order_acquire)} {} - atomicbool(const atomicbool& other) - : value_{other.value_.load(std::memory_order_acquire)} {} + atomicbool() : + value_{false} {} + atomicbool(bool value) : + value_{value} {} + atomicbool(const std::atomic& value) : + value_{value.load(std::memory_order_acquire)} {} + atomicbool(const atomicbool& other) : + value_{other.value_.load(std::memory_order_acquire)} {} atomicbool& operator=(const atomicbool& other) { value_.store(other.value_.load(std::memory_order_acquire), std::memory_order_release); diff --git a/src/g3log/loglevels.hpp b/src/g3log/loglevels.hpp index 1efc63b8..419f6ec6 100644 --- a/src/g3log/loglevels.hpp +++ b/src/g3log/loglevels.hpp @@ -33,11 +33,11 @@ struct LEVELS { // force internal copy of the const char*. This is a simple safeguard for when g3log is used in a // "dynamic, runtime loading of shared libraries" - LEVELS(const LEVELS& other) - : value(other.value), text(other.text.c_str()) {} + LEVELS(const LEVELS& other) : + value(other.value), text(other.text.c_str()) {} - LEVELS(int id, const std::string& idtext) - : value(id), text(idtext) {} + LEVELS(int id, const std::string& idtext) : + value(id), text(idtext) {} bool operator==(const LEVELS& rhs) const { return (value == rhs.value && text == rhs.text); @@ -103,14 +103,14 @@ namespace g3 { LEVELS level; // default operator needed for std::map compliance - LoggingLevel() - : status(false), level(INFO){}; - LoggingLevel(const LoggingLevel& lvl) - : status(lvl.status), level(lvl.level) {} - LoggingLevel(const LEVELS& lvl) - : status(true), level(lvl){}; - LoggingLevel(const LEVELS& lvl, bool enabled) - : status(enabled), level(lvl){}; + LoggingLevel() : + status(false), level(INFO){}; + LoggingLevel(const LoggingLevel& lvl) : + status(lvl.status), level(lvl.level) {} + LoggingLevel(const LEVELS& lvl) : + status(true), level(lvl){}; + LoggingLevel(const LEVELS& lvl, bool enabled) : + status(enabled), level(lvl){}; ~LoggingLevel() = default; LoggingLevel& operator=(const LoggingLevel& other) { diff --git a/src/g3log/moveoncopy.hpp b/src/g3log/moveoncopy.hpp index 74e9e43d..32a44b3c 100644 --- a/src/g3log/moveoncopy.hpp +++ b/src/g3log/moveoncopy.hpp @@ -18,12 +18,12 @@ namespace g3 { struct MoveOnCopy { mutable Moveable _move_only; - explicit MoveOnCopy(Moveable&& m) - : _move_only(std::move(m)) {} - MoveOnCopy(MoveOnCopy const& t) - : _move_only(std::move(t._move_only)) {} - MoveOnCopy(MoveOnCopy&& t) - : _move_only(std::move(t._move_only)) {} + explicit MoveOnCopy(Moveable&& m) : + _move_only(std::move(m)) {} + MoveOnCopy(MoveOnCopy const& t) : + _move_only(std::move(t._move_only)) {} + MoveOnCopy(MoveOnCopy&& t) : + _move_only(std::move(t._move_only)) {} MoveOnCopy& operator=(MoveOnCopy const& other) { _move_only = std::move(other._move_only); diff --git a/src/g3log/sink.hpp b/src/g3log/sink.hpp index 7596f1bf..61f8850d 100644 --- a/src/g3log/sink.hpp +++ b/src/g3log/sink.hpp @@ -40,17 +40,17 @@ namespace g3 { AsyncMessageCall _default_log_call; template - Sink(std::unique_ptr sink, DefaultLogCall call) - : SinkWrapper(), - _real_sink{std::move(sink)}, - _bg(kjellkod::Active::createActive()), - _default_log_call(std::bind(call, _real_sink.get(), std::placeholders::_1)) { + Sink(std::unique_ptr sink, DefaultLogCall call) : + SinkWrapper(), + _real_sink{std::move(sink)}, + _bg(kjellkod::Active::createActive()), + _default_log_call(std::bind(call, _real_sink.get(), std::placeholders::_1)) { } - Sink(std::unique_ptr sink, void (T::*Call)(std::string)) - : SinkWrapper(), - _real_sink{std::move(sink)}, - _bg(kjellkod::Active::createActive()) { + Sink(std::unique_ptr sink, void (T::*Call)(std::string)) : + SinkWrapper(), + _real_sink{std::move(sink)}, + _bg(kjellkod::Active::createActive()) { std::function adapter = std::bind(Call, _real_sink.get(), std::placeholders::_1); _default_log_call = [=](LogMessageMover m) { adapter(m.get().toString()); diff --git a/src/g3log/sinkhandle.hpp b/src/g3log/sinkhandle.hpp index 4fc18904..34848d21 100644 --- a/src/g3log/sinkhandle.hpp +++ b/src/g3log/sinkhandle.hpp @@ -27,8 +27,8 @@ namespace g3 { std::weak_ptr> _sink; public: - SinkHandle(std::shared_ptr> sink) - : _sink(sink) {} + SinkHandle(std::shared_ptr> sink) : + _sink(sink) {} ~SinkHandle() = default; diff --git a/src/g3log/stlpatch_future.hpp b/src/g3log/stlpatch_future.hpp index 464798ae..b7f30160 100644 --- a/src/g3log/stlpatch_future.hpp +++ b/src/g3log/stlpatch_future.hpp @@ -25,13 +25,13 @@ namespace std { } template - explicit packaged_task(_Fty2&& _Fnarg) - : _my_func(_Fnarg) { + explicit packaged_task(_Fty2&& _Fnarg) : + _my_func(_Fnarg) { } - packaged_task(packaged_task&& _Other) - : _my_promise(move(_Other._my_promise)), - _my_func(move(_Other._my_func)) { + packaged_task(packaged_task&& _Other) : + _my_promise(move(_Other._my_promise)), + _my_func(move(_Other._my_func)) { } packaged_task& operator=(packaged_task&& _Other) { diff --git a/src/logcapture.cpp b/src/logcapture.cpp index d3ec6501..d3859d30 100644 --- a/src/logcapture.cpp +++ b/src/logcapture.cpp @@ -47,8 +47,8 @@ LogCapture::~LogCapture() noexcept(false) { } /// Called from crash handler when a fatal signal has occurred (SIGSEGV etc) -LogCapture::LogCapture(const LEVELS& level, g3::SignalType fatal_signal, const char* dump) - : LogCapture("", 0, "", level, "", fatal_signal, dump) { +LogCapture::LogCapture(const LEVELS& level, g3::SignalType fatal_signal, const char* dump) : + LogCapture("", 0, "", level, "", fatal_signal, dump) { } /** @@ -58,8 +58,8 @@ LogCapture::LogCapture(const LEVELS& level, g3::SignalType fatal_signal, const c * @fatal_signal for failed CHECK:SIGABRT or fatal signal caught in the signal handler */ LogCapture::LogCapture(const char* file, const int line, const char* function, const LEVELS& level, - const char* expression, g3::SignalType fatal_signal, const char* dump) - : _file(file), _line(line), _function(function), _level(level), _expression(expression), _fatal_signal(fatal_signal) { + const char* expression, g3::SignalType fatal_signal, const char* dump) : + _file(file), _line(line), _function(function), _level(level), _expression(expression), _fatal_signal(fatal_signal) { if (g3::internal::wasFatal(level)) { _stack_trace = std::string{"\n*******\tSTACKDUMP *******\n"}; diff --git a/src/logmessage.cpp b/src/logmessage.cpp index a902360c..0b7f6dc1 100644 --- a/src/logmessage.cpp +++ b/src/logmessage.cpp @@ -119,33 +119,33 @@ namespace g3 { } LogMessage::LogMessage(std::string file, const int line, - std::string function, const LEVELS level) - : _logDetailsToStringFunc(LogMessage::DefaultLogDetailsToString), _timestamp(std::chrono::high_resolution_clock::now()), _call_thread_id(std::this_thread::get_id()) + std::string function, const LEVELS level) : + _logDetailsToStringFunc(LogMessage::DefaultLogDetailsToString), _timestamp(std::chrono::high_resolution_clock::now()), _call_thread_id(std::this_thread::get_id()) #if defined(G3_LOG_FULL_FILENAME) - , - _file(file) + , + _file(file) #else - , - _file(LogMessage::splitFileName(file)) + , + _file(LogMessage::splitFileName(file)) #endif - , - _file_path(file), - _line(line), - _function(std::move(function)), - _level(level) { + , + _file_path(file), + _line(line), + _function(std::move(function)), + _level(level) { } - LogMessage::LogMessage(const std::string& fatalOsSignalCrashMessage) - : LogMessage({""}, 0, {""}, internal::FATAL_SIGNAL) { + LogMessage::LogMessage(const std::string& fatalOsSignalCrashMessage) : + LogMessage({""}, 0, {""}, internal::FATAL_SIGNAL) { _message.append(fatalOsSignalCrashMessage); } - LogMessage::LogMessage(const LogMessage& other) - : _logDetailsToStringFunc(other._logDetailsToStringFunc), _timestamp(other._timestamp), _call_thread_id(other._call_thread_id), _file(other._file), _file_path(other._file_path), _line(other._line), _function(other._function), _level(other._level), _expression(other._expression), _message(other._message) { + LogMessage::LogMessage(const LogMessage& other) : + _logDetailsToStringFunc(other._logDetailsToStringFunc), _timestamp(other._timestamp), _call_thread_id(other._call_thread_id), _file(other._file), _file_path(other._file_path), _line(other._line), _function(other._function), _level(other._level), _expression(other._expression), _message(other._message) { } - LogMessage::LogMessage(LogMessage&& other) - : _logDetailsToStringFunc(other._logDetailsToStringFunc), _timestamp(other._timestamp), _call_thread_id(other._call_thread_id), _file(std::move(other._file)), _file_path(std::move(other._file_path)), _line(other._line), _function(std::move(other._function)), _level(other._level), _expression(std::move(other._expression)), _message(std::move(other._message)) { + LogMessage::LogMessage(LogMessage&& other) : + _logDetailsToStringFunc(other._logDetailsToStringFunc), _timestamp(other._timestamp), _call_thread_id(other._call_thread_id), _file(std::move(other._file)), _file_path(std::move(other._file_path)), _line(other._line), _function(std::move(other._function)), _level(other._level), _expression(std::move(other._expression)), _message(std::move(other._message)) { } std::string LogMessage::threadID() const { @@ -154,11 +154,11 @@ namespace g3 { return oss.str(); } - FatalMessage::FatalMessage(const LogMessage& details, g3::SignalType signal_id) - : LogMessage(details), _signal_id(signal_id) {} + FatalMessage::FatalMessage(const LogMessage& details, g3::SignalType signal_id) : + LogMessage(details), _signal_id(signal_id) {} - FatalMessage::FatalMessage(const FatalMessage& other) - : LogMessage(other), _signal_id(other._signal_id) {} + FatalMessage::FatalMessage(const FatalMessage& other) : + LogMessage(other), _signal_id(other._signal_id) {} LogMessage FatalMessage::copyToLogMessage() const { return LogMessage(*this); diff --git a/src/logworker.cpp b/src/logworker.cpp index 7abb17c5..4bda2453 100644 --- a/src/logworker.cpp +++ b/src/logworker.cpp @@ -17,8 +17,8 @@ namespace g3 { - LogWorkerImpl::LogWorkerImpl() - : _bg(kjellkod::Active::createActive()) {} + LogWorkerImpl::LogWorkerImpl() : + _bg(kjellkod::Active::createActive()) {} void LogWorkerImpl::bgSave(g3::LogMessagePtr msgPtr) { std::unique_ptr uniqueMsg(std::move(msgPtr.get())); diff --git a/test_unit/test_concept_sink.cpp b/test_unit/test_concept_sink.cpp index 6be4b918..9977ec39 100644 --- a/test_unit/test_concept_sink.cpp +++ b/test_unit/test_concept_sink.cpp @@ -29,8 +29,8 @@ class CoutSink { stringstream buffer; unique_ptr scope_ptr; - CoutSink() - : scope_ptr(std::make_unique(std::cout, &buffer)) {} + CoutSink() : + scope_ptr(std::make_unique(std::cout, &buffer)) {} public: void clear() { buffer.str(""); } @@ -67,9 +67,9 @@ namespace g3 { } public: - Worker() - : _bg{ - kjellkod::Active::createActive()} { + Worker() : + _bg{ + kjellkod::Active::createActive()} { } ~Worker() { diff --git a/test_unit/test_cpp_future_concepts.cpp b/test_unit/test_cpp_future_concepts.cpp index d22d3d19..68f7d907 100644 --- a/test_unit/test_cpp_future_concepts.cpp +++ b/test_unit/test_cpp_future_concepts.cpp @@ -34,8 +34,8 @@ TEST(Configuration, FutureSilly) { struct MsgType { std::string msg_; - MsgType(std::string m) - : msg_(m){}; + MsgType(std::string m) : + msg_(m){}; std::string msg() { return msg_; } }; diff --git a/test_unit/test_io.cpp b/test_unit/test_io.cpp index 782d64f8..2224d034 100644 --- a/test_unit/test_io.cpp +++ b/test_unit/test_io.cpp @@ -593,8 +593,8 @@ TEST(CHECK, CHECK_runtimeError) { const int size_; public: - explicit dynamic_int_array(int size) - : data_{std::make_unique(size)}, size_(size) {} + explicit dynamic_int_array(int size) : + data_{std::make_unique(size)}, size_(size) {} int& at(int i) { CHECK(i < size_); diff --git a/test_unit/test_linux_dynamic_loaded_sharedlib.cpp b/test_unit/test_linux_dynamic_loaded_sharedlib.cpp index bc434d0e..0ec6c453 100644 --- a/test_unit/test_linux_dynamic_loaded_sharedlib.cpp +++ b/test_unit/test_linux_dynamic_loaded_sharedlib.cpp @@ -20,8 +20,8 @@ struct LogMessageCounter { std::vector& bank; - LogMessageCounter(std::vector& storeMessages) - : bank(storeMessages) { + LogMessageCounter(std::vector& storeMessages) : + bank(storeMessages) { } void countMessages(std::string msg) { diff --git a/test_unit/test_sink.cpp b/test_unit/test_sink.cpp index 1bab30f1..e200161b 100644 --- a/test_unit/test_sink.cpp +++ b/test_unit/test_sink.cpp @@ -227,8 +227,8 @@ TEST(ConceptSink, OneHundredRemoveAllSinks) { struct VoidReceiver { std::atomic* _atomicCounter; - explicit VoidReceiver(std::atomic* counter) - : _atomicCounter(counter) {} + explicit VoidReceiver(std::atomic* counter) : + _atomicCounter(counter) {} void receiveMsg(std::string msg) { /*ignored*/ } @@ -271,8 +271,8 @@ TEST(ConceptSink, VoidCall__TwoCalls_ExpectingTwoAdd) { struct IntReceiver { std::atomic* _atomicCounter; - explicit IntReceiver(std::atomic* counter) - : _atomicCounter(counter) {} + explicit IntReceiver(std::atomic* counter) : + _atomicCounter(counter) {} void receiveMsgDoNothing(std::string msg) { /*ignored*/ } diff --git a/test_unit/testing_helpers.cpp b/test_unit/testing_helpers.cpp index d1021f43..ce5f7d07 100644 --- a/test_unit/testing_helpers.cpp +++ b/test_unit/testing_helpers.cpp @@ -98,16 +98,16 @@ namespace testing_helpers { } } - ScopedLogger::ScopedLogger() - : _currentWorker(g3::LogWorker::createLogWorker()) {} + ScopedLogger::ScopedLogger() : + _currentWorker(g3::LogWorker::createLogWorker()) {} ScopedLogger::~ScopedLogger() {} g3::LogWorker* ScopedLogger::get() { return _currentWorker.get(); } - RestoreFileLogger::RestoreFileLogger(std::string directory) - : _scope(new ScopedLogger), _handle(_scope->get()->addSink(std::make_unique("UNIT_TEST_LOGGER", directory, "g3log", kFlushToDiskWithThisInterval), &g3::FileSink::fileWrite)) { + RestoreFileLogger::RestoreFileLogger(std::string directory) : + _scope(new ScopedLogger), _handle(_scope->get()->addSink(std::make_unique("UNIT_TEST_LOGGER", directory, "g3log", kFlushToDiskWithThisInterval), &g3::FileSink::fileWrite)) { using namespace g3; g3::initializeLogging(_scope->_currentWorker.get()); clearMockFatal();