mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
TDB2::get
- Implemented high-level accessors for tasks, by ID and UUID. This permits full DOM implementation.
This commit is contained in:
parent
dab06f8672
commit
60ca284e3a
2 changed files with 77 additions and 0 deletions
72
src/TDB2.cpp
72
src/TDB2.cpp
|
@ -555,6 +555,78 @@ int TDB2::next_id ()
|
|||
return _id++;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Locate task by ID.
|
||||
bool TDB2::get (int id, Task& task)
|
||||
{
|
||||
// First load and scan pending.
|
||||
if (! pending._loaded_tasks)
|
||||
pending.load_tasks ();
|
||||
|
||||
std::vector <Task>::iterator i;
|
||||
for (i = pending._tasks.begin (); i != pending._tasks.end (); ++i)
|
||||
{
|
||||
if (i->id == id)
|
||||
{
|
||||
task = *i;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Next load and scan completed.
|
||||
// Note that this is harmless, because it is only performed if the above
|
||||
// load and search fails.
|
||||
if (! completed._loaded_tasks)
|
||||
completed.load_tasks ();
|
||||
|
||||
for (i = completed._tasks.begin (); i != completed._tasks.end (); ++i)
|
||||
{
|
||||
if (i->id == id)
|
||||
{
|
||||
task = *i;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Locate task by UUID.
|
||||
bool TDB2::get (const std::string& uuid, Task& task)
|
||||
{
|
||||
// First load and scan pending.
|
||||
if (! pending._loaded_tasks)
|
||||
pending.load_tasks ();
|
||||
|
||||
std::vector <Task>::iterator i;
|
||||
for (i = pending._tasks.begin (); i != pending._tasks.end (); ++i)
|
||||
{
|
||||
if (i->get ("uuid") == uuid)
|
||||
{
|
||||
task = *i;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Next load and scan completed.
|
||||
// Note that this is harmless, because it is only performed if the above
|
||||
// load and search fails.
|
||||
if (! completed._loaded_tasks)
|
||||
completed.load_tasks ();
|
||||
|
||||
for (i = completed._tasks.begin (); i != completed._tasks.end (); ++i)
|
||||
{
|
||||
if (i->get ("uuid") == uuid)
|
||||
{
|
||||
task = *i;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool TDB2::verifyUniqueUUID (const std::string& uuid)
|
||||
{
|
||||
|
|
|
@ -59,6 +59,7 @@ public:
|
|||
void load_lines ();
|
||||
void load_contents ();
|
||||
|
||||
// ID <--> UUID mapping.
|
||||
std::string uuid (int);
|
||||
int id (const std::string&);
|
||||
|
||||
|
@ -98,6 +99,10 @@ public:
|
|||
int gc ();
|
||||
int next_id ();
|
||||
|
||||
// Generalized task accessors.
|
||||
bool get (int, Task&);
|
||||
bool get (const std::string&, Task&);
|
||||
|
||||
void dump ();
|
||||
|
||||
private:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue