mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Filter: C++11
This commit is contained in:
parent
cdd1c4681d
commit
3b82be9c16
2 changed files with 13 additions and 21 deletions
|
@ -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 <Task>& input, std::vector <Task>& output)
|
||||
|
@ -194,9 +186,9 @@ void Filter::subset (std::vector <Task>& 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"))
|
||||
|
|
14
src/Filter.h
14
src/Filter.h
|
@ -37,19 +37,19 @@ bool domSource (const std::string&, Variant&);
|
|||
class Filter
|
||||
{
|
||||
public:
|
||||
Filter ();
|
||||
Filter () = default;
|
||||
|
||||
void subset (const std::vector <Task>&, std::vector <Task>&);
|
||||
void subset (std::vector <Task>&);
|
||||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue