From 5427d659d7a5a0467ddd858dd19023f329bc1f2b Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 4 Jan 2015 09:26:25 +0100 Subject: [PATCH] definition reordering and comments --- src/lib/diff/diff-language.hpp | 61 ++++---- tests/library/diff-list-generation-test.cpp | 148 +++++++++++--------- 2 files changed, 111 insertions(+), 98 deletions(-) diff --git a/src/lib/diff/diff-language.hpp b/src/lib/diff/diff-language.hpp index 74adeedb9..76f1f6aa7 100644 --- a/src/lib/diff/diff-language.hpp +++ b/src/lib/diff/diff-language.hpp @@ -100,6 +100,37 @@ namespace diff{ LUMIERA_ERROR_DECLARE(DIFF_CONFLICT); ///< Collision in diff application: contents of target not as expected. + template + using HandlerFun = void (I::*) (E); + + + /** @internal type rebinding helper */ + template + struct InterpreterScheme ///< base case is to expect typedef I::Val + { + using Interpreter = I; + using Val = typename I::Val; + using Handler = HandlerFun; + }; + + template class IP, typename E> + struct InterpreterScheme> ///< alternatively, the interpreter value type can be templated + { + using Val = E; + using Interpreter = IP; + using Handler = HandlerFun; + }; + + template + struct InterpreterScheme> + { + using Val = E; + using Interpreter = I; + using Handler = HandlerFun; + }; + + + /** * Definition frame for a language to describe differences in data structures. * We use a \em linearised representation as a sequence of DiffStep messages @@ -146,33 +177,6 @@ namespace diff{ }; }; - template - using HandlerFun = void (I::*) (E); - - - template - struct InterpreterScheme - { - using Interpreter = I; - using Val = typename I::Val; - using Handler = HandlerFun; - }; - - template class IP, typename E> - struct InterpreterScheme> - { - using Val = E; - using Interpreter = IP; - using Handler = HandlerFun; - }; - - template - struct InterpreterScheme> - { - using Val = E; - using Interpreter = I; - using Handler = HandlerFun; - }; @@ -215,9 +219,10 @@ namespace diff{ } /** shortcut to define tokens of the diff language. - * Use it to define namespace level function objects, which, + * Use it to define namespace or class level function objects, which, * when supplied with an argument value of type \c E, will generate * a specific language token wrapping a copy of this element. + * @see ListDiffLanguage usage example * @note need a typedef \c Interpreter at usage site * to refer to the actual language interpreter interface; * the template parameters of the Language and the element diff --git a/tests/library/diff-list-generation-test.cpp b/tests/library/diff-list-generation-test.cpp index 4fd2c7673..3ca8abebb 100644 --- a/tests/library/diff-list-generation-test.cpp +++ b/tests/library/diff-list-generation-test.cpp @@ -76,76 +76,8 @@ namespace diff{ using DiffStep = typename ListDiffLanguage::DiffStep; - /** - * @internal state frame for diff detection and generation. - * A diff generation process is built on top of an "old" reference point - * and a "new" state of the underlying sequence. Within this reference frame, - * an demand-driven evaluation of the differences is handed out to the client - * as an iterator. While consuming this evaluation process, both the old and - * the new version of the sequence will be traversed once. In case of re-orderings, - * a nested forward lookup similar to insertion sort will look for matches in the - * old sequence, rendering the whole evaluation quadratic in worst-case. - */ - class DiffFrame - { - Idx old_; - Idx* new_; - size_t oldHead_=0, - newHead_=0; - - static ListDiffLanguage token; - - DiffStep currentStep_{token.skip(Val())}; - - bool hasOld() const { return oldHead_ < old_.size(); } - bool hasNew() const { return newHead_ < new_->size(); } - - public: - DiffFrame(Idx& current, Idx&& refPoint) - : old_(refPoint) - , new_(¤t) - { } - - - /* === Iteration control API for IterStateWrapper== */ - - friend bool - checkPoint (DiffFrame const& frame) - { - return frame.hasNew() || frame.hasOld(); - } - - friend DiffStep& - yield (DiffFrame const& frame) - { - REQUIRE (checkPoint (frame)); - return unConst(frame).currentStep_; - } - - friend void - iterNext (DiffFrame & frame) - { - frame.establishInvariant(); - } - - private: - void - establishInvariant() - { - if (canPick()) - { - - } - } - - bool - canPick() - { - return false;//TODO - } - - - }; + /** @internal state frame for diff detection and generation. */ + class DiffFrame; @@ -194,10 +126,86 @@ namespace diff{ return Diff(DiffFrame(refIdx_, move(mark))); } }; + + + + /** + * A diff generation process is built on top of an "old" reference point + * and a "new" state of the underlying sequence. Within this reference frame, + * an demand-driven evaluation of the differences is handed out to the client + * as an iterator. While consuming this evaluation process, both the old and + * the new version of the sequence will be traversed once. In case of re-orderings, + * a nested forward lookup similar to insertion sort will look for matches in the + * old sequence, rendering the whole evaluation quadratic in worst-case. + */ + template + class DiffDetector::DiffFrame + { + Idx old_; + Idx* new_; + size_t oldHead_=0, + newHead_=0; + + static ListDiffLanguage token; + + DiffStep currentStep_{token.skip (Val())}; + + bool hasOld() const { return oldHead_ < old_.size(); } + bool hasNew() const { return newHead_ < new_->size(); } + + public: + DiffFrame(Idx& current, Idx&& refPoint) + : old_(refPoint) + , new_(¤t) + { } + + + /* === Iteration control API for IterStateWrapper== */ + + friend bool + checkPoint (DiffFrame const& frame) + { + return frame.hasNew() || frame.hasOld(); + } + + friend DiffStep& + yield (DiffFrame const& frame) + { + REQUIRE (checkPoint (frame)); + return unConst(frame).currentStep_; + } + + friend void + iterNext (DiffFrame & frame) + { + frame.establishInvariant(); + } + + private: + void + establishInvariant() + { + if (canPick()) + { + + } + } + + bool + canPick() + { + return false;//TODO + } + + + }; + + /** allocate static storage for the diff language token builder functions */ template ListDiffLanguage::Val> DiffDetector::DiffFrame::token; + //######################### namespace test{