Enhancements - TDB2::gc

- Stubbed TDB2::gc.
- Fixed broken tests Makefile
- Added handleCustomReport call to Context dispatch.
This commit is contained in:
Paul Beckingham 2009-06-11 21:17:30 -04:00
parent edd065d80e
commit 37e08df8ba
4 changed files with 56 additions and 10 deletions

View file

@ -151,9 +151,12 @@ int Context::run ()
////////////////////////////////////////////////////////////////////////////////
std::string Context::dispatch ()
{
bool gc = true; // TODO Should be false for shadow file updates.
bool gcMod = false; // Change occurred by way of gc.
bool cmdMod = false; // Change occurred by way of command type.
std::string out;
/*
// Read-only commands with no side effects.
if (command == "export") { out = handleExport (); }
@ -192,18 +195,19 @@ std::string Context::dispatch ()
// Command that display IDs and therefore need TDB::gc first.
/*
else if (command == "completed") { if (gc) gcMod = tdb.gc (); out = handleCompleted (); }
else if (command == "completed") { if (gc) gcMod = tdb.gc (); out = handleCompleted (); } // TODO OBSOLETE
else if (command == "next") { if (gc) gcMod = tdb.gc (); out = handleReportNext (); }
else if (command == "active") { if (gc) gcMod = tdb.gc (); out = handleReportActive (); }
else if (command == "overdue") { if (gc) gcMod = tdb.gc (); out = handleReportOverdue (); }
else if (cmd.validCustom (command)) { if (gc) gcMod = tdb.gc (); out = handleCustomReport (command); }
else if (command == "active") { if (gc) gcMod = tdb.gc (); out = handleReportActive (); } // TODO OBSOLETE
else if (command == "overdue") { if (gc) gcMod = tdb.gc (); out = handleReportOverdue (); } // TODO OBSOLETE
*/
else if (cmd.validCustom (cmd.command)) { if (gc) gcMod = tdb.gc (); out = handleCustomReport (cmd.command); }
// If the command is not recognized, display usage.
else { out = shortUsage (); }
// Only update the shadow file if such an update was not suppressed (shadow),
// and if an actual change occurred (gcMod || cmdMod).
// TODO
// if (shadow && (gcMod || cmdMod))
// shadow ();

View file

@ -282,6 +282,46 @@ void TDB2::upgrade ()
throw std::string ("unimplemented TDB2::upgrade");
}
////////////////////////////////////////////////////////////////////////////////
// Scans the pending tasks for any that are completed or deleted, and if so,
// moves them to the completed.data file. Returns a count of tasks moved.
int TDB2::gc ()
{
int count = 0;
/*
// Read everything from the pending file.
std::vector <T> all;
allPendingT (all);
// A list of the truly pending tasks.
std::vector <T> pending;
std::vector<T>::iterator it;
for (it = all.begin (); it != all.end (); ++it)
{
// Some tasks stay in the pending file.
if (it->getStatus () == T::pending ||
it->getStatus () == T::recurring)
{
pending.push_back (*it);
}
// Others are transferred to the completed file.
else
{
writeCompleted (*it);
++count;
}
}
// Dump all clean tasks into pending. But don't bother unless at least one
// task was transferred.
if (count)
overwritePending (pending);
*/
return count;
}
////////////////////////////////////////////////////////////////////////////////
FILE* TDB2::openAndLock (const std::string& file)
{

View file

@ -52,10 +52,12 @@ public:
int load (std::vector <Task>&, Filter&);
int loadPending (std::vector <Task>&, Filter&);
int loadCompleted (std::vector <Task>&, Filter&);
void add (Task&);
void update (Task&, Task&);
int commit ();
void upgrade ();
void add (Task&); // Single task add to pending
void update (Task&, Task&); // Single task update to pending
int commit (); // Write out all tasks
void upgrade (); // Convert both files to FF4
int gc (); // Clean up pending
private:
FILE* openAndLock (const std::string&);

View file

@ -3,11 +3,11 @@ PROJECT = t.t t2.t tdb.t date.t duration.t t.benchmark.t text.t autocomplete.t \
cmd.t config.t
CFLAGS = -I. -I.. -Wall -pedantic -ggdb3 -fno-rtti
LFLAGS = -L/usr/local/lib -lncurses
OBJECTS = ../TDB2.o ../T.o ../Task.o ../parse.o ../text.o ../Date.o ../Table.o \
OBJECTS = ../TDB2.o ../T.o ../Task.o ../valid.o ../text.o ../Date.o ../Table.o \
../Duration.o ../util.o ../Config.o ../Sequence.o ../Att.o ../Cmd.o \
../Record.o ../StringTable.o ../Subst.o ../Nibbler.o ../Location.o \
../Filter.o ../Context.o ../Keymap.o ../command.o ../interactive.o \
../report.o ../Grid.o ../color.o ../rules.o ../recur.o
../report.o ../Grid.o ../color.o ../rules.o ../recur.o ../custom.o
all: $(PROJECT)