2015-01-02 11:26:27 +01:00
|
|
|
/*
|
|
|
|
|
Diff - common helpers for the diff handling framework
|
|
|
|
|
|
|
|
|
|
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 diff.cpp
|
|
|
|
|
** Diff handling framework support code.
|
|
|
|
|
** This translation unit emits code used by the implementation
|
|
|
|
|
** of generic functionality
|
|
|
|
|
**
|
|
|
|
|
** @see diff-language.hpp
|
|
|
|
|
**
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "lib/error.hpp"
|
|
|
|
|
#include "lib/diff/diff-language.hpp"
|
2015-07-04 20:50:18 +02:00
|
|
|
#include "lib/diff/gen-node.hpp"
|
2015-01-02 11:26:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace lib {
|
|
|
|
|
namespace diff{
|
|
|
|
|
|
|
|
|
|
LUMIERA_ERROR_DEFINE(DIFF_CONFLICT, "Collision in diff application: contents of target not as expected.");
|
|
|
|
|
|
2015-07-04 20:50:18 +02:00
|
|
|
/* symbolic marker ID references
|
Generic Record: finish implementation of Mutator
especially setting (changing) attributes turned out to be tricky,
since in case of a GenNode this would mean to re-bind the hash ID;
we can not possibly do that properly without knowing the type of the payload,
and by design this payload type is opaque (erased).
As resort, I changed the semantics of the assign operation:
now it rather builds a new payload element, with a given initialiser.
In case of the strings, this ends up being the same operation,
while in case of GenNode, this is now something entirely different:
we can now build a new GenNode "in place" of the old one, and both
will have the same symbolic ID (attribute key). Incidentally,
our Variant implementation will reject such a re-building operatinon
when this means to change the (opaque) payload type.
in addition, I created a new API function on the Mutator,
allowing to move-in a complete attribute object. Actually this
new function became the working implementation. This way, it is
still possible to emplace a new attribute efficiently (consider
this to be a whole object graph!). But only, if the key (ID)
embedded in the attribute object is already what is the intended
key for this attribute. This way, we elegantly circumvent the
problem of having to re-bind a hash ID without knowing the type seed
2015-08-17 20:31:07 +02:00
|
|
|
* used within the tree diff language
|
2015-07-04 20:50:18 +02:00
|
|
|
* to mark specific scopes
|
|
|
|
|
*/
|
|
|
|
|
Ref Ref::END ("_END_");
|
|
|
|
|
Ref Ref::THIS ("_THIS_");
|
|
|
|
|
Ref Ref::CHILD ("_CHILD_");
|
|
|
|
|
Ref Ref::ATTRIBS("_ATTRIBS_");
|
|
|
|
|
|
2015-01-02 11:26:27 +01:00
|
|
|
|
2015-08-28 16:12:04 +02:00
|
|
|
/** Implementation of content equality test */
|
|
|
|
|
bool
|
|
|
|
|
DataCap::operator== (DataCap const& o) const
|
|
|
|
|
{
|
|
|
|
|
class EqualityTest
|
|
|
|
|
: public Variant<DataValues>::Visitor
|
|
|
|
|
{
|
|
|
|
|
DataCap const& o_;
|
|
|
|
|
bool isEqual_;
|
|
|
|
|
|
|
|
|
|
#define DERIVE_EQUALITY(_TY_) \
|
|
|
|
|
virtual void handle (_TY_& val) override { isEqual_ = (o_.get<_TY_>() == val); }
|
|
|
|
|
|
|
|
|
|
DERIVE_EQUALITY (int)
|
|
|
|
|
DERIVE_EQUALITY (int64_t)
|
|
|
|
|
DERIVE_EQUALITY (short)
|
|
|
|
|
DERIVE_EQUALITY (char)
|
|
|
|
|
DERIVE_EQUALITY (bool)
|
|
|
|
|
DERIVE_EQUALITY (double)
|
|
|
|
|
DERIVE_EQUALITY (string)
|
|
|
|
|
DERIVE_EQUALITY (time::Time)
|
|
|
|
|
DERIVE_EQUALITY (time::Offset)
|
|
|
|
|
DERIVE_EQUALITY (time::Duration)
|
|
|
|
|
DERIVE_EQUALITY (time::TimeSpan)
|
|
|
|
|
DERIVE_EQUALITY (hash::LuidH)
|
|
|
|
|
DERIVE_EQUALITY (RecRef)
|
|
|
|
|
DERIVE_EQUALITY (Rec)
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
EqualityTest(DataCap const& o)
|
|
|
|
|
: o_(o)
|
|
|
|
|
, isEqual_(false)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
operator bool() { return isEqual_; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
EqualityTest visitor(o);
|
|
|
|
|
unConst(this)->accept(visitor);
|
|
|
|
|
return visitor;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-02 11:26:27 +01:00
|
|
|
}} // namespace lib::diff
|