From d7da182450eea523d58baabff6d8bdc10f97bd10 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Wed, 10 Jun 2009 21:35:07 -0400 Subject: [PATCH] Code Cleanup - Renamed T2.h -> Task.h, T2.cpp -> Task.cpp. This permanently avoids the problem where g++ on OpenBSD 4.5 fails because of the T class, which probably conflicts with C++ templates. Who knows. --- src/Context.h | 4 +-- src/Makefile.am | 4 +-- src/TDB2.cpp | 10 +++---- src/TDB2.h | 8 +++--- src/{T2.cpp => Task.cpp} | 56 ++++++++++++++++++++-------------------- src/{T2.h => Task.h} | 14 +++++----- src/command.cpp | 4 +-- src/recur.cpp | 2 +- src/tests/Makefile | 2 +- src/tests/filt.t.cpp | 20 +++++++------- src/tests/subst.t.cpp | 4 +-- src/tests/t2.t.cpp | 38 +++++++++++++-------------- 12 files changed, 83 insertions(+), 83 deletions(-) rename src/{T2.cpp => Task.cpp} (92%) rename src/{T2.h => Task.h} (89%) diff --git a/src/Context.h b/src/Context.h index 5d3d6e0d8..14422fcbc 100644 --- a/src/Context.h +++ b/src/Context.h @@ -33,7 +33,7 @@ #include "Sequence.h" #include "Subst.h" #include "Cmd.h" -#include "T2.h" +#include "Task.h" #include "TDB2.h" #include "StringTable.h" @@ -64,7 +64,7 @@ public: Keymap keymap; Sequence sequence; Subst subst; - T2 task; + Task task; TDB2 tdb; StringTable stringtable; std::string program; diff --git a/src/Makefile.am b/src/Makefile.am index ab30e3973..c25530018 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,12 +1,12 @@ bin_PROGRAMS = task task_SOURCES = Att.cpp Cmd.cpp Config.cpp Context.cpp Date.cpp Duration.cpp \ Filter.cpp Grid.cpp Keymap.cpp Location.cpp Nibbler.cpp \ - Record.cpp Sequence.cpp StringTable.cpp Subst.cpp T2.cpp \ + Record.cpp Sequence.cpp StringTable.cpp Subst.cpp Task.cpp \ TDB2.cpp Table.cpp Timer.cpp color.cpp command.cpp edit.cpp \ import.cpp interactive.cpp parse.cpp recur.cpp report.cpp \ rules.cpp main.cpp text.cpp util.cpp \ Att.h Cmd.h Config.h Context.h Date.h Duration.h Filter.h \ Grid.h Keymap.h Location.h Nibbler.h Record.h Sequence.h \ - StringTable.h Subst.h T2.h TDB2.h Table.h Timer.h color.h \ + StringTable.h Subst.h Task.h TDB2.h Table.h Timer.h color.h \ i18n.h main.h text.h util.h \ T.cpp T.h TDB.cpp TDB.h diff --git a/src/TDB2.cpp b/src/TDB2.cpp index 5641f6607..c730b4659 100644 --- a/src/TDB2.cpp +++ b/src/TDB2.cpp @@ -154,7 +154,7 @@ void TDB2::unlock () //////////////////////////////////////////////////////////////////////////////// // Returns number of filtered tasks. -int TDB2::load (std::vector & tasks, Filter& filter) +int TDB2::load (std::vector & tasks, Filter& filter) { // Note: tasks.clear () is deliberately not called, to allow the combination // of multiple files. @@ -178,7 +178,7 @@ int TDB2::load (std::vector & tasks, Filter& filter) { // TODO Add hidden attribute indicating source? line[length - 1] = '\0'; // Kill \n - T2 task (line); + Task task (line); if (filter.pass (task)) tasks.push_back (task); } @@ -198,7 +198,7 @@ int TDB2::load (std::vector & tasks, Filter& filter) { // TODO Add hidden attribute indicating source? line[length - 1] = '\0'; // Kill \n - T2 task (line); + Task task (line); if (filter.pass (task)) tasks.push_back (task); } @@ -220,7 +220,7 @@ int TDB2::load (std::vector & tasks, Filter& filter) //////////////////////////////////////////////////////////////////////////////// // TODO Write to transaction log. -void TDB2::add (T2& after) +void TDB2::add (Task& after) { throw std::string ("unimplemented TDB2::add"); @@ -230,7 +230,7 @@ void TDB2::add (T2& after) //////////////////////////////////////////////////////////////////////////////// // TODO Write to transaction log. -void TDB2::update (T2& before, T2& after) +void TDB2::update (Task& before, Task& after) { throw std::string ("unimplemented TDB2::update"); } diff --git a/src/TDB2.h b/src/TDB2.h index 90c26bc21..95406e388 100644 --- a/src/TDB2.h +++ b/src/TDB2.h @@ -32,7 +32,7 @@ #include #include #include -#include +#include // Length of longest line. #define T_LINE_MAX 32768 @@ -50,9 +50,9 @@ public: void lock (bool lockFile = true); void unlock (); - int load (std::vector &, Filter&); - void add (T2&); - void update (T2&, T2&); + int load (std::vector &, Filter&); + void add (Task&); + void update (Task&, Task&); int commit (); void upgrade (); diff --git a/src/T2.cpp b/src/Task.cpp similarity index 92% rename from src/T2.cpp rename to src/Task.cpp index 56b0d2801..d520a1c91 100644 --- a/src/T2.cpp +++ b/src/Task.cpp @@ -28,12 +28,12 @@ #include #include #include "Nibbler.h" -#include "T2.h" +#include "Task.h" #include "text.h" #include "util.h" //////////////////////////////////////////////////////////////////////////////// -T2::T2 () +Task::Task () { // Each new task gets a uuid. set ("uuid", uuid ()); @@ -42,7 +42,7 @@ T2::T2 () //////////////////////////////////////////////////////////////////////////////// // Attempt an FF4 parse first, using Record::parse, and in the event of an error // try a legacy parse (F3, FF2). Note that FF1 is no longer supported. -T2::T2 (const std::string& input) +Task::Task (const std::string& input) { try { @@ -56,9 +56,9 @@ T2::T2 (const std::string& input) } //////////////////////////////////////////////////////////////////////////////// -T2& T2::operator= (const T2& other) +Task& Task::operator= (const Task& other) { - throw std::string ("unimplemented T2::operator="); + throw std::string ("unimplemented Task::operator="); if (this != &other) { sequence = other.sequence; @@ -69,12 +69,12 @@ T2& T2::operator= (const T2& other) } //////////////////////////////////////////////////////////////////////////////// -T2::~T2 () +Task::~Task () { } //////////////////////////////////////////////////////////////////////////////// -T2::status T2::textToStatus (const std::string& input) +Task::status Task::textToStatus (const std::string& input) { if (input == "pending") return pending; else if (input == "completed") return completed; @@ -85,7 +85,7 @@ T2::status T2::textToStatus (const std::string& input) } //////////////////////////////////////////////////////////////////////////////// -std::string T2::statusToText (T2::status s) +std::string Task::statusToText (Task::status s) { if (s == pending) return "pending"; else if (s == completed) return "completed"; @@ -96,19 +96,19 @@ std::string T2::statusToText (T2::status s) } //////////////////////////////////////////////////////////////////////////////// -T2::status T2::getStatus () +Task::status Task::getStatus () { return textToStatus (get ("status")); } //////////////////////////////////////////////////////////////////////////////// -void T2::setSatus (T2::status status) +void Task::setSatus (Task::status status) { set ("status", statusToText (status)); } //////////////////////////////////////////////////////////////////////////////// -void T2::parse (const std::string& line) +void Task::parse (const std::string& line) { try { @@ -124,7 +124,7 @@ void T2::parse (const std::string& line) //////////////////////////////////////////////////////////////////////////////// // Support FF2, FF3. // Thankfully FF1 is no longer supported. -void T2::legacyParse (const std::string& line) +void Task::legacyParse (const std::string& line) { switch (determineVersion (line)) { @@ -141,7 +141,7 @@ void T2::legacyParse (const std::string& line) { set ("uuid", line.substr (0, 36)); - T2::status status = line[37] == '+' ? completed + Task::status status = line[37] == '+' ? completed : line[37] == 'X' ? deleted : line[37] == 'r' ? recurring : pending; @@ -198,7 +198,7 @@ void T2::legacyParse (const std::string& line) { set ("uuid", line.substr (0, 36)); - T2::status status = line[37] == '+' ? completed + Task::status status = line[37] == '+' ? completed : line[37] == 'X' ? deleted : line[37] == 'r' ? recurring : pending; @@ -302,14 +302,14 @@ void T2::legacyParse (const std::string& line) } //////////////////////////////////////////////////////////////////////////////// -std::string T2::composeCSV () +std::string Task::composeCSV () { - throw std::string ("unimplemented T2::composeCSV"); + throw std::string ("unimplemented Task::composeCSV"); return ""; } //////////////////////////////////////////////////////////////////////////////// -void T2::getAnnotations (std::vector & annotations) const +void Task::getAnnotations (std::vector & annotations) const { annotations.clear (); @@ -320,7 +320,7 @@ void T2::getAnnotations (std::vector & annotations) const } //////////////////////////////////////////////////////////////////////////////// -void T2::setAnnotations (const std::vector & annotations) +void Task::setAnnotations (const std::vector & annotations) { // Erase old annotations. removeAnnotations (); @@ -334,7 +334,7 @@ void T2::setAnnotations (const std::vector & annotations) // The timestamp is part of the name: // annotation_1234567890:"..." // -void T2::addAnnotation (const std::string& description) +void Task::addAnnotation (const std::string& description) { std::stringstream s; s << "annotation_" << time (NULL); @@ -343,7 +343,7 @@ void T2::addAnnotation (const std::string& description) } //////////////////////////////////////////////////////////////////////////////// -void T2::removeAnnotations () +void Task::removeAnnotations () { // Erase old annotations. Record::iterator i; @@ -353,7 +353,7 @@ void T2::removeAnnotations () } //////////////////////////////////////////////////////////////////////////////// -int T2::getTagCount () +int Task::getTagCount () { std::vector tags; split (tags, get ("tags"), ','); @@ -362,7 +362,7 @@ int T2::getTagCount () } //////////////////////////////////////////////////////////////////////////////// -bool T2::hasTag (const std::string& tag) +bool Task::hasTag (const std::string& tag) { std::vector tags; split (tags, get ("tags"), ','); @@ -374,7 +374,7 @@ bool T2::hasTag (const std::string& tag) } //////////////////////////////////////////////////////////////////////////////// -void T2::addTag (const std::string& tag) +void Task::addTag (const std::string& tag) { std::vector tags; split (tags, get ("tags"), ','); @@ -389,7 +389,7 @@ void T2::addTag (const std::string& tag) } //////////////////////////////////////////////////////////////////////////////// -void T2::addTags (const std::vector & tags) +void Task::addTags (const std::vector & tags) { remove ("tags"); @@ -399,13 +399,13 @@ void T2::addTags (const std::vector & tags) } //////////////////////////////////////////////////////////////////////////////// -void T2::getTags (std::vector& tags) +void Task::getTags (std::vector& tags) { split (tags, get ("tags"), ','); } //////////////////////////////////////////////////////////////////////////////// -void T2::removeTag (const std::string& tag) +void Task::removeTag (const std::string& tag) { std::vector tags; split (tags, get ("tags"), ','); @@ -422,7 +422,7 @@ void T2::removeTag (const std::string& tag) } //////////////////////////////////////////////////////////////////////////////// -bool T2::valid () const +bool Task::valid () const { // TODO Verify until > due // TODO Verify entry < until, due, start, end @@ -431,7 +431,7 @@ bool T2::valid () const } //////////////////////////////////////////////////////////////////////////////// -int T2::determineVersion (const std::string& line) +int Task::determineVersion (const std::string& line) { // Version 2 looks like: // diff --git a/src/T2.h b/src/Task.h similarity index 89% rename from src/T2.h rename to src/Task.h index 3897a4e2b..50b05614d 100644 --- a/src/T2.h +++ b/src/Task.h @@ -24,21 +24,21 @@ // USA // //////////////////////////////////////////////////////////////////////////////// -#ifndef INCLUDED_T2 -#define INCLUDED_T2 +#ifndef INCLUDED_TASK +#define INCLUDED_TASK #include #include "Record.h" #include "Subst.h" #include "Sequence.h" -class T2 : public Record +class Task : public Record { public: - T2 (); // Default constructor - T2 (const std::string&); // Parse - T2& operator= (const T2&); // Assignment operator - ~T2 (); // Destructor + Task (); // Default constructor + Task (const std::string&); // Parse + Task& operator= (const Task&); // Assignment operator + ~Task (); // Destructor void parse (const std::string&); std::string composeCSV (); diff --git a/src/command.cpp b/src/command.cpp index a91e7d5ea..d20f52714 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -98,7 +98,7 @@ std::string handleProjects () context.filter.push_back (Att ("status", "pending")); - std::vector tasks; + std::vector tasks; context.tdb.lock (context.config.get ("locking", true)); int quantity = context.tdb.load (tasks, context.filter); context.tdb.unlock (); @@ -155,7 +155,7 @@ std::string handleTags () context.filter.push_back (Att ("status", "pending")); - std::vector tasks; + std::vector tasks; context.tdb.lock (context.config.get ("locking", true)); int quantity = context.tdb.load (tasks, context.filter); context.tdb.unlock (); diff --git a/src/recur.cpp b/src/recur.cpp index 8a1c0fd25..5ff8b9fa5 100644 --- a/src/recur.cpp +++ b/src/recur.cpp @@ -56,7 +56,7 @@ extern Context context; //////////////////////////////////////////////////////////////////////////////// // Scans all tasks, and for any recurring tasks, determines whether any new // child tasks need to be generated to fill gaps. -void handleRecurrence (std::vector & tasks) +void handleRecurrence (std::vector & tasks) { /* std::vector modified; diff --git a/src/tests/Makefile b/src/tests/Makefile index a814fde36..d0c0cff92 100644 --- a/src/tests/Makefile +++ b/src/tests/Makefile @@ -3,7 +3,7 @@ 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 = ../TDB.o ../TDB2.o ../T.o ../T2.o ../parse.o ../text.o ../Date.o \ +OBJECTS = ../TDB.o ../TDB2.o ../T.o ../Task.o ../parse.o ../text.o ../Date.o \ ../Duration.o ../util.o ../Config.o ../Sequence.o ../Att.o \ ../Record.o ../StringTable.o ../Subst.o ../Nibbler.o ../Location.o \ ../Filter.o ../Context.o ../Keymap.o ../Cmd.o ../command.o \ diff --git a/src/tests/filt.t.cpp b/src/tests/filt.t.cpp index 764bfc8b4..0f2272fb6 100644 --- a/src/tests/filt.t.cpp +++ b/src/tests/filt.t.cpp @@ -27,7 +27,7 @@ #include "main.h" #include "test.h" #include "Filter.h" -#include "T2.h" +#include "Task.h" Context context; @@ -42,8 +42,8 @@ int main (int argc, char** argv) f.push_back (Att ("name2", "value2")); test.is (f.size (), (size_t)2, "Filter created"); - // Create a T2 to match against. - T2 yes; + // Create a Task to match against. + Task yes; yes.set ("name1", "value1"); yes.set ("name2", "value2"); test.ok (f.pass (yes), "full match"); @@ -52,19 +52,19 @@ int main (int argc, char** argv) test.ok (f.pass (yes), "over match"); // Negative tests. - T2 no0; - test.notok (f.pass (no0), "no match against default T2"); + Task no0; + test.notok (f.pass (no0), "no match against default Task"); - T2 no1; + Task no1; no1.set ("name3", "value3"); - test.notok (f.pass (no1), "no match against mismatch T2"); + test.notok (f.pass (no1), "no match against mismatch Task"); - T2 partial; + Task partial; partial.set ("name1", "value1"); - test.notok (f.pass (partial), "no match against partial T2"); + test.notok (f.pass (partial), "no match against partial Task"); // Modifiers. - T2 mods; + Task mods; mods.set ("name", "value"); Att a ("name", "value"); diff --git a/src/tests/subst.t.cpp b/src/tests/subst.t.cpp index 635e52b3f..3b916ab6e 100644 --- a/src/tests/subst.t.cpp +++ b/src/tests/subst.t.cpp @@ -25,7 +25,7 @@ // //////////////////////////////////////////////////////////////////////////////// #include -#include +#include #include #include @@ -36,7 +36,7 @@ int main (int argc, char** argv) { UnitTest t (15); - T2 task; + Task task; task.set ("description", "one two three four"); Subst s; diff --git a/src/tests/t2.t.cpp b/src/tests/t2.t.cpp index d1b0602bf..c38112139 100644 --- a/src/tests/t2.t.cpp +++ b/src/tests/t2.t.cpp @@ -34,18 +34,18 @@ int main (int argc, char** argv) { UnitTest test (34); - test.is ((int)T2::textToStatus ("pending"), (int)T2::pending, "textToStatus pending"); - test.is ((int)T2::textToStatus ("completed"), (int)T2::completed, "textToStatus completed"); - test.is ((int)T2::textToStatus ("deleted"), (int)T2::deleted, "textToStatus deleted"); - test.is ((int)T2::textToStatus ("recurring"), (int)T2::recurring, "textToStatus recurring"); + test.is ((int)Task::textToStatus ("pending"), (int)Task::pending, "textToStatus pending"); + test.is ((int)Task::textToStatus ("completed"), (int)Task::completed, "textToStatus completed"); + test.is ((int)Task::textToStatus ("deleted"), (int)Task::deleted, "textToStatus deleted"); + test.is ((int)Task::textToStatus ("recurring"), (int)Task::recurring, "textToStatus recurring"); - test.is (T2::statusToText (T2::pending), "pending", "statusToText pending"); - test.is (T2::statusToText (T2::completed), "completed", "statusToText completed"); - test.is (T2::statusToText (T2::deleted), "deleted", "statusToText deleted"); - test.is (T2::statusToText (T2::recurring), "recurring", "statusToText recurring"); + test.is (Task::statusToText (Task::pending), "pending", "statusToText pending"); + test.is (Task::statusToText (Task::completed), "completed", "statusToText completed"); + test.is (Task::statusToText (Task::deleted), "deleted", "statusToText deleted"); + test.is (Task::statusToText (Task::recurring), "recurring", "statusToText recurring"); // Round-trip testing. - T2 t3; + Task t3; std::string before = t3.composeF4 (); t3.parse (before); std::string after = t3.composeF4 (); @@ -53,7 +53,7 @@ int main (int argc, char** argv) after = t3.composeF4 (); t3.parse (after); after = t3.composeF4 (); - test.is (before, after, "T2::composeF4 -> parse round trip 4 iterations"); + test.is (before, after, "Task::composeF4 -> parse round trip 4 iterations"); // Legacy Format 1 // [tags] [attributes] description\n @@ -64,7 +64,7 @@ int main (int argc, char** argv) "[att1:value1 att2:value2] " "Description"; bool good = true; - try { T2 ff1 (sample); } catch (...) { good = false; } + try { Task ff1 (sample); } catch (...) { good = false; } test.notok (good, "Support for ff1 removed"); // Legacy Format 2 @@ -74,7 +74,7 @@ int main (int argc, char** argv) "[tag1 tag2] " "[att1:value1 att2:value2] " "Description"; - T2 ff2 (sample); + Task ff2 (sample); std::string value = ff2.get ("uuid"); test.is (value, "00000000-0000-0000-0000-000000000000", "ff2 uuid"); value = ff2.get ("status"); @@ -96,7 +96,7 @@ int main (int argc, char** argv) "[tag1 tag2] " "[att1:value1 att2:value2] " "[123:ann1 456:ann2] Description"; - T2 ff3 (sample); + Task ff3 (sample); value = ff2.get ("uuid"); test.is (value, "00000000-0000-0000-0000-000000000000", "ff3 uuid"); value = ff2.get ("status"); @@ -121,7 +121,7 @@ int main (int argc, char** argv) "att2:\"value2\" " "description:\"Description\"" "]"; - T2 ff4 (sample); + Task ff4 (sample); value = ff2.get ("uuid"); test.is (value, "00000000-0000-0000-0000-000000000000", "ff4 uuid"); value = ff2.get ("status"); @@ -138,11 +138,11 @@ int main (int argc, char** argv) /* -T2::composeCSV -T2::id -T2::*Status -T2::*Tag* -T2::*Annotation* +Task::composeCSV +Task::id +Task::*Status +Task::*Tag* +Task::*Annotation* */