mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Integration - removing T
- Removed linkage to T.o in unit tests. The first step towards eliminating T.cpp.
This commit is contained in:
parent
841958d889
commit
c89a222c7c
7 changed files with 116 additions and 170 deletions
|
@ -122,6 +122,8 @@ void Subst::apply (
|
|||
{
|
||||
std::string::size_type pattern;
|
||||
|
||||
if (mFrom != "")
|
||||
{
|
||||
if (mGlobal)
|
||||
{
|
||||
// Perform all subs on description.
|
||||
|
@ -161,6 +163,7 @@ void Subst::apply (
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
106
src/command.cpp
106
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 <std::string, std::string> 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);
|
||||
|
||||
if (from != "")
|
||||
{
|
||||
std::string description = task.getDescription ();
|
||||
size_t pattern;
|
||||
|
||||
if (global)
|
||||
{
|
||||
// Perform all subs on description.
|
||||
while ((pattern = description.find (from)) != std::string::npos)
|
||||
{
|
||||
description.replace (pattern, from.length (), to);
|
||||
++changes;
|
||||
}
|
||||
|
||||
task.setDescription (description);
|
||||
|
||||
// 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;
|
||||
std::string description = task.get ("description");
|
||||
std::vector <Att> 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;
|
||||
}
|
||||
}
|
||||
context.subst.apply (description, annotations);
|
||||
|
||||
task.set ("description", description);
|
||||
task.setAnnotations (annotations);
|
||||
}
|
||||
}
|
||||
}
|
||||
return changes;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
18
src/main.h
18
src/main.h
|
@ -42,16 +42,16 @@ void validSortColumns (const std::vector <std::string>&, const std::vector <std:
|
|||
bool validTag (const std::string&);
|
||||
|
||||
// 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 ();
|
||||
|
||||
// recur.cpp
|
||||
void handleRecurrence ();
|
||||
Date getNextRecurrence (Date&, std::string&);
|
||||
bool generateDueDates (T&, std::vector <Date>&);
|
||||
void updateRecurrenceMask (/*TDB&,*/ std::vector <T>&, T&);
|
||||
bool generateDueDates (Task&, std::vector <Date>&);
|
||||
void updateRecurrenceMask (/*TDB&,*/ std::vector <T>&, 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 ();
|
||||
|
|
|
@ -141,17 +141,17 @@ void handleRecurrence (std::vector <Task>& 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 <Date>& allDue)
|
||||
bool generateDueDates (Task& parent, std::vector <Date>& 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 <Date>& 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;
|
||||
|
|
|
@ -1464,7 +1464,7 @@ std::string renderMonths (
|
|||
int firstMonth,
|
||||
int firstYear,
|
||||
const Date& today,
|
||||
std::vector <T>& all,
|
||||
std::vector <Task>& 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 <T>::iterator it;
|
||||
std::vector <Task>::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 <T>& pending,
|
||||
Task& task,
|
||||
std::vector <Task>& pending,
|
||||
std::vector <int>& 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];
|
||||
|
|
|
@ -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 \
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#include <sys/time.h>
|
||||
#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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue