mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Task: Conditional compilation allows Taskserver to reuse code
This commit is contained in:
parent
0141d10d56
commit
9415f62482
2 changed files with 30 additions and 5 deletions
29
src/Task.cpp
29
src/Task.cpp
|
@ -33,12 +33,12 @@
|
||||||
#ifdef PRODUCT_TASKWARRIOR
|
#ifdef PRODUCT_TASKWARRIOR
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <cfloat>
|
|
||||||
#endif
|
#endif
|
||||||
|
#include <cfloat>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <Lexer.h>
|
||||||
#ifdef PRODUCT_TASKWARRIOR
|
#ifdef PRODUCT_TASKWARRIOR
|
||||||
#include <Context.h>
|
#include <Context.h>
|
||||||
#include <Lexer.h>
|
|
||||||
#include <Nibbler.h>
|
#include <Nibbler.h>
|
||||||
#endif
|
#endif
|
||||||
#include <ISO8601.h>
|
#include <ISO8601.h>
|
||||||
|
@ -314,6 +314,7 @@ void Task::setStatus (Task::status status)
|
||||||
recalc_urgency = true;
|
recalc_urgency = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef PRODUCT_TASKWARRIOR
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Determines status of a date attribute.
|
// Determines status of a date attribute.
|
||||||
Task::dateState Task::getDateState (const std::string& name) const
|
Task::dateState Task::getDateState (const std::string& name) const
|
||||||
|
@ -348,7 +349,6 @@ Task::dateState Task::getDateState (const std::string& name) const
|
||||||
return dateNotDue;
|
return dateNotDue;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef PRODUCT_TASKWARRIOR
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Ready means pending, not blocked and either not scheduled or scheduled before
|
// Ready means pending, not blocked and either not scheduled or scheduled before
|
||||||
// now.
|
// now.
|
||||||
|
@ -582,7 +582,9 @@ void Task::parse (const std::string& input)
|
||||||
nl.skip (':') &&
|
nl.skip (':') &&
|
||||||
nl.getQuoted ('"', value))
|
nl.getQuoted ('"', value))
|
||||||
{
|
{
|
||||||
|
#ifdef PRODUCT_TASKWARRIOR
|
||||||
legacyAttributeMap (name);
|
legacyAttributeMap (name);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (! name.compare (0, 11, "annotation_", 11))
|
if (! name.compare (0, 11, "annotation_", 11))
|
||||||
++annotation_count;
|
++annotation_count;
|
||||||
|
@ -765,11 +767,13 @@ void Task::parseLegacy (const std::string& line)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
#ifdef PRODUCT_TASKWARRIOR
|
||||||
std::stringstream message;
|
std::stringstream message;
|
||||||
message << "Invalid fileformat at line '"
|
message << "Invalid fileformat at line '"
|
||||||
<< line
|
<< line
|
||||||
<< "'";
|
<< "'";
|
||||||
context.debug (message.str ());
|
context.debug (message.str ());
|
||||||
|
#endif
|
||||||
throw std::string (STRING_TASK_PARSE_UNREC_FF);
|
throw std::string (STRING_TASK_PARSE_UNREC_FF);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -894,8 +898,11 @@ std::string Task::composeJSON (bool decorate /*= false*/) const
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dependencies are an array by default.
|
// Dependencies are an array by default.
|
||||||
else if (i.first == "depends" &&
|
else if (i.first == "depends"
|
||||||
context.config.getBoolean ("json.depends.array"))
|
#ifdef PRODUCT_TASKWARRIOR
|
||||||
|
&& context.config.getBoolean ("json.depends.array")
|
||||||
|
#endif
|
||||||
|
)
|
||||||
{
|
{
|
||||||
std::vector <std::string> deps;
|
std::vector <std::string> deps;
|
||||||
split (deps, i.second, ',');
|
split (deps, i.second, ',');
|
||||||
|
@ -1057,6 +1064,7 @@ void Task::addDependency (int depid)
|
||||||
|
|
||||||
addDependency(uuid);
|
addDependency(uuid);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void Task::addDependency (const std::string& uuid)
|
void Task::addDependency (const std::string& uuid)
|
||||||
|
@ -1073,7 +1081,9 @@ void Task::addDependency (const std::string& uuid)
|
||||||
set ("depends", depends + "," + uuid);
|
set ("depends", depends + "," + uuid);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
#ifdef PRODUCT_TASKWARRIOR
|
||||||
context.footnote (format (STRING_TASK_DEPEND_DUP, get ("uuid"), uuid));
|
context.footnote (format (STRING_TASK_DEPEND_DUP, get ("uuid"), uuid));
|
||||||
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1081,12 +1091,15 @@ void Task::addDependency (const std::string& uuid)
|
||||||
set ("depends", uuid);
|
set ("depends", uuid);
|
||||||
|
|
||||||
// Prevent circular dependencies.
|
// Prevent circular dependencies.
|
||||||
|
#ifdef PRODUCT_TASKWARRIOR
|
||||||
if (dependencyIsCircular (*this))
|
if (dependencyIsCircular (*this))
|
||||||
throw std::string (STRING_TASK_DEPEND_CIRCULAR);
|
throw std::string (STRING_TASK_DEPEND_CIRCULAR);
|
||||||
|
#endif
|
||||||
|
|
||||||
recalc_urgency = true;
|
recalc_urgency = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef PRODUCT_TASKWARRIOR
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void Task::removeDependency (const std::string& uuid)
|
void Task::removeDependency (const std::string& uuid)
|
||||||
{
|
{
|
||||||
|
@ -1190,9 +1203,11 @@ bool Task::hasTag (const std::string& tag) const
|
||||||
if (tag == "PENDING") return get ("status") == "pending";
|
if (tag == "PENDING") return get ("status") == "pending";
|
||||||
if (tag == "COMPLETED") return get ("status") == "completed";
|
if (tag == "COMPLETED") return get ("status") == "completed";
|
||||||
if (tag == "DELETED") return get ("status") == "deleted";
|
if (tag == "DELETED") return get ("status") == "deleted";
|
||||||
|
#ifdef PRODUCT_TASKWARRIOR
|
||||||
if (tag == "UDA") return is_udaPresent ();
|
if (tag == "UDA") return is_udaPresent ();
|
||||||
if (tag == "ORPHAN") return is_orphanPresent ();
|
if (tag == "ORPHAN") return is_orphanPresent ();
|
||||||
if (tag == "LATEST") return id == context.tdb2.latest_id ();
|
if (tag == "LATEST") return id == context.tdb2.latest_id ();
|
||||||
|
#endif
|
||||||
if (tag == "PROJECT") return has ("project");
|
if (tag == "PROJECT") return has ("project");
|
||||||
if (tag == "PRIORITY") return has ("priority");
|
if (tag == "PRIORITY") return has ("priority");
|
||||||
}
|
}
|
||||||
|
@ -1800,7 +1815,9 @@ float Task::urgency_inherit () const
|
||||||
// Calling dependencyGetBlocked is rather expensive.
|
// Calling dependencyGetBlocked is rather expensive.
|
||||||
// It is called recursively for each dependency in the chain here.
|
// It is called recursively for each dependency in the chain here.
|
||||||
std::vector <Task> blocked;
|
std::vector <Task> blocked;
|
||||||
|
#ifdef PRODUCT_TASKWARRIOR
|
||||||
dependencyGetBlocked (*this, blocked);
|
dependencyGetBlocked (*this, blocked);
|
||||||
|
#endif
|
||||||
|
|
||||||
float v = FLT_MIN;
|
float v = FLT_MIN;
|
||||||
for (auto& task : blocked)
|
for (auto& task : blocked)
|
||||||
|
@ -1933,6 +1950,7 @@ float Task::urgency_blocking () const
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef PRODUCT_TASKWARRIOR
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Arguably does not belong here. This method reads the parse tree and calls
|
// Arguably does not belong here. This method reads the parse tree and calls
|
||||||
// Task methods. It could be a standalone function with no loss in access, as
|
// Task methods. It could be a standalone function with no loss in access, as
|
||||||
|
@ -2252,5 +2270,6 @@ void Task::modify (modType type, bool text_required /* = false */)
|
||||||
else if (modCount == 0 && text_required)
|
else if (modCount == 0 && text_required)
|
||||||
throw std::string (STRING_CMD_MODIFY_NEED_TEXT);
|
throw std::string (STRING_CMD_MODIFY_NEED_TEXT);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -119,7 +119,9 @@ public:
|
||||||
status getStatus () const;
|
status getStatus () const;
|
||||||
void setStatus (status);
|
void setStatus (status);
|
||||||
|
|
||||||
|
#ifdef PRODUCT_TASKWARRIOR
|
||||||
dateState getDateState (const std::string&) const;
|
dateState getDateState (const std::string&) const;
|
||||||
|
#endif
|
||||||
|
|
||||||
int getTagCount () const;
|
int getTagCount () const;
|
||||||
bool hasTag (const std::string&) const;
|
bool hasTag (const std::string&) const;
|
||||||
|
@ -136,7 +138,9 @@ public:
|
||||||
|
|
||||||
#ifdef PRODUCT_TASKWARRIOR
|
#ifdef PRODUCT_TASKWARRIOR
|
||||||
void addDependency (int);
|
void addDependency (int);
|
||||||
|
#endif
|
||||||
void addDependency (const std::string&);
|
void addDependency (const std::string&);
|
||||||
|
#ifdef PRODUCT_TASKWARRIOR
|
||||||
void removeDependency (int);
|
void removeDependency (int);
|
||||||
void removeDependency (const std::string&);
|
void removeDependency (const std::string&);
|
||||||
void getDependencies (std::vector <int>&) const;
|
void getDependencies (std::vector <int>&) const;
|
||||||
|
@ -152,8 +156,10 @@ public:
|
||||||
float urgency_c () const;
|
float urgency_c () const;
|
||||||
float urgency ();
|
float urgency ();
|
||||||
|
|
||||||
|
#ifdef PRODUCT_TASKWARRIOR
|
||||||
enum modType {modReplace, modPrepend, modAppend, modAnnotate};
|
enum modType {modReplace, modPrepend, modAppend, modAnnotate};
|
||||||
void modify (modType, bool text_required = false);
|
void modify (modType, bool text_required = false);
|
||||||
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int determineVersion (const std::string&);
|
int determineVersion (const std::string&);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue