From ddc38c399898e5d510c56e49a443c00ab1ed430d Mon Sep 17 00:00:00 2001 From: Shamari Campbell Date: Sun, 16 Dec 2018 23:43:39 +0000 Subject: [PATCH] Issue 362 Here are some small changes from CPPCheck and also in some places I seen that some parameters could be declared const as they are not being changed. --- include/nana/datetime.hpp | 6 +++--- include/nana/gui/detail/drawer.hpp | 2 +- include/nana/gui/effects.hpp | 2 +- source/datetime.cpp | 13 ++++++++----- source/gui/detail/drawer.cpp | 9 +++++---- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/include/nana/datetime.hpp b/include/nana/datetime.hpp index b6678226..3abe9500 100644 --- a/include/nana/datetime.hpp +++ b/include/nana/datetime.hpp @@ -27,7 +27,7 @@ namespace nana }; date(); ///< the initialized date is today. - date(const std::tm&); + explicit date(const std::tm&); date(int year, int month, int day); date operator - (int off) const; @@ -44,8 +44,8 @@ namespace nana void set(const std::tm&); static int day_of_week(int year, int month, int day); - static unsigned year_days(unsigned year); ///< the number of days in the specified year. - static unsigned month_days(unsigned year, unsigned month); ///< the number of days in the specified month. + static unsigned year_days(const unsigned year); ///< the number of days in the specified year. + static unsigned month_days(const unsigned year, const unsigned month); ///< the number of days in the specified month. static unsigned day_in_year(unsigned y, unsigned m, unsigned d); ///< Returns the index of the specified day in this year, at range[1, 365] or [1, 366] private: date _m_add(unsigned x) const; diff --git a/include/nana/gui/detail/drawer.hpp b/include/nana/gui/detail/drawer.hpp index 63cea67f..7c20db17 100644 --- a/include/nana/gui/detail/drawer.hpp +++ b/include/nana/gui/detail/drawer.hpp @@ -91,7 +91,7 @@ namespace nana virtual void shortkey(graph_reference, const arg_keyboard&); void filter_event(const event_code evt_code, const bool bDisabled); - void filter_event(const std::vector evt_codes, const bool bDisabled); + void filter_event(const std::vector& evt_codes, const bool bDisabled); void filter_event(const event_filter_status& evt_all_states); bool filter_event(const event_code evt_code); event_filter_status filter_event(); diff --git a/include/nana/gui/effects.hpp b/include/nana/gui/effects.hpp index 3825c07a..c7a8f0a4 100644 --- a/include/nana/gui/effects.hpp +++ b/include/nana/gui/effects.hpp @@ -45,7 +45,7 @@ namespace nana : public bground_factory_interface { public: - bground_transparent(std::size_t percent); + explicit bground_transparent(std::size_t percent); private: bground_interface* create() const override; private: diff --git a/source/datetime.cpp b/source/datetime.cpp index d633090d..9911dd1d 100644 --- a/source/datetime.cpp +++ b/source/datetime.cpp @@ -15,6 +15,7 @@ #include #endif #include +#include namespace { std::tm localtime() @@ -239,18 +240,20 @@ namespace nana return days + d; } - unsigned date::month_days(unsigned year, unsigned month) + unsigned date::month_days(const unsigned year, const unsigned month) { - unsigned num[] = {31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; - if(month != 2) - return num[month - 1]; + if (month != 2) + { + const std::array days_in_month = { 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; + return days_in_month[month - 1]; + } if(((year % 4 == 0) && (year % 100)) || (year % 400 == 0)) return 29; return 28; } - unsigned date::year_days(unsigned year) + unsigned date::year_days(const unsigned year) { if(((year % 4 == 0) && (year % 100)) || (year % 400 == 0)) return 366; diff --git a/source/gui/detail/drawer.cpp b/source/gui/detail/drawer.cpp index e6b9108a..08e31cba 100644 --- a/source/gui/detail/drawer.cpp +++ b/source/gui/detail/drawer.cpp @@ -136,11 +136,12 @@ namespace nana evt_disabled_ &= ~(1 << static_cast(evt_code)); // clear } - void drawer_trigger::filter_event(const std::vector evt_codes, const bool bDisabled) + void drawer_trigger::filter_event(const std::vector& evt_codes, const bool bDisabled) { - const auto it_end = evt_codes.end(); - for (auto it = evt_codes.begin(); it != it_end; it++) - filter_event(*it, bDisabled); + for (const auto& evt_code : evt_codes) + { + filter_event(evt_code, bDisabled); + } } void drawer_trigger::filter_event(const event_filter_status& evt_all_states)