Integration - removing T

- Removed linkage to T.o in unit tests.  The first step towards
  eliminating T.cpp.
This commit is contained in:
Paul Beckingham 2009-06-13 18:53:01 -04:00
parent 841958d889
commit c89a222c7c
7 changed files with 116 additions and 170 deletions

View file

@ -122,41 +122,44 @@ void Subst::apply (
{ {
std::string::size_type pattern; std::string::size_type pattern;
if (mGlobal) if (mFrom != "")
{ {
// Perform all subs on description. if (mGlobal)
while ((pattern = description.find (mFrom)) != std::string::npos)
description.replace (pattern, mFrom.length (), mTo);
// Perform all subs on annotations.
std::vector <Att>::iterator i;
for (i = annotations.begin (); i != annotations.end (); ++i)
{ {
std::string description = i->value (); // Perform all subs on description.
while ((pattern = description.find (mFrom)) != std::string::npos) while ((pattern = description.find (mFrom)) != std::string::npos)
{
description.replace (pattern, mFrom.length (), mTo); 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. // Perform all subs on annotations.
else
{
std::vector <Att>::iterator i; std::vector <Att>::iterator i;
for (i = annotations.begin (); i != annotations.end (); ++i) for (i = annotations.begin (); i != annotations.end (); ++i)
{ {
std::string description = i->value (); 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); 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 <Att>::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;
}
} }
} }
} }

View file

@ -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.set ("description",
task.getDescription () + task.get ("description") + " " + delta.get ("description"));
" " +
delta.getDescription ());
return 1; 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; 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; int changes = 0;
@ -1023,6 +1020,8 @@ int deltaTags (T& task, T& delta)
++changes; ++changes;
} }
/*
// TODO Needs Task::getRemoveTags
delta.getRemoveTags (tags); delta.getRemoveTags (tags);
for (unsigned int i = 0; i < tags.size (); ++i) for (unsigned int i = 0; i < tags.size (); ++i)
{ {
@ -1033,23 +1032,22 @@ int deltaTags (T& task, T& delta)
++changes; ++changes;
} }
*/
return changes; return changes;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int deltaAttributes (T& task, T& delta) int deltaAttributes (Task& task, Task& delta)
{ {
int changes = 0; int changes = 0;
std::map <std::string, std::string> attributes; foreach (att, delta)
delta.getAttributes (attributes);
foreach (i, attributes)
{ {
if (i->second == "") if (att->second.value () == "")
task.removeAttribute (i->first); task.remove (att->first);
else else
task.setAttribute (i->first, i->second); task.set (att->first, att->second.value ());
++changes; ++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 description = task.get ("description");
std::string from; std::vector <Att> annotations;
std::string to; task.getAnnotations (annotations);
bool global;
delta.getSubstitution (from, to, global);
if (from != "") context.subst.apply (description, annotations);
{
std::string description = task.getDescription ();
size_t pattern;
if (global) task.set ("description", description);
{ task.setAnnotations (annotations);
// Perform all subs on description.
while ((pattern = description.find (from)) != std::string::npos)
{
description.replace (pattern, from.length (), to);
++changes;
}
task.setDescription (description); return 1;
// Perform all subs on annotations.
std::map <time_t, std::string> annotations;
task.getAnnotations (annotations);
std::map <time_t, std::string>::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 <time_t, std::string> annotations;
task.getAnnotations (annotations);
std::map <time_t, std::string>::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;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View file

@ -42,16 +42,16 @@ void validSortColumns (const std::vector <std::string>&, const std::vector <std:
bool validTag (const std::string&); bool validTag (const std::string&);
// task.cpp // task.cpp
void gatherNextTasks (/*const TDB&,*/ T&, std::vector <T>&, std::vector <int>&); void gatherNextTasks (/*const TDB&,*/ Task&, std::vector <Task>&, std::vector <int>&);
void onChangeCallback (); void onChangeCallback ();
// recur.cpp // recur.cpp
void handleRecurrence (); void handleRecurrence ();
Date getNextRecurrence (Date&, std::string&); Date getNextRecurrence (Date&, std::string&);
bool generateDueDates (T&, std::vector <Date>&); bool generateDueDates (Task&, std::vector <Date>&);
void updateRecurrenceMask (/*TDB&,*/ std::vector <T>&, T&); void updateRecurrenceMask (/*TDB&,*/ std::vector <T>&, Task&);
int getDueState (const std::string&); int getDueState (const std::string&);
void nag (/*TDB&,*/ T&); void nag (/*TDB&,*/ Task&);
// command.cpp // command.cpp
std::string handleAdd (); std::string handleAdd ();
@ -70,11 +70,11 @@ std::string handleUndo ();
std::string handleColor (); std::string handleColor ();
std::string handleAnnotate (); std::string handleAnnotate ();
std::string handleDuplicate (); std::string handleDuplicate ();
int deltaAppend (T&, T&); int deltaAppend (Task&, Task&);
int deltaDescription (T&, T&); int deltaDescription (Task&, Task&);
int deltaTags (T&, T&); int deltaTags (Task&, Task&);
int deltaAttributes (T&, T&); int deltaAttributes (Task&, Task&);
int deltaSubstitutions (T&, T&); int deltaSubstitutions (Task&, Task&);
// edit.cpp // edit.cpp
std::string handleEdit (); std::string handleEdit ();

View file

@ -141,17 +141,17 @@ void handleRecurrence (std::vector <Task>& tasks)
// period (recur). Then generate a set of corresponding dates. // period (recur). Then generate a set of corresponding dates.
// //
// Returns false if the parent recurring task is depleted. // Returns false if the parent recurring task is depleted.
bool generateDueDates (T& parent, std::vector <Date>& allDue) bool generateDueDates (Task& parent, std::vector <Date>& allDue)
{ {
// Determine due date, recur period and until date. // Determine due date, recur period and until date.
Date due (atoi (parent.getAttribute ("due").c_str ())); Date due (atoi (parent.get ("due").c_str ()));
std::string recur = parent.getAttribute ("recur"); std::string recur = parent.get ("recur");
bool specificEnd = false; bool specificEnd = false;
Date until; 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; specificEnd = true;
} }
@ -165,7 +165,7 @@ bool generateDueDates (T& parent, std::vector <Date>& allDue)
// If i > until, it means there are no more tasks to generate, and if the // 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 // parent mask contains all + or X, then there never will be another task
// to generate, and this parent task may be safely reaped. // 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 () && if (mask.length () == allDue.size () &&
mask.find ('-') == std::string::npos) mask.find ('-') == std::string::npos)
return false; return false;

View file

@ -1464,7 +1464,7 @@ std::string renderMonths (
int firstMonth, int firstMonth,
int firstYear, int firstYear,
const Date& today, const Date& today,
std::vector <T>& all, std::vector <Task>& all,
int monthsPerLine) int monthsPerLine)
{ {
Table table; Table table;
@ -1593,10 +1593,10 @@ std::string renderMonths (
today.year () == years.at (mpl)) today.year () == years.at (mpl))
table.setCellFg (row, thisCol, Text::cyan); table.setCellFg (row, thisCol, Text::cyan);
std::vector <T>::iterator it; std::vector <Task>::iterator it;
for (it = all.begin (); it != all.end (); ++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)) && if ((context.config.get ("color", true) || context.config.get (std::string ("_forcecolor"), false)) &&
due.day () == d && due.day () == d &&
@ -1932,8 +1932,8 @@ std::string handleReportStats ()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void gatherNextTasks ( void gatherNextTasks (
// const TDB& tdb, // const TDB& tdb,
T& task, Task& task,
std::vector <T>& pending, std::vector <Task>& pending,
std::vector <int>& all) std::vector <int>& all)
{ {
// For counting tasks by project. // For counting tasks by project.
@ -1948,15 +1948,14 @@ void gatherNextTasks (
// due:< 1wk, pri:* // due:< 1wk, pri:*
for (unsigned int i = 0; i < pending.size (); ++i) 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 (pending[i].has ("due"))
if (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 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 ()) if (countByProject[project] < limit && matching.find (i) == matching.end ())
{ {
++countByProject[project]; ++countByProject[project];
@ -1970,15 +1969,14 @@ void gatherNextTasks (
// due:*, pri:H // due:*, pri:H
for (unsigned int i = 0; i < pending.size (); ++i) 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 (pending[i].has ("due"))
if (due != "")
{ {
std::string priority = pending[i].getAttribute ("priority"); std::string priority = pending[i].get ("priority");
if (priority == "H") 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 ()) if (countByProject[project] < limit && matching.find (i) == matching.end ())
{ {
++countByProject[project]; ++countByProject[project];
@ -1992,12 +1990,12 @@ void gatherNextTasks (
// pri:H // pri:H
for (unsigned int i = 0; i < pending.size (); ++i) 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") 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 ()) if (countByProject[project] < limit && matching.find (i) == matching.end ())
{ {
++countByProject[project]; ++countByProject[project];
@ -2010,15 +2008,14 @@ void gatherNextTasks (
// due:*, pri:M // due:*, pri:M
for (unsigned int i = 0; i < pending.size (); ++i) 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 (pending[i].has ("due"))
if (due != "")
{ {
std::string priority = pending[i].getAttribute ("priority"); std::string priority = pending[i].get ("priority");
if (priority == "M") 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 ()) if (countByProject[project] < limit && matching.find (i) == matching.end ())
{ {
++countByProject[project]; ++countByProject[project];
@ -2032,12 +2029,12 @@ void gatherNextTasks (
// pri:M // pri:M
for (unsigned int i = 0; i < pending.size (); ++i) 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") 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 ()) if (countByProject[project] < limit && matching.find (i) == matching.end ())
{ {
++countByProject[project]; ++countByProject[project];
@ -2050,15 +2047,14 @@ void gatherNextTasks (
// due:*, pri:L // due:*, pri:L
for (unsigned int i = 0; i < pending.size (); ++i) 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 (pending[i].has ("due"))
if (due != "")
{ {
std::string priority = pending[i].getAttribute ("priority"); std::string priority = pending[i].get ("priority");
if (priority == "L") 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 ()) if (countByProject[project] < limit && matching.find (i) == matching.end ())
{ {
++countByProject[project]; ++countByProject[project];
@ -2072,12 +2068,12 @@ void gatherNextTasks (
// pri:L // pri:L
for (unsigned int i = 0; i < pending.size (); ++i) 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") 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 ()) if (countByProject[project] < limit && matching.find (i) == matching.end ())
{ {
++countByProject[project]; ++countByProject[project];
@ -2090,15 +2086,14 @@ void gatherNextTasks (
// due:, pri: // due:, pri:
for (unsigned int i = 0; i < pending.size (); ++i) 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 (pending[i].has ("due"))
if (due == "")
{ {
std::string priority = pending[i].getAttribute ("priority"); std::string priority = pending[i].get ("priority");
if (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 ()) if (countByProject[project] < limit && matching.find (i) == matching.end ())
{ {
++countByProject[project]; ++countByProject[project];

View file

@ -3,7 +3,7 @@ PROJECT = t2.t tdb.t date.t duration.t t.benchmark.t text.t autocomplete.t \
cmd.t cmd.t
CFLAGS = -I. -I.. -Wall -pedantic -ggdb3 -fno-rtti CFLAGS = -I. -I.. -Wall -pedantic -ggdb3 -fno-rtti
LFLAGS = -L/usr/local/lib -lncurses 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 \ ../Duration.o ../util.o ../Config.o ../Sequence.o ../Att.o ../Cmd.o \
../Record.o ../StringTable.o ../Subst.o ../Nibbler.o ../Location.o \ ../Record.o ../StringTable.o ../Subst.o ../Nibbler.o ../Location.o \
../Filter.o ../Context.o ../Keymap.o ../command.o ../interactive.o \ ../Filter.o ../Context.o ../Keymap.o ../command.o ../interactive.o \

View file

@ -25,7 +25,7 @@
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#include <sys/time.h> #include <sys/time.h>
#include "T.h" #include "Task.h"
#include "main.h" #include "main.h"
#include "test.h" #include "test.h"
@ -36,11 +36,19 @@ int main (int argc, char** argv)
{ {
UnitTest test (1); UnitTest test (1);
std::string sample = "d346065c-7ef6-49af-ae77-19c1825807f5 " // FF4 parsing is being tested. Performance of legacy format parsing is
"- " // immaterial.
"[bug performance solaris linux osx] " std::string sample = "["
"[due:1236142800 entry:1236177552 priority:H project:task-1.5.0 start:1236231761] " "uuid:\"d346065c-7ef6-49af-ae77-19c1825807f5\" "
"Profile task and identify performance bottlenecks"; "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 // Start clock
test.diag ("start"); test.diag ("start");
@ -49,7 +57,7 @@ int main (int argc, char** argv)
for (int i = 0; i < 1000000; i++) for (int i = 0; i < 1000000; i++)
{ {
T t (sample); Task t (sample);
} }
// End clock // End clock