remove leftovers of first diff-applicator implementation

...obsoleted by new generic implementation
This commit is contained in:
Fischlurch 2016-09-08 18:30:27 +02:00
parent 89bfbcab43
commit 2a26cef010
4 changed files with 0 additions and 342 deletions

View file

@ -1,152 +0,0 @@
/*
RECORD-CONTENT-MUTATOR.hpp - helper to remould record contents
Copyright (C) Lumiera.org
2015, Hermann Vosseler <Ichthyostega@web.de>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/** @file record-content-mutator.hpp
** Implementation helper for reshaping the contents of a lib::diff::Record.
** This technical helper is necessary to apply one level of a "Tree Diff"
** to an object represented as #Record::Mutator. Since records as such are
** designed as immutable value objects, we build a dedicated #Record::Mutator
** when it comes to reordering the contents of a given record. The technical
** details of doing so are highly coupled to the actual storage implementation
** of #Record, as well as to the actual procedure to apply a diff message, as
** implemented in lib::diff::DiffApplicationStrategy.
** @warning this struct is marked "internal" for a reason;
** it serves the purpose to remove technicalities from usage site,
** yet it is \em not a proper abstraction. Be sure you understand
** the storage layout, especially when testing for iteration end.
** @see generic-record-update-test.cpp
** @see tree-diff-application-test.cpp
** @see Record::Mutator
** @see diff-language.hpp
**
*/
#ifndef LIB_DIFF_RECORD_CONTENT_MUTATOR_H
#define LIB_DIFF_RECORD_CONTENT_MUTATOR_H
#include "lib/error.hpp"
#include <boost/noncopyable.hpp>
#include <utility>
namespace lib {
namespace diff{
namespace error = lumiera::error;
using std::move;
using std::swap;
/** @internal helper for DiffApplicationStrategy<Rec::Mutator> */
template<class STO>
struct RecordContentMutator
: boost::noncopyable
{
using Iter = typename STO::iterator;
STO attribs;
STO children;
Iter pos;
RecordContentMutator()
: attribs()
, children()
, pos(attribs.begin())
{ }
bool
empty() const
{
return attribs.empty()
and children.empty();
}
bool
currIsAttrib() const
{
return & *pos >= & *attribs.begin()
and & *pos < & *attribs.end();
}
bool
currIsChild() const
{
return & *pos >= & *children.begin()
and & *pos < & *children.end();
}
Iter end() { return children.end(); }
Iter end() const { return children.end(); }
RecordContentMutator&
operator++()
{
if (pos == children.end())
throw error::State ("attempt to iterate beyond end of scope"
,error::LUMIERA_ERROR_ITER_EXHAUST);
if (pos == attribs.end())
pos = children.begin();
else
++pos;
if (pos == attribs.end())
pos = children.begin();
return *this;
}
void
resetPos()
{
if (attribs.empty())
jumpToChildScope();
else
jumpToAttribScope();
}
void
jumpToAttribScope()
{
pos = attribs.begin();
}
void
jumpToChildScope()
{
pos = children.begin();
}
void
preAllocateStorage(size_t attribCnt, size_t childrenCnt)
{
// heuristics for storage pre-allocation (for tree diff application)
attribs.reserve (attribCnt * 120 / 100);
children.reserve (childrenCnt * 120 / 100);
ASSERT (this->empty());
}
};
}} // namespace lib::diff
#endif /*LIB_DIFF_RECORD_CONTENT_MUTATOR_H*/

View file

@ -93,7 +93,6 @@
#include "lib/format-util.hpp" ///////////////////////////////TICKET #973 : investigate the impact of this inclusion on code size
#include "lib/util.hpp"
#include "lib/diff/record-content-mutator.hpp"
#include <boost/noncopyable.hpp>
@ -275,7 +274,6 @@ namespace diff{
*/
class Mutator;
using ContentMutator = RecordContentMutator<Storage>;
/**
@ -524,16 +522,6 @@ namespace diff{
return std::tie (record_.attribs_, record_.children_);
}
void
swapContent (ContentMutator& alteredContent)
{
if (alteredContent.empty())
alteredContent.preAllocateStorage(record_.attribs_.size(),
record_.children_.size());
std::swap (record_.attribs_, alteredContent.attribs);
std::swap (record_.children_, alteredContent.children);
alteredContent.resetPos();
}
/** get the tail element.
* @return either the last child, or the last attribute, when children are empty.

View file

@ -314,11 +314,6 @@ return: 0
END
TEST "Generic Record - Mutations" GenericRecordUpdate_test <<END
return: 0
END
TEST "Generic Record data node" GenNodeBasic_test <<END
out: GenNode.+_CHILD_Record.+Rec.spam..ham = DataCap.+eggs
out-lit: --spam--

View file

@ -1,173 +0,0 @@
/*
GenericRecordUpdate(Test) - manipulate and reshape the generic record contents
Copyright (C) Lumiera.org
2015, Hermann Vosseler <Ichthyostega@web.de>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* *****************************************************/
#include "lib/test/run.hpp"
#include "lib/test/test-helper.hpp"
#include "lib/diff/record-content-mutator.hpp"
#include "lib/format-util.hpp"
#include "lib/diff/record.hpp"
#include "lib/itertools.hpp"
#include "lib/util.hpp"
#include <algorithm>
#include <string>
#include <vector>
using lib::append_all;
using util::isnil;
using std::vector;
using lumiera::error::LUMIERA_ERROR_ITER_EXHAUST;
namespace lib {
namespace diff{
namespace test{
namespace {//Test fixture....
using Seq = vector<string>;
using RecS = Record<string>;
template<class IT>
inline Seq
contents (IT const& it)
{
Seq collected;
append_all (it, collected);
return collected;
}
inline Seq
contents (RecS const& rec_of_strings)
{
return contents (rec_of_strings.begin());
}
}//(End)Test fixture
/*****************************************************************************//**
* @test cover technical details of rearranging the contents of lib::diff::Record.
* The implementation of our generic record (abstract object representation)
* uses two lists to hold the data of the attribute and content scopes.
* When receiving a diff message, we have to rearrange and alter the contents,
* which are by default immutable. Thus, for this specific task, embedded
* data is moved into this adapter, which exposes the mutating operation
* required to apply such a diff message.
*
* @see generic-record-representation-test.cpp
* @see tree-diff-application-test.cpp
*/
class GenericRecordUpdate_test
: public Test
{
virtual void
run (Arg)
{
RecS subject({"b = β", "a = α", "γ", "ε"});
RecS::Mutator mut(subject);
mut.appendChild("δ");
mut.setType("🌰");
RecS::ContentMutator content; // empty
CHECK (!isnil (mut));
CHECK ( isnil (content));
mut.swapContent(content); // contents of mutator now moved over
CHECK (!isnil (content));
CHECK ( isnil (mut));
CHECK (content.pos == content.attribs.begin());
CHECK (content.currIsAttrib());
CHECK (!content.currIsChild());
CHECK ("b = β" == *content.pos);
void* rawElm = &content.attribs[0];
swap (content.attribs[0], content.attribs[1]);
CHECK ("a = α" == *content.pos);
CHECK (rawElm == & *content.pos);
++content;
CHECK ("b = β" == *content.pos);
CHECK (rawElm != &*content.pos);
CHECK (content.currIsAttrib());
CHECK (!content.currIsChild());
std::sort (content.children.begin(), content.children.end());
++content; // now leaving attributes and entering child scope...
CHECK (!content.currIsAttrib());
CHECK (content.currIsChild());
CHECK ("γ" == *content.pos);
++content;
CHECK ("δ" == *content.pos);
++content;
CHECK ("ε" == *content.pos);
++content;
CHECK (content.pos == content.end());
CHECK (!content.currIsAttrib());
CHECK (!content.currIsChild());
VERIFY_ERROR (ITER_EXHAUST, ++content);
content.resetPos();
CHECK (content.currIsAttrib());
CHECK (!content.currIsChild());
CHECK (rawElm == & *content.pos);
++content;
CHECK ("b = β" == *content.pos);
content.jumpToChildScope();
CHECK ("γ" == *content.pos);
CHECK (!content.currIsAttrib());
CHECK (content.currIsChild());
CHECK ( isnil (mut));
CHECK (!isnil (content));
mut.swapContent(content);
CHECK ( isnil (content));
CHECK (!isnil (mut));
mut.swap (subject);
CHECK (Seq({"a = α", "b = β", "γ", "δ", "ε"}) == contents(subject));
CHECK ("Rec(🌰| a = α, b = β |{γ, δ, ε})" == string(subject));
}
};
/** Register this test class... */
LAUNCHER (GenericRecordUpdate_test, "unit common");
}}} // namespace lib::diff::test