mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-19 09:53:08 +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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
Filter::Filter ()
|
|
||||||
: _startCount (0)
|
|
||||||
, _endCount (0)
|
|
||||||
, _safety (true)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Take an input set of tasks and filter into a subset.
|
// Take an input set of tasks and filter into a subset.
|
||||||
void Filter::subset (const std::vector <Task>& input, std::vector <Task>& output)
|
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"))
|
if (a.hasTag ("FILTER"))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
@ -207,7 +199,7 @@ bool Filter::hasFilter ()
|
||||||
// If the filter contains no 'or', 'xor' or 'not' operators, and only includes
|
// If the filter contains no 'or', 'xor' or 'not' operators, and only includes
|
||||||
// status values 'pending', 'waiting' or 'recurring', then the filter is
|
// status values 'pending', 'waiting' or 'recurring', then the filter is
|
||||||
// guaranteed to only need data from pending.data.
|
// guaranteed to only need data from pending.data.
|
||||||
bool Filter::pendingOnly ()
|
bool Filter::pendingOnly () const
|
||||||
{
|
{
|
||||||
// When GC is off, there are no shortcuts.
|
// When GC is off, there are no shortcuts.
|
||||||
if (! context.config.getBoolean ("gc"))
|
if (! context.config.getBoolean ("gc"))
|
||||||
|
@ -229,7 +221,7 @@ bool Filter::pendingOnly ()
|
||||||
int countXor = 0;
|
int countXor = 0;
|
||||||
int countNot = 0;
|
int countNot = 0;
|
||||||
|
|
||||||
for (auto& a : context.cli2._args)
|
for (const auto& a : context.cli2._args)
|
||||||
{
|
{
|
||||||
if (a.hasTag ("FILTER"))
|
if (a.hasTag ("FILTER"))
|
||||||
{
|
{
|
||||||
|
@ -269,13 +261,13 @@ bool Filter::pendingOnly ()
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Disaster avoidance mechanism. If a !READONLY has no filter, then it can cause
|
// Disaster avoidance mechanism. If a !READONLY has no filter, then it can cause
|
||||||
// all tasks to be modified. This is usually not intended.
|
// all tasks to be modified. This is usually not intended.
|
||||||
void Filter::safety ()
|
void Filter::safety () const
|
||||||
{
|
{
|
||||||
if (_safety)
|
if (_safety)
|
||||||
{
|
{
|
||||||
bool readonly = true;
|
bool readonly = true;
|
||||||
bool filter = false;
|
bool filter = false;
|
||||||
for (auto& a : context.cli2._args)
|
for (const auto& a : context.cli2._args)
|
||||||
{
|
{
|
||||||
if (a.hasTag ("CMD") &&
|
if (a.hasTag ("CMD") &&
|
||||||
! a.hasTag ("READONLY"))
|
! a.hasTag ("READONLY"))
|
||||||
|
|
14
src/Filter.h
14
src/Filter.h
|
@ -37,19 +37,19 @@ bool domSource (const std::string&, Variant&);
|
||||||
class Filter
|
class Filter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Filter ();
|
Filter () = default;
|
||||||
|
|
||||||
void subset (const std::vector <Task>&, std::vector <Task>&);
|
void subset (const std::vector <Task>&, std::vector <Task>&);
|
||||||
void subset (std::vector <Task>&);
|
void subset (std::vector <Task>&);
|
||||||
bool hasFilter ();
|
bool hasFilter () const;
|
||||||
bool pendingOnly ();
|
bool pendingOnly () const;
|
||||||
void safety ();
|
void safety () const;
|
||||||
void disableSafety ();
|
void disableSafety ();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int _startCount;
|
int _startCount {0};
|
||||||
int _endCount;
|
int _endCount {0};
|
||||||
bool _safety;
|
bool _safety {true};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue