From e2cd4aba8a8a01bb245dfc72ba7f37ce2edd7937 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Mon, 13 Jul 2009 01:25:24 +0200 Subject: [PATCH] fix name, add test for postfix increment --- .../{iter-adaptor.hpp => iter-adapter.hpp} | 12 ++++++----- src/lib/scoped-ptrvect.hpp | 2 +- tests/40components.tests | 3 ++- tests/lib/Makefile.am | 2 +- ...adaptor-test.cpp => iter-adapter-test.cpp} | 20 +++++++++++-------- 5 files changed, 23 insertions(+), 16 deletions(-) rename src/lib/{iter-adaptor.hpp => iter-adapter.hpp} (91%) rename tests/lib/{iter-adaptor-test.cpp => iter-adapter-test.cpp} (93%) diff --git a/src/lib/iter-adaptor.hpp b/src/lib/iter-adapter.hpp similarity index 91% rename from src/lib/iter-adaptor.hpp rename to src/lib/iter-adapter.hpp index 560b03eae..1b8bbbc7b 100644 --- a/src/lib/iter-adaptor.hpp +++ b/src/lib/iter-adapter.hpp @@ -20,7 +20,7 @@ */ -/** @file iter-adaptor.hpp +/** @file iter-adapter.hpp ** Helper template(s) for creating lumiera forward iterators. ** This denotes a concept similar to STL's "forward iterator", with ** the addition of an bool check to detect iteration end. The latter @@ -61,13 +61,15 @@ namespace lib { /** - * simple ptr-to-object based implementation of the lumiera forward iterator concept. - * Basically such an PtrIter behaves like the similar concept from STL, but - * - it is not just a disguised pointer (meaning, its more expensive) + * Adapter for building an implementation of the lumiera forward iterator concept. + * The "current position" is represented as an opaque element (usually an nested iterator), + * with callbacks to the controlling container instance for managing this position. + * Basically such an IterAdapter behaves like the similar concept from STL, but + * - it is not just a disguised pointer (meaning, it's more expensive) * - it checks validity on every operation and may throw * - it has a distinct back-link to the source container * - the source container needs to implement iterStart() and iterInc() - * - we need friendship to and from the container class + * - we need friendship to access the callbacks on the container * - the end-of-iteration can be detected by bool check * * @see scoped-ptrvect.hpp usage example diff --git a/src/lib/scoped-ptrvect.hpp b/src/lib/scoped-ptrvect.hpp index 5f68037d7..932bcffb6 100644 --- a/src/lib/scoped-ptrvect.hpp +++ b/src/lib/scoped-ptrvect.hpp @@ -45,7 +45,7 @@ #include "include/logging.h" -#include "lib/iter-adaptor.hpp" +#include "lib/iter-adapter.hpp" #include "lib/error.hpp" #include "lib/util.hpp" diff --git a/tests/40components.tests b/tests/40components.tests index 379df32c1..59e355116 100644 --- a/tests/40components.tests +++ b/tests/40components.tests @@ -281,7 +281,8 @@ return: 0 END -PLANNED "Lumiera Iterator Concept" IterAdaptor_test < @@ -26,7 +26,7 @@ #include "lib/util.hpp" //#include "lib/scoped-ptrvect.hpp" -#include "lib/iter-adaptor.hpp" +#include "lib/iter-adapter.hpp" //#include "testdummy.hpp" #include #include @@ -72,10 +72,7 @@ namespace test{ for_each (numberz_, killIt); } - typedef int * value_type; - typedef int ** pointer; - typedef int *& reference; - + typedef IterAdapter<_Vec::iterator, TestContainer> iterator; typedef IterAdapter<_Vec::const_iterator, TestContainer> const_iterator; typedef PtrDerefIter ref_iterator; @@ -122,7 +119,7 @@ namespace test{ * "lumiera forward iterator" * @todo see Ticket #182 */ - class IterAdaptor_test : public Test + class IterAdapter_test : public Test { virtual void @@ -199,6 +196,13 @@ namespace test{ ASSERT ((*iter) == i); } + TestContainer::ref_iterator rI (elms.begin_ref()); + + ASSERT (0 == *rI ); + ASSERT (0 == *rI++); + ASSERT (1 == *rI ); + ASSERT (2 == *++rI); + ASSERT (TestContainer::iterator() == elms.end()); ASSERT (!(TestContainer::iterator())); ASSERT (!(elms.end())); @@ -211,7 +215,7 @@ namespace test{ }; - LAUNCHER (IterAdaptor_test, "unit common"); + LAUNCHER (IterAdapter_test, "unit common"); }} // namespace lib::test