DiffMessage: draft content diagnostics wrapper
This commit is contained in:
parent
d4ac2d78e2
commit
efc27fd07b
2 changed files with 67 additions and 1 deletions
|
|
@ -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 <string>
|
||||
|
|
@ -147,8 +148,59 @@ namespace diff{
|
|||
,__not_<can_IterForEach<CON>>>, 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<DiffStep>
|
||||
{
|
||||
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<DiffSnapshot> (*this))+"}";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
inline DiffMessage&
|
||||
DiffMessage::withDiagnostics()
|
||||
{
|
||||
return *this = DiffMessage{new MaterialisedDiffMessageBuffer(*this)};
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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 <string>
|
||||
|
|
@ -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 <<endl;
|
||||
|
||||
diffMsg.withDiagnostics();
|
||||
cout << diffMsg <<endl;
|
||||
|
||||
CHECK (!isnil (diffMsg));
|
||||
CHECK (ins(TYPE_X) == *diffMsg);
|
||||
CHECK (set(ATTRIB1) == *++diffMsg);
|
||||
CHECK (del(CHILD_T) == *++diffMsg);
|
||||
CHECK (isnil (++diffMsg));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue