From 3b82be9c16858cafc144ed31cf148c65a25d49fd Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Wed, 3 Feb 2016 21:12:18 -0500 Subject: [PATCH] Filter: C++11 --- src/Filter.cpp | 20 ++++++-------------- src/Filter.h | 14 +++++++------- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/Filter.cpp b/src/Filter.cpp index e4f6114d1..2cb080a84 100644 --- a/src/Filter.cpp +++ b/src/Filter.cpp @@ -54,14 +54,6 @@ bool domSource (const std::string& identifier, Variant& value) return false; } -//////////////////////////////////////////////////////////////////////////////// -Filter::Filter () -: _startCount (0) -, _endCount (0) -, _safety (true) -{ -} - //////////////////////////////////////////////////////////////////////////////// // Take an input set of tasks and filter into a subset. void Filter::subset (const std::vector & input, std::vector & output) @@ -194,9 +186,9 @@ void Filter::subset (std::vector & output) } //////////////////////////////////////////////////////////////////////////////// -bool Filter::hasFilter () +bool Filter::hasFilter () const { - for (auto& a : context.cli2._args) + for (const auto& a : context.cli2._args) if (a.hasTag ("FILTER")) return true; @@ -207,7 +199,7 @@ bool Filter::hasFilter () // If the filter contains no 'or', 'xor' or 'not' operators, and only includes // status values 'pending', 'waiting' or 'recurring', then the filter is // guaranteed to only need data from pending.data. -bool Filter::pendingOnly () +bool Filter::pendingOnly () const { // When GC is off, there are no shortcuts. if (! context.config.getBoolean ("gc")) @@ -229,7 +221,7 @@ bool Filter::pendingOnly () int countXor = 0; int countNot = 0; - for (auto& a : context.cli2._args) + for (const auto& a : context.cli2._args) { if (a.hasTag ("FILTER")) { @@ -269,13 +261,13 @@ bool Filter::pendingOnly () //////////////////////////////////////////////////////////////////////////////// // Disaster avoidance mechanism. If a !READONLY has no filter, then it can cause // all tasks to be modified. This is usually not intended. -void Filter::safety () +void Filter::safety () const { if (_safety) { bool readonly = true; bool filter = false; - for (auto& a : context.cli2._args) + for (const auto& a : context.cli2._args) { if (a.hasTag ("CMD") && ! a.hasTag ("READONLY")) diff --git a/src/Filter.h b/src/Filter.h index e128d379d..604f06ab8 100644 --- a/src/Filter.h +++ b/src/Filter.h @@ -37,19 +37,19 @@ bool domSource (const std::string&, Variant&); class Filter { public: - Filter (); + Filter () = default; void subset (const std::vector &, std::vector &); void subset (std::vector &); - bool hasFilter (); - bool pendingOnly (); - void safety (); + bool hasFilter () const; + bool pendingOnly () const; + void safety () const; void disableSafety (); private: - int _startCount; - int _endCount; - bool _safety; + int _startCount {0}; + int _endCount {0}; + bool _safety {true}; }; #endif