From 005dc7e605ceeabbda80679dbc8af1a184d069dc Mon Sep 17 00:00:00 2001 From: gabime Date: Sat, 22 Feb 2014 10:34:42 +0200 Subject: [PATCH] underscore first in members --- include/c11log/details/blocking_queue.h | 56 ++++++++++++------------ include/c11log/details/line_logger.h | 4 +- include/c11log/logger.h | 58 ++++++++++++------------- include/c11log/sinks/async_sink.h | 58 ++++++++++++------------- include/c11log/sinks/base_sink.h | 6 +-- include/c11log/sinks/file_sinks.h | 24 +++++----- include/c11log/sinks/stdout_sinks.h | 2 +- 7 files changed, 104 insertions(+), 104 deletions(-) diff --git a/include/c11log/details/blocking_queue.h b/include/c11log/details/blocking_queue.h index 07d40080..2ac8bbc0 100644 --- a/include/c11log/details/blocking_queue.h +++ b/include/c11log/details/blocking_queue.h @@ -21,17 +21,17 @@ public: using clock = std::chrono::system_clock; explicit blocking_queue(size_type max_size) : - max_size_(max_size), - q_(), - mutex_() { + _max_size(max_size), + _q(), + _mutex() { } blocking_queue(const blocking_queue&) = delete; blocking_queue& operator=(const blocking_queue&) = delete; ~blocking_queue() = default; size_type size() { - std::lock_guard lock(mutex_); - return q_.size(); + std::lock_guard lock(_mutex); + return _q.size(); } // Push copy of item into the back of the queue. @@ -39,17 +39,17 @@ public: // Return: false on timeout, true on successful push. template bool push(TT&& item, const std::chrono::duration& timeout) { - std::unique_lock ul(mutex_); - if (q_.size() >= max_size_) { - if (!item_popped_cond_.wait_until(ul, clock::now() + timeout, [this]() { - return this->q_.size() < this->max_size_; + std::unique_lock ul(_mutex); + if (_q.size() >= _max_size) { + if (!_item_popped_cond.wait_until(ul, clock::now() + timeout, [this]() { + return this->_q.size() < this->_max_size; })) return false; } - q_.push(std::forward(item)); - if (q_.size() <= 1) { + _q.push(std::forward(item)); + if (_q.size() <= 1) { ul.unlock(); //So the notified thread will have better chance to accuire the lock immediatly.. - item_pushed_cond_.notify_one(); + _item_pushed_cond.notify_one(); } return true; } @@ -66,18 +66,18 @@ public: // Return: false on timeout , true on successful pop/ template bool pop(T& item, const std::chrono::duration& timeout) { - std::unique_lock ul(mutex_); - if (q_.empty()) { - if (!item_pushed_cond_.wait_until(ul, clock::now() + timeout, [this]() { - return !this->q_.empty(); + std::unique_lock ul(_mutex); + if (_q.empty()) { + if (!_item_pushed_cond.wait_until(ul, clock::now() + timeout, [this]() { + return !this->_q.empty(); })) return false; } - item = std::move(q_.front()); - q_.pop(); - if (q_.size() >= max_size_ - 1) { + item = std::move(_q.front()); + _q.pop(); + if (_q.size() >= _max_size - 1) { ul.unlock(); //So the notified thread will have better chance to accuire the lock immediatly.. - item_popped_cond_.notify_one(); + _item_popped_cond.notify_one(); } return true; } @@ -91,18 +91,18 @@ public: // Clear the queue void clear() { { - std::unique_lock ul(mutex_); - queue_t().swap(q_); + std::unique_lock ul(_mutex); + queue_t().swap(_q); } - item_popped_cond_.notify_all(); + _item_popped_cond.notify_all(); } private: - size_type max_size_; - std::queue q_; - std::mutex mutex_; - std::condition_variable item_pushed_cond_; - std::condition_variable item_popped_cond_; + size_type _max_size; + std::queue _q; + std::mutex _mutex; + std::condition_variable _item_pushed_cond; + std::condition_variable _item_popped_cond; static constexpr auto one_hour = std::chrono::hours(1); }; diff --git a/include/c11log/details/line_logger.h b/include/c11log/details/line_logger.h index 1c9378fb..b0222843 100644 --- a/include/c11log/details/line_logger.h +++ b/include/c11log/details/line_logger.h @@ -14,7 +14,7 @@ public: _callback_logger(callback_logger), _oss(), _level(msg_level) { - callback_logger->formatter_->format_header(callback_logger->logger_name_, + callback_logger->_formatter->format_header(callback_logger->_logger_name, msg_level, c11log::formatters::clock::now(), _oss); @@ -30,7 +30,7 @@ public: ~line_logger() { if (_callback_logger) { _oss << '\n'; - _callback_logger->log_it_(_oss.str_ref()); + _callback_logger->_log_it(_oss.str_ref()); } } diff --git a/include/c11log/logger.h b/include/c11log/logger.h index c02f12b4..b8c62754 100644 --- a/include/c11log/logger.h +++ b/include/c11log/logger.h @@ -24,11 +24,11 @@ public: typedef std::vector sinks_vector_t; explicit logger(const std::string& name) : - logger_name_(name), - formatter_(new formatters::default_formatter()), - sinks_(), - mutex_(), - atomic_level_(level::INFO) { + _logger_name(name), + _formatter(new formatters::default_formatter()), + _sinks(), + _mutex(), + _atomic_level(level::INFO) { } ~logger() = default; @@ -55,13 +55,13 @@ public: private: friend details::line_logger; - std::string logger_name_ = ""; - std::unique_ptr formatter_; - sinks_vector_t sinks_; - std::mutex mutex_; - std::atomic_int atomic_level_; + std::string _logger_name = ""; + std::unique_ptr _formatter; + sinks_vector_t _sinks; + std::mutex _mutex; + std::atomic_int _atomic_level; - void log_it_(const std::string& msg); + void _log_it(const std::string& msg); }; @@ -75,7 +75,7 @@ logger& get_logger(const std::string& name); inline c11log::details::line_logger c11log::logger::log(c11log::level::level_enum msg_level) { - if (msg_level >= atomic_level_) + if (msg_level >= _atomic_level) return details::line_logger(this, msg_level); else return details::line_logger(nullptr); @@ -104,53 +104,53 @@ inline c11log::details::line_logger c11log::logger::fatal() inline void c11log::logger::set_name(const std::string& name) { - std::lock_guard lock(mutex_); - logger_name_ = name; + std::lock_guard lock(_mutex); + _logger_name = name; } inline const std::string& c11log::logger::get_name() { - std::lock_guard lock(mutex_); - return logger_name_; + std::lock_guard lock(_mutex); + return _logger_name; } inline void c11log::logger::add_sink(sink_ptr_t sink_ptr) { - std::lock_guard lock(mutex_); - sinks_.push_back(sink_ptr); + std::lock_guard lock(_mutex); + _sinks.push_back(sink_ptr); } inline void c11log::logger::remove_sink(sink_ptr_t sink_ptr) { - std::lock_guard lock(mutex_); - sinks_.erase(std::remove(sinks_.begin(), sinks_.end(), sink_ptr), sinks_.end()); + std::lock_guard lock(_mutex); + _sinks.erase(std::remove(_sinks.begin(), _sinks.end(), sink_ptr), _sinks.end()); } inline void c11log::logger::set_formatter(std::unique_ptr formatter) { - std::lock_guard lock(mutex_); - formatter_ = std::move(formatter); + std::lock_guard lock(_mutex); + _formatter = std::move(formatter); } inline void c11log::logger::set_level(c11log::level::level_enum level) { - atomic_level_.store(level); + _atomic_level.store(level); } inline c11log::level::level_enum c11log::logger::get_level() const { - return static_cast(atomic_level_.load()); + return static_cast(_atomic_level.load()); } inline bool c11log::logger::should_log(c11log::level::level_enum level) const { - return level >= atomic_level_.load(); + return level >= _atomic_level.load(); } -inline void c11log::logger::log_it_(const std::string& msg) +inline void c11log::logger::_log_it(const std::string& msg) { - level::level_enum level = static_cast(atomic_level_.load()); - std::lock_guard lock(mutex_); - for (auto &sink : sinks_) + level::level_enum level = static_cast(_atomic_level.load()); + std::lock_guard lock(_mutex); + for (auto &sink : _sinks) sink->log(msg, level); } diff --git a/include/c11log/sinks/async_sink.h b/include/c11log/sinks/async_sink.h index c80d435e..2aa7d37a 100644 --- a/include/c11log/sinks/async_sink.h +++ b/include/c11log/sinks/async_sink.h @@ -25,16 +25,16 @@ public: protected: - void sink_it_(const std::string& msg) override; - void thread_loop_(); + void _sink_it(const std::string& msg) override; + void _thread_loop(); private: - c11log::logger::sinks_vector_t sinks_; - std::atomic active_; - c11log::details::blocking_queue q_; - std::thread back_thread_; - //Clear all remaining messages(if any), stop the back_thread_ and join it - void shutdown_(); + c11log::logger::sinks_vector_t _sinks; + std::atomic _active; + c11log::details::blocking_queue _q; + std::thread _back_thread; + //Clear all remaining messages(if any), stop the _back_thread and join it + void _shutdown(); }; } } @@ -44,31 +44,31 @@ private: /////////////////////////////////////////////////////////////////////////////// inline c11log::sinks::async_sink::async_sink(const std::size_t max_queue_size) - :sinks_(), - active_(true), - q_(max_queue_size), - back_thread_(&async_sink::thread_loop_, this) + :_sinks(), + _active(true), + _q(max_queue_size), + _back_thread(&async_sink::_thread_loop, this) {} inline c11log::sinks::async_sink::~async_sink() { - shutdown_(); + _shutdown(); } -inline void c11log::sinks::async_sink::sink_it_(const std::string& msg) +inline void c11log::sinks::async_sink::_sink_it(const std::string& msg) { - q_.push(msg); + _q.push(msg); } -inline void c11log::sinks::async_sink::thread_loop_() +inline void c11log::sinks::async_sink::_thread_loop() { constexpr auto pop_timeout = std::chrono::seconds(1); std::string msg; - while (active_) { - if (q_.pop(msg, pop_timeout)) { - for (auto &sink : sinks_) { + while (_active) { + if (_q.pop(msg, pop_timeout)) { + for (auto &sink : _sinks) { sink->log(msg, static_cast(_level.load())); - if (!active_) + if (!_active) return; } } @@ -77,30 +77,30 @@ inline void c11log::sinks::async_sink::thread_loop_() inline void c11log::sinks::async_sink::add_sink(logger::sink_ptr_t sink) { - sinks_.push_back(sink); + _sinks.push_back(sink); } inline void c11log::sinks::async_sink::remove_sink(logger::sink_ptr_t sink_ptr) { - sinks_.erase(std::remove(sinks_.begin(), sinks_.end(), sink_ptr), sinks_.end()); + _sinks.erase(std::remove(_sinks.begin(), _sinks.end(), sink_ptr), _sinks.end()); } inline void c11log::sinks::async_sink::shutdown(const std::chrono::seconds &timeout) { auto until = std::chrono::system_clock::now() + timeout; - while (q_.size() > 0 && std::chrono::system_clock::now() < until) { + while (_q.size() > 0 && std::chrono::system_clock::now() < until) { std::this_thread::sleep_for(std::chrono::milliseconds(200)); } - shutdown_(); + _shutdown(); } -inline void c11log::sinks::async_sink::shutdown_() +inline void c11log::sinks::async_sink::_shutdown() { - if(active_) { - active_ = false; - if (back_thread_.joinable()) - back_thread_.join(); + if(_active) { + _active = false; + if (_back_thread.joinable()) + _back_thread.join(); } } diff --git a/include/c11log/sinks/base_sink.h b/include/c11log/sinks/base_sink.h index e3e61fbf..f5846e8d 100644 --- a/include/c11log/sinks/base_sink.h +++ b/include/c11log/sinks/base_sink.h @@ -20,7 +20,7 @@ public: void log(const std::string &msg, level::level_enum level) { if (level >= _level) { - sink_it_(msg); + _sink_it(msg); } }; @@ -29,13 +29,13 @@ public: } protected: - virtual void sink_it_(const std::string& msg) = 0; + virtual void _sink_it(const std::string& msg) = 0; std::atomic _level {level::INFO}; }; class null_sink:public base_sink { protected: - void sink_it_(const std::string& ) override { + void _sink_it(const std::string& ) override { } }; } diff --git a/include/c11log/sinks/file_sinks.h b/include/c11log/sinks/file_sinks.h index 42167ecc..3ead8918 100644 --- a/include/c11log/sinks/file_sinks.h +++ b/include/c11log/sinks/file_sinks.h @@ -14,17 +14,17 @@ namespace sinks { class simple_file_sink : public base_sink { public: explicit simple_file_sink(const std::string &filename, const std::string& extension = "txt") - : mutex_(), + : _mutex(), _ofstream(filename + "." + extension, std::ofstream::app) { } protected: - void sink_it_(const std::string& msg) override { - std::lock_guard lock(mutex_); + void _sink_it(const std::string& msg) override { + std::lock_guard lock(_mutex); _ofstream << msg; _ofstream.flush(); } private: - std::mutex mutex_; + std::mutex _mutex; std::ofstream _ofstream; }; @@ -41,13 +41,13 @@ public: _max_size(max_size), _max_files(max_files), _current_size(0), - mutex_(), + _mutex(), _ofstream(_calc_filename(_base_filename, 0, _extension)) { } protected: - void sink_it_(const std::string& msg) override { - std::lock_guard lock(mutex_); + void _sink_it(const std::string& msg) override { + std::lock_guard lock(_mutex); _current_size += msg.length(); if (_current_size > _max_size) { _rotate(); @@ -91,7 +91,7 @@ private: std::size_t _max_size; std::size_t _max_files; std::size_t _current_size; - std::mutex mutex_; + std::mutex _mutex; std::ofstream _ofstream; }; @@ -104,13 +104,13 @@ public: _base_filename(base_filename), _extension(extension), _midnight_tp (_calc_midnight_tp() ), - mutex_(), + _mutex(), _ofstream(_calc_filename(_base_filename, _extension), std::ofstream::app) { } protected: - void sink_it_(const std::string& msg) override { - std::lock_guard lock(mutex_); + void _sink_it(const std::string& msg) override { + std::lock_guard lock(_mutex); if (std::chrono::system_clock::now() >= _midnight_tp) { _ofstream.close(); _ofstream.open(_calc_filename(_base_filename, _extension)); @@ -142,7 +142,7 @@ private: std::string _base_filename; std::string _extension; std::chrono::system_clock::time_point _midnight_tp; - std::mutex mutex_; + std::mutex _mutex; std::ofstream _ofstream; }; diff --git a/include/c11log/sinks/stdout_sinks.h b/include/c11log/sinks/stdout_sinks.h index 5787913f..81864a44 100644 --- a/include/c11log/sinks/stdout_sinks.h +++ b/include/c11log/sinks/stdout_sinks.h @@ -11,7 +11,7 @@ public: virtual ~ostream_sink() = default; protected: - virtual void sink_it_(const std::string& msg) override { + virtual void _sink_it(const std::string& msg) override { _ostream << msg; }