diff --git a/src/lib/diff/gen-node.hpp b/src/lib/diff/gen-node.hpp index a821db633..09ad59421 100644 --- a/src/lib/diff/gen-node.hpp +++ b/src/lib/diff/gen-node.hpp @@ -101,6 +101,7 @@ #include "lib/variant.hpp" #include "lib/time/timevalue.hpp" #include "lib/diff/record.hpp" +#include "lib/idi/entry-id.hpp" //#include "lib/util.hpp" //#include "lib/format-string.hpp" @@ -148,13 +149,88 @@ namespace diff{ DataCap(X&& x) : Variant(std::forward(x)) { } + + DataCap(DataCap const& o) =default; + DataCap(DataCap&& o) =default; + DataCap(DataCap& o) + : DataCap((DataCap const&)o) + { } }; /** generic data element node within a tree */ - class GenNode + struct GenNode { - public: + class ID + : public idi::BareEntryID + { + friend class GenNode; + + template + ID (X*, string const& symbolicID) + : idi::BareEntryID (symbolicID, + idi::getTypeHash()) + { } + + public: + ID (GenNode const& node) + : ID(node.idi) + { } + + // standard copy operations acceptable + }; + + ID idi; + DataCap data; + + template + GenNode(X&& val) + : idi(&val, buildChildID()) + , data(std::forward(val)) + { } + + template + GenNode(string const& symbolicID, X&& val) + : idi(&val, symbolicID) + , data(std::forward(val)) + { } + + GenNode(string const& symbolicID, const char* text) + : GenNode(symbolicID, string(text)) + { } + + GenNode(const char* text) + : GenNode(string(text)) + { } + + GenNode(GenNode const& o) =default; + GenNode(GenNode&& o) =default; + GenNode(GenNode& o) + : GenNode((GenNode const&)o) + { } + + // default copy assignable + + + bool + isNamed() const + { + return util::startsWith (idi.getSym(), "_CHILD_"); + } + + friend string + name (GenNode const& node) + { + return node.idi.getSym(); + } + + private: + template + static string + buildChildID() + { + return "_CHILD_" + idi::generateSymbolicID(); + } }; @@ -186,21 +262,21 @@ namespace diff{ inline GenNode Rec::buildTypeAttribute (string const& typeID) { - return GenNode(); ///TODO + return GenNode("type", typeID); } template<> inline string Rec::extractKey (GenNode const& v) { - return "todo"; ////TODO + return v.idi.getSym(); } template<> inline GenNode Rec::extractVal (GenNode const& v) { - return GenNode(); ///TODO + return GenNode(v); ///TODO } diff --git a/src/lib/variant.hpp b/src/lib/variant.hpp index 938fd2203..2ffb00143 100644 --- a/src/lib/variant.hpp +++ b/src/lib/variant.hpp @@ -111,6 +111,12 @@ namespace lib { using Type = X; }; + template + struct CanBuildFrom> + { + using Type = X; + }; + template struct CanBuildFrom> { diff --git a/tests/library/diff/gen-node-basic-test.cpp b/tests/library/diff/gen-node-basic-test.cpp index 58ed90248..161b47854 100644 --- a/tests/library/diff/gen-node-basic-test.cpp +++ b/tests/library/diff/gen-node-basic-test.cpp @@ -33,7 +33,9 @@ //#include #include +using util::isnil; using util::contains; +using util::isSameObject; using lib::time::Time; using lib::time::TimeSpan; //using std::string; @@ -93,7 +95,6 @@ namespace test{ objectShortcut(); symbolReference(); sequenceIteration(); - duplicateDetection(); copy_and_move(); } @@ -110,7 +111,7 @@ namespace test{ // can optionally be named GenNode n2("π", 3.14159265358979323846264338328); - CHECK (fabs (3.14159265 - n2.data.get) < 1e-5 ); + CHECK (fabs (3.14159265 - n2.data.get()) < 1e-5 ); CHECK (n2.isNamed()); CHECK ("π" == n2.idi.getSym()); CHECK ("π" == name(n2)); @@ -255,18 +256,14 @@ namespace test{ void sequenceIteration() { - } - - - void - duplicateDetection() - { + UNIMPLEMENTED ("wtf"); } void copy_and_move() { + UNIMPLEMENTED ("need to check that?"); } }; diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index d3566b380..8357203dc 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -35,7 +35,13 @@ - + + + + + + +