From c89a222c7cdcf6d6f9bc4e0ab7de7d8aaf07ac78 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 13 Jun 2009 18:53:01 -0400 Subject: [PATCH] Integration - removing T - Removed linkage to T.o in unit tests. The first step towards eliminating T.cpp. --- src/Subst.cpp | 51 +++++++++-------- src/command.cpp | 108 ++++++++---------------------------- src/main.h | 18 +++--- src/recur.cpp | 12 ++-- src/report.cpp | 73 ++++++++++++------------ src/tests/Makefile | 2 +- src/tests/t.benchmark.t.cpp | 22 +++++--- 7 files changed, 116 insertions(+), 170 deletions(-) diff --git a/src/Subst.cpp b/src/Subst.cpp index a2f83bec1..4dd02a6c1 100644 --- a/src/Subst.cpp +++ b/src/Subst.cpp @@ -122,41 +122,44 @@ void Subst::apply ( { std::string::size_type pattern; - if (mGlobal) + if (mFrom != "") { - // Perform all subs on description. - while ((pattern = description.find (mFrom)) != std::string::npos) - description.replace (pattern, mFrom.length (), mTo); - - // Perform all subs on annotations. - std::vector ::iterator i; - for (i = annotations.begin (); i != annotations.end (); ++i) + if (mGlobal) { - std::string description = i->value (); + // Perform all subs on description. while ((pattern = description.find (mFrom)) != std::string::npos) - { description.replace (pattern, mFrom.length (), mTo); - i->value (description); - } - } - } - else - { - // Perform first description substitution. - if ((pattern = description.find (mFrom)) != std::string::npos) - description.replace (pattern, mFrom.length (), mTo); - // Failing that, perform the first annotation substitution. - else - { + // Perform all subs on annotations. std::vector ::iterator i; for (i = annotations.begin (); i != annotations.end (); ++i) { std::string description = i->value (); - if ((pattern = description.find (mFrom)) != std::string::npos) + while ((pattern = description.find (mFrom)) != std::string::npos) { description.replace (pattern, mFrom.length (), mTo); - break; + i->value (description); + } + } + } + else + { + // Perform first description substitution. + if ((pattern = description.find (mFrom)) != std::string::npos) + description.replace (pattern, mFrom.length (), mTo); + + // Failing that, perform the first annotation substitution. + else + { + std::vector ::iterator i; + for (i = annotations.begin (); i != annotations.end (); ++i) + { + std::string description = i->value (); + if ((pattern = description.find (mFrom)) != std::string::npos) + { + description.replace (pattern, mFrom.length (), mTo); + break; + } } } } diff --git a/src/command.cpp b/src/command.cpp index d36bf79ae..4636d0fb1 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -978,15 +978,12 @@ std::string handleAnnotate () } //////////////////////////////////////////////////////////////////////////////// -int deltaAppend (T& task, T& delta) +int deltaAppend (Task& task, Task& delta) { - if (delta.getDescription () != "") + if (delta.has ("description")) { - task.setDescription ( - task.getDescription () + - " " + - delta.getDescription ()); - + task.set ("description", + task.get ("description") + " " + delta.get ("description")); return 1; } @@ -994,11 +991,11 @@ int deltaAppend (T& task, T& delta) } //////////////////////////////////////////////////////////////////////////////// -int deltaDescription (T& task, T& delta) +int deltaDescription (Task& task, Task& delta) { - if (delta.getDescription () != "") + if (delta.has ("description")) { - task.setDescription (delta.getDescription ()); + task.set ("description", delta.get ("description")); return 1; } @@ -1006,7 +1003,7 @@ int deltaDescription (T& task, T& delta) } //////////////////////////////////////////////////////////////////////////////// -int deltaTags (T& task, T& delta) +int deltaTags (Task& task, Task& delta) { int changes = 0; @@ -1023,6 +1020,8 @@ int deltaTags (T& task, T& delta) ++changes; } +/* + // TODO Needs Task::getRemoveTags delta.getRemoveTags (tags); for (unsigned int i = 0; i < tags.size (); ++i) { @@ -1033,23 +1032,22 @@ int deltaTags (T& task, T& delta) ++changes; } +*/ return changes; } //////////////////////////////////////////////////////////////////////////////// -int deltaAttributes (T& task, T& delta) +int deltaAttributes (Task& task, Task& delta) { int changes = 0; - std::map attributes; - delta.getAttributes (attributes); - foreach (i, attributes) + foreach (att, delta) { - if (i->second == "") - task.removeAttribute (i->first); + if (att->second.value () == "") + task.remove (att->first); else - task.setAttribute (i->first, i->second); + task.set (att->first, att->second.value ()); ++changes; } @@ -1058,76 +1056,18 @@ int deltaAttributes (T& task, T& delta) } //////////////////////////////////////////////////////////////////////////////// -int deltaSubstitutions (T& task, T& delta) +int deltaSubstitutions (Task& task, Task& delta) { - int changes = 0; - std::string from; - std::string to; - bool global; - delta.getSubstitution (from, to, global); + std::string description = task.get ("description"); + std::vector annotations; + task.getAnnotations (annotations); - if (from != "") - { - std::string description = task.getDescription (); - size_t pattern; + context.subst.apply (description, annotations); - if (global) - { - // Perform all subs on description. - while ((pattern = description.find (from)) != std::string::npos) - { - description.replace (pattern, from.length (), to); - ++changes; - } + task.set ("description", description); + task.setAnnotations (annotations); - task.setDescription (description); - - // Perform all subs on annotations. - std::map annotations; - task.getAnnotations (annotations); - std::map ::iterator it; - for (it = annotations.begin (); it != annotations.end (); ++it) - { - while ((pattern = it->second.find (from)) != std::string::npos) - { - it->second.replace (pattern, from.length (), to); - ++changes; - } - } - - task.setAnnotations (annotations); - } - else - { - // Perform first description substitution. - if ((pattern = description.find (from)) != std::string::npos) - { - description.replace (pattern, from.length (), to); - task.setDescription (description); - ++changes; - } - // Failing that, perform the first annotation substitution. - else - { - std::map annotations; - task.getAnnotations (annotations); - - std::map ::iterator it; - for (it = annotations.begin (); it != annotations.end (); ++it) - { - if ((pattern = it->second.find (from)) != std::string::npos) - { - it->second.replace (pattern, from.length (), to); - ++changes; - break; - } - } - - task.setAnnotations (annotations); - } - } - } - return changes; + return 1; } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/main.h b/src/main.h index 294765b7b..a6da31399 100644 --- a/src/main.h +++ b/src/main.h @@ -42,16 +42,16 @@ void validSortColumns (const std::vector &, const std::vector &, std::vector &); +void gatherNextTasks (/*const TDB&,*/ Task&, std::vector &, std::vector &); void onChangeCallback (); // recur.cpp void handleRecurrence (); Date getNextRecurrence (Date&, std::string&); -bool generateDueDates (T&, std::vector &); -void updateRecurrenceMask (/*TDB&,*/ std::vector &, T&); +bool generateDueDates (Task&, std::vector &); +void updateRecurrenceMask (/*TDB&,*/ std::vector &, Task&); int getDueState (const std::string&); -void nag (/*TDB&,*/ T&); +void nag (/*TDB&,*/ Task&); // command.cpp std::string handleAdd (); @@ -70,11 +70,11 @@ std::string handleUndo (); std::string handleColor (); std::string handleAnnotate (); std::string handleDuplicate (); -int deltaAppend (T&, T&); -int deltaDescription (T&, T&); -int deltaTags (T&, T&); -int deltaAttributes (T&, T&); -int deltaSubstitutions (T&, T&); +int deltaAppend (Task&, Task&); +int deltaDescription (Task&, Task&); +int deltaTags (Task&, Task&); +int deltaAttributes (Task&, Task&); +int deltaSubstitutions (Task&, Task&); // edit.cpp std::string handleEdit (); diff --git a/src/recur.cpp b/src/recur.cpp index 67fd90da4..17a7801dd 100644 --- a/src/recur.cpp +++ b/src/recur.cpp @@ -141,17 +141,17 @@ void handleRecurrence (std::vector & tasks) // period (recur). Then generate a set of corresponding dates. // // Returns false if the parent recurring task is depleted. -bool generateDueDates (T& parent, std::vector & allDue) +bool generateDueDates (Task& parent, std::vector & allDue) { // Determine due date, recur period and until date. - Date due (atoi (parent.getAttribute ("due").c_str ())); - std::string recur = parent.getAttribute ("recur"); + Date due (atoi (parent.get ("due").c_str ())); + std::string recur = parent.get ("recur"); bool specificEnd = false; Date until; - if (parent.getAttribute ("until") != "") + if (parent.get ("until") != "") { - until = Date (atoi (parent.getAttribute ("until").c_str ())); + until = Date (atoi (parent.get ("until").c_str ())); specificEnd = true; } @@ -165,7 +165,7 @@ bool generateDueDates (T& parent, std::vector & allDue) // If i > until, it means there are no more tasks to generate, and if the // parent mask contains all + or X, then there never will be another task // to generate, and this parent task may be safely reaped. - std::string mask = parent.getAttribute ("mask"); + std::string mask = parent.get ("mask"); if (mask.length () == allDue.size () && mask.find ('-') == std::string::npos) return false; diff --git a/src/report.cpp b/src/report.cpp index 7ddcf12db..e8817d234 100644 --- a/src/report.cpp +++ b/src/report.cpp @@ -1464,7 +1464,7 @@ std::string renderMonths ( int firstMonth, int firstYear, const Date& today, - std::vector & all, + std::vector & all, int monthsPerLine) { Table table; @@ -1593,10 +1593,10 @@ std::string renderMonths ( today.year () == years.at (mpl)) table.setCellFg (row, thisCol, Text::cyan); - std::vector ::iterator it; + std::vector ::iterator it; for (it = all.begin (); it != all.end (); ++it) { - Date due (::atoi (it->getAttribute ("due").c_str ())); + Date due (::atoi (it->get ("due").c_str ())); if ((context.config.get ("color", true) || context.config.get (std::string ("_forcecolor"), false)) && due.day () == d && @@ -1932,8 +1932,8 @@ std::string handleReportStats () //////////////////////////////////////////////////////////////////////////////// void gatherNextTasks ( // const TDB& tdb, - T& task, - std::vector & pending, + Task& task, + std::vector & pending, std::vector & all) { // For counting tasks by project. @@ -1948,15 +1948,14 @@ void gatherNextTasks ( // due:< 1wk, pri:* for (unsigned int i = 0; i < pending.size (); ++i) { - if (pending[i].getStatus () == T::pending) + if (pending[i].getStatus () == Task::pending) { - std::string due = pending[i].getAttribute ("due"); - if (due != "") + if (pending[i].has ("due")) { - Date d (::atoi (due.c_str ())); + Date d (::atoi (pending[i].get ("due").c_str ())); if (d < now + (7 * 24 * 60 * 60)) // if due:< 1wk { - std::string project = pending[i].getAttribute ("project"); + std::string project = pending[i].get ("project"); if (countByProject[project] < limit && matching.find (i) == matching.end ()) { ++countByProject[project]; @@ -1970,15 +1969,14 @@ void gatherNextTasks ( // due:*, pri:H for (unsigned int i = 0; i < pending.size (); ++i) { - if (pending[i].getStatus () == T::pending) + if (pending[i].getStatus () == Task::pending) { - std::string due = pending[i].getAttribute ("due"); - if (due != "") + if (pending[i].has ("due")) { - std::string priority = pending[i].getAttribute ("priority"); + std::string priority = pending[i].get ("priority"); if (priority == "H") { - std::string project = pending[i].getAttribute ("project"); + std::string project = pending[i].get ("project"); if (countByProject[project] < limit && matching.find (i) == matching.end ()) { ++countByProject[project]; @@ -1992,12 +1990,12 @@ void gatherNextTasks ( // pri:H for (unsigned int i = 0; i < pending.size (); ++i) { - if (pending[i].getStatus () == T::pending) + if (pending[i].getStatus () == Task::pending) { - std::string priority = pending[i].getAttribute ("priority"); + std::string priority = pending[i].get ("priority"); if (priority == "H") { - std::string project = pending[i].getAttribute ("project"); + std::string project = pending[i].get ("project"); if (countByProject[project] < limit && matching.find (i) == matching.end ()) { ++countByProject[project]; @@ -2010,15 +2008,14 @@ void gatherNextTasks ( // due:*, pri:M for (unsigned int i = 0; i < pending.size (); ++i) { - if (pending[i].getStatus () == T::pending) + if (pending[i].getStatus () == Task::pending) { - std::string due = pending[i].getAttribute ("due"); - if (due != "") + if (pending[i].has ("due")) { - std::string priority = pending[i].getAttribute ("priority"); + std::string priority = pending[i].get ("priority"); if (priority == "M") { - std::string project = pending[i].getAttribute ("project"); + std::string project = pending[i].get ("project"); if (countByProject[project] < limit && matching.find (i) == matching.end ()) { ++countByProject[project]; @@ -2032,12 +2029,12 @@ void gatherNextTasks ( // pri:M for (unsigned int i = 0; i < pending.size (); ++i) { - if (pending[i].getStatus () == T::pending) + if (pending[i].getStatus () == Task::pending) { - std::string priority = pending[i].getAttribute ("priority"); + std::string priority = pending[i].get ("priority"); if (priority == "M") { - std::string project = pending[i].getAttribute ("project"); + std::string project = pending[i].get ("project"); if (countByProject[project] < limit && matching.find (i) == matching.end ()) { ++countByProject[project]; @@ -2050,15 +2047,14 @@ void gatherNextTasks ( // due:*, pri:L for (unsigned int i = 0; i < pending.size (); ++i) { - if (pending[i].getStatus () == T::pending) + if (pending[i].getStatus () == Task::pending) { - std::string due = pending[i].getAttribute ("due"); - if (due != "") + if (pending[i].has ("due")) { - std::string priority = pending[i].getAttribute ("priority"); + std::string priority = pending[i].get ("priority"); if (priority == "L") { - std::string project = pending[i].getAttribute ("project"); + std::string project = pending[i].get ("project"); if (countByProject[project] < limit && matching.find (i) == matching.end ()) { ++countByProject[project]; @@ -2072,12 +2068,12 @@ void gatherNextTasks ( // pri:L for (unsigned int i = 0; i < pending.size (); ++i) { - if (pending[i].getStatus () == T::pending) + if (pending[i].getStatus () == Task::pending) { - std::string priority = pending[i].getAttribute ("priority"); + std::string priority = pending[i].get ("priority"); if (priority == "L") { - std::string project = pending[i].getAttribute ("project"); + std::string project = pending[i].get ("project"); if (countByProject[project] < limit && matching.find (i) == matching.end ()) { ++countByProject[project]; @@ -2090,15 +2086,14 @@ void gatherNextTasks ( // due:, pri: for (unsigned int i = 0; i < pending.size (); ++i) { - if (pending[i].getStatus () == T::pending) + if (pending[i].getStatus () == Task::pending) { - std::string due = pending[i].getAttribute ("due"); - if (due == "") + if (pending[i].has ("due")) { - std::string priority = pending[i].getAttribute ("priority"); + std::string priority = pending[i].get ("priority"); if (priority == "") { - std::string project = pending[i].getAttribute ("project"); + std::string project = pending[i].get ("project"); if (countByProject[project] < limit && matching.find (i) == matching.end ()) { ++countByProject[project]; diff --git a/src/tests/Makefile b/src/tests/Makefile index 373360b8c..95c1f6d6f 100644 --- a/src/tests/Makefile +++ b/src/tests/Makefile @@ -3,7 +3,7 @@ PROJECT = t2.t tdb.t date.t duration.t t.benchmark.t text.t autocomplete.t \ cmd.t CFLAGS = -I. -I.. -Wall -pedantic -ggdb3 -fno-rtti LFLAGS = -L/usr/local/lib -lncurses -OBJECTS = ../TDB2.o ../T.o ../Task.o ../valid.o ../text.o ../Date.o ../Table.o \ +OBJECTS = ../TDB2.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 \ diff --git a/src/tests/t.benchmark.t.cpp b/src/tests/t.benchmark.t.cpp index a90a71b9c..5bb3b36a4 100644 --- a/src/tests/t.benchmark.t.cpp +++ b/src/tests/t.benchmark.t.cpp @@ -25,7 +25,7 @@ // //////////////////////////////////////////////////////////////////////////////// #include -#include "T.h" +#include "Task.h" #include "main.h" #include "test.h" @@ -36,11 +36,19 @@ int main (int argc, char** argv) { UnitTest test (1); - std::string sample = "d346065c-7ef6-49af-ae77-19c1825807f5 " - "- " - "[bug performance solaris linux osx] " - "[due:1236142800 entry:1236177552 priority:H project:task-1.5.0 start:1236231761] " - "Profile task and identify performance bottlenecks"; + // FF4 parsing is being tested. Performance of legacy format parsing is + // immaterial. + std::string sample = "[" + "uuid:\"d346065c-7ef6-49af-ae77-19c1825807f5\" " + "status:\"pending\" " + "tags:\"bug,performance,solaris,linux,osx\" " + "due:\"1236142800\" " + "entry:\"1236177552\" " + "priority:\"H\" " + "project:\"task-1.5.0\" " + "start:\"1236231761\" " + "description:\"Profile task and identify performance bottlenecks\"" + "]"; // Start clock test.diag ("start"); @@ -49,7 +57,7 @@ int main (int argc, char** argv) for (int i = 0; i < 1000000; i++) { - T t (sample); + Task t (sample); } // End clock