diff --git a/src/DOM.cpp b/src/DOM.cpp index eec38c57f..53f59b00b 100644 --- a/src/DOM.cpp +++ b/src/DOM.cpp @@ -246,13 +246,13 @@ bool getDOM (const std::string& name, const Task& task, Variant& value) return false; // Quickly deal with the most common cases. - if (task.data.size () && name == "id") + if (task.data_removeme ().size () && name == "id") { value = Variant (static_cast (task.id)); return true; } - if (task.data.size () && name == "urgency") + if (task.data_removeme ().size () && name == "urgency") { value = Variant (task.urgency_c ()); return true; @@ -318,13 +318,13 @@ bool getDOM (const std::string& name, const Task& task, Variant& value) { // Now that 'ref' is the contextual task, and any ID/UUID is chopped off the // elements vector, DOM resolution is now simple. - if (ref.data.size () && size == 1 && canonical == "id") + if (ref.data_removeme ().size () && size == 1 && canonical == "id") { value = Variant (static_cast (ref.id)); return true; } - if (ref.data.size () && size == 1 && canonical == "urgency") + if (ref.data_removeme ().size () && size == 1 && canonical == "urgency") { value = Variant (ref.urgency_c ()); return true; @@ -332,7 +332,7 @@ bool getDOM (const std::string& name, const Task& task, Variant& value) // Special handling of status required for virtual waiting status // implementation. Remove in 3.0.0. - if (ref.data.size () && size == 1 && canonical == "status") + if (ref.data_removeme ().size () && size == 1 && canonical == "status") { value = Variant (ref.statusToText (ref.getStatus ())); return true; @@ -340,7 +340,7 @@ bool getDOM (const std::string& name, const Task& task, Variant& value) Column* column = Context::getContext ().columns[canonical]; - if (ref.data.size () && size == 1 && column) + if (ref.data_removeme ().size () && size == 1 && column) { if (column->is_uda () && ! ref.has (canonical)) { @@ -375,13 +375,13 @@ bool getDOM (const std::string& name, const Task& task, Variant& value) return true; } - if (ref.data.size () && size == 2 && canonical == "tags") + if (ref.data_removeme ().size () && size == 2 && canonical == "tags") { value = Variant (ref.hasTag (elements[1]) ? elements[1] : ""); return true; } - if (ref.data.size () && size == 2 && column && column->type () == "date") + if (ref.data_removeme ().size () && size == 2 && column && column->type () == "date") { Datetime date (ref.get_date (canonical)); if (elements[1] == "year") { value = Variant (static_cast (date.year ())); return true; } @@ -396,13 +396,13 @@ bool getDOM (const std::string& name, const Task& task, Variant& value) } } - if (ref.data.size () && size == 2 && elements[0] == "annotations" && elements[1] == "count") + if (ref.data_removeme ().size () && size == 2 && elements[0] == "annotations" && elements[1] == "count") { value = Variant (static_cast (ref.getAnnotationCount ())); return true; } - if (ref.data.size () && size == 3 && elements[0] == "annotations") + if (ref.data_removeme ().size () && size == 3 && elements[0] == "annotations") { auto annos = ref.getAnnotations (); @@ -430,7 +430,7 @@ bool getDOM (const std::string& name, const Task& task, Variant& value) } } - if (ref.data.size () && size == 4 && elements[0] == "annotations" && elements[2] == "entry") + if (ref.data_removeme ().size () && size == 4 && elements[0] == "annotations" && elements[2] == "entry") { auto annos = ref.getAnnotations (); diff --git a/src/TDB2.cpp b/src/TDB2.cpp index 884dc0f45..be3d7d83c 100644 --- a/src/TDB2.cpp +++ b/src/TDB2.cpp @@ -1048,11 +1048,11 @@ void TDB2::show_diff ( Task before (prior); std::vector beforeAtts; - for (auto& att : before.data) + for (auto& att : before.data_removeme ()) beforeAtts.push_back (att.first); std::vector afterAtts; - for (auto& att : after.data) + for (auto& att : after.data_removeme ()) afterAtts.push_back (att.first); std::vector beforeOnly; @@ -1067,7 +1067,7 @@ void TDB2::show_diff ( view.set (row, 1, renderAttribute (name, before.get (name)), color_red); } - for (auto& att : before.data) + for (auto& att : before.data_removeme ()) { std::string priorValue = before.get (att.first); std::string currentValue = after.get (att.first); @@ -1093,7 +1093,7 @@ void TDB2::show_diff ( else { int row; - for (auto& att : after.data) + for (auto& att : after.data_removeme ()) { row = view.addRow (); view.set (row, 0, att.first); @@ -1151,11 +1151,11 @@ void TDB2::show_diff ( std::vector all = Context::getContext ().getColumns (); // Now factor in the annotation attributes. - for (auto& it : before.data) + for (auto& it : before.data_removeme ()) if (it.first.substr (0, 11) == "annotation_") all.push_back (it.first); - for (auto& it : after.data) + for (auto& it : after.data_removeme ()) if (it.first.substr (0, 11) == "annotation_") all.push_back (it.first); diff --git a/src/Task.h b/src/Task.h index a438e0c93..120c89c23 100644 --- a/src/Task.h +++ b/src/Task.h @@ -74,7 +74,7 @@ public: enum dateState {dateNotDue, dateAfterToday, dateLaterToday, dateEarlierToday, dateBeforeToday}; // Public data. - std::map data {}; + const std::map &data_removeme () const { return data; }; int id {0}; float urgency_value {0.0}; bool recalc_urgency {true}; @@ -187,6 +187,9 @@ private: void fixDependsAttribute (); void fixTagsAttribute (); +protected: + std::map data {}; + public: float urgency_project () const; float urgency_active () const; diff --git a/src/commands/CmdDenotate.cpp b/src/commands/CmdDenotate.cpp index 8237bf28d..e2ea1e788 100644 --- a/src/commands/CmdDenotate.cpp +++ b/src/commands/CmdDenotate.cpp @@ -128,7 +128,7 @@ int CmdDenotate::execute (std::string&) } } - if (before.data != task.data) + if (before.data_removeme () != task.data_removeme ()) { auto question = format ("Denotate task {1} '{2}'?", task.identifier (true), diff --git a/src/commands/CmdImport.cpp b/src/commands/CmdImport.cpp index 3e4540db1..f473a0fbf 100644 --- a/src/commands/CmdImport.cpp +++ b/src/commands/CmdImport.cpp @@ -198,7 +198,7 @@ void CmdImport::importSingleTask (json::object* obj) if (hasGeneratedEnd) task.set ("end", before.get ("end")); - if (before.data != task.data) + if (before.data_removeme() != task.data_removeme()) { CmdModify modHelper; modHelper.checkConsistency (before, task); diff --git a/src/commands/CmdModify.cpp b/src/commands/CmdModify.cpp index fedbf8a74..eae2ae995 100644 --- a/src/commands/CmdModify.cpp +++ b/src/commands/CmdModify.cpp @@ -79,7 +79,7 @@ int CmdModify::execute (std::string&) Task before (task); task.modify (Task::modReplace); - if (before.data != task.data) + if (before.data_removeme () != task.data_removeme ()) { // Abort if change introduces inconsistencies. checkConsistency(before, task); diff --git a/src/commands/CmdUDAs.cpp b/src/commands/CmdUDAs.cpp index eaa8dc03e..048c41e59 100644 --- a/src/commands/CmdUDAs.cpp +++ b/src/commands/CmdUDAs.cpp @@ -134,7 +134,7 @@ int CmdUDAs::execute (std::string& output) std::map orphans; for (auto& i : filtered) { - for (auto& att : i.data) + for (auto& att : i.data_removeme ()) if (! Task::isAnnotationAttr (att.first) && ! Task::isTagAttr (att.first) && ! Task::isDepAttr (att.first) && diff --git a/src/rules.cpp b/src/rules.cpp index 058a14787..038fe73a4 100644 --- a/src/rules.cpp +++ b/src/rules.cpp @@ -189,7 +189,7 @@ static void colorizeKeyword (Task& task, const std::string& rule, const Color& b // first match. else { - for (const auto& att : task.data) + for (const auto& att : task.data_removeme ()) { if (! att.first.compare (0, 11, "annotation_", 11) && find (att.second, rule.substr (14), sensitive) != std::string::npos) diff --git a/test/t.t.cpp b/test/t.t.cpp index 197bef959..ace646244 100644 --- a/test/t.t.cpp +++ b/test/t.t.cpp @@ -187,7 +187,7 @@ TODO Task::decode test.is (task.get ("three"), "four", "three=four"); // Task::set - task.data.clear (); + task = Task(); task.set ("name", "value"); test.is (task.composeF4 (), "[name:\"value\"]", "Task::set"); @@ -211,7 +211,7 @@ TODO Task::decode test.is (task.composeF4 (), "[name:\"value\"]", "Task::remove"); // Task::all - test.is (task.data.size (), (size_t)1, "Task::all size"); + test.is (task.data_removeme ().size (), (size_t)1, "Task::all size"); //////////////////////////////////////////////////////////////////////////////// diff --git a/test/util.t.cpp b/test/util.t.cpp index ad9e7d3b7..6f554f3f6 100644 --- a/test/util.t.cpp +++ b/test/util.t.cpp @@ -58,7 +58,7 @@ int main (int, char**) Task rightAgain (right); std::string output = left.diff (right); - t.ok (left.data != right.data, "Detected changes"); + t.ok (!(left == right), "Detected changes"); t.ok (output.find ("Zero will be changed from '0' to '00'") != std::string::npos, "Detected change zero:0 -> zero:00"); t.ok (output.find ("One will be deleted") != std::string::npos, "Detected deletion one:1 ->"); t.ok (output.find ("Two") == std::string::npos, "Detected no change two:2 -> two:2");