diff --git a/src/lib/diff/diff-message.hpp b/src/lib/diff/diff-message.hpp index 640ed154e..047ad9d52 100644 --- a/src/lib/diff/diff-message.hpp +++ b/src/lib/diff/diff-message.hpp @@ -52,6 +52,7 @@ #include "lib/iter-adapter-stl.hpp" #include "lib/diff/tree-diff.hpp" #include "lib/diff/gen-node.hpp" +#include "lib/format-util.hpp" #include "lib/meta/util.hpp" #include @@ -147,8 +148,59 @@ namespace diff{ ,__not_>>, void*> =nullptr) : _FrontEnd{iter_source::eachEntry(container)} { } + + + /** + * enable support to show content of the message. + * After calling this function, operator string() renders all DiffSteps + * @warning since by design a DiffMessage can only be ``pulled'' once, + * this operation needs to impose a _side effect:_ it materialises + * the complete diff sequence at once into a heap allocated buffer. + */ + DiffMessage& withDiagnostics(); }; + namespace { + + struct DiffSnapshot + : std::vector + { + DiffSnapshot(DiffMessage& srcMsg) + { + for ( ; srcMsg; ++srcMsg ) + push_back (*srcMsg); + } + }; + + using _VecIter = DiffSnapshot::iterator; + using _RangeIT = RangeIter<_VecIter>; + using _Wrapped = WrappedLumieraIter<_RangeIT>; + + class MaterialisedDiffMessageBuffer + : private DiffSnapshot + , public _Wrapped + { + public: + MaterialisedDiffMessageBuffer(DiffMessage& srcMsg) + : DiffSnapshot{srcMsg} + , _Wrapped{_RangeIT{DiffSnapshot::begin(), DiffSnapshot::end()}} + { } + + virtual + operator string() const override + { + return "Diff--{"+util::join (static_cast (*this))+"}"; + } + }; + } + + inline DiffMessage& + DiffMessage::withDiagnostics() + { + return *this = DiffMessage{new MaterialisedDiffMessageBuffer(*this)}; + } + + diff --git a/tests/library/diff/diff-message-test.cpp b/tests/library/diff/diff-message-test.cpp index ab7fe4d7f..2dfe3abf4 100644 --- a/tests/library/diff/diff-message-test.cpp +++ b/tests/library/diff/diff-message-test.cpp @@ -33,6 +33,7 @@ #include "lib/iter-adapter-stl.hpp" #include "lib/time/timevalue.hpp" #include "lib/format-util.hpp" +#include "lib/format-cout.hpp" ///////////////TODO remove when done #include "lib/util.hpp" #include @@ -289,7 +290,20 @@ namespace test{ void verify_diagnostics() { - UNIMPLEMENTED("add toString decorator"); + DiffMessage diffMsg{ins(TYPE_X) + ,set(ATTRIB1) + ,del(CHILD_T)}; + + cout << diffMsg <