From 71af21ffd6b475fdf22306007dd78f9d850038a9 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 9 Nov 2024 22:43:05 +0100 Subject: [PATCH] Library: clarify name of index-based iterator Originally, this helper was called `IterIndex`, thereby following a common naming scheme of iteration-related facilities in Lumiera, e.g. * `IterAdapter` * `IterExplorer` * `IterSource` However, I myself was not able to recall this name, and found myself now for the second time unable to find this piece of code, even while still able to recall vaguely that I had written something of this kind. (and unable to find it by a text search for "index", for obvious reasons) So, on a second thought, the original name is confusing: we do not create an index of / for iterators; rather we are iterating an index. So this is what it should be called... --- src/lib/{iter-index.hpp => index-iter.hpp} | 22 +++++++++---------- src/lib/several.hpp | 6 ++--- src/lib/text-template.hpp | 4 ++-- src/steam/engine/node-builder.hpp | 4 ++-- tests/12metaprogramming.tests | 5 +++++ ...ter-index-test.cpp => index-iter-test.cpp} | 20 ++++++++--------- 6 files changed, 33 insertions(+), 28 deletions(-) rename src/lib/{iter-index.hpp => index-iter.hpp} (91%) rename tests/library/{iter-index-test.cpp => index-iter-test.cpp} (94%) diff --git a/src/lib/iter-index.hpp b/src/lib/index-iter.hpp similarity index 91% rename from src/lib/iter-index.hpp rename to src/lib/index-iter.hpp index 59fb36809..51b20f051 100644 --- a/src/lib/iter-index.hpp +++ b/src/lib/index-iter.hpp @@ -1,5 +1,5 @@ /* - ITER-INDEX.hpp - iterator with indexed random-access to referred container + INDEX-ITER.hpp - iterator with indexed random-access to referred container Copyright (C) Lumiera.org 2024, Hermann Vosseler @@ -21,7 +21,7 @@ */ -/** @file iter-index.hpp +/** @file index-iter.hpp ** Iterator-style access handle to a referred container with subscript index. ** This wrapper packages a current index number and a back-link to some data container ** with subscript operator and range check. This allows to hand out a navigable access point @@ -31,14 +31,14 @@ ** to re-set the iteration to the container's start. Optionally, a smart-ptr can be ** embedded, allowing the handle also to own and manage the data container. ** - ** @see IterIndex_test + ** @see IndexIter_test ** @see iter-adapter.hpp ** @see [usage example](\ref lib::TextTemplate::InstanceCore) */ -#ifndef SRC_LIB_ITER_INDEX_H -#define SRC_LIB_ITER_INDEX_H +#ifndef SRC_LIB_INDEX_ITER_H +#define SRC_LIB_INDEX_ITER_H #include "lib/iter-adapter.hpp" @@ -114,20 +114,20 @@ namespace lib { * @tparam CON a container with `operator[]` and a function `size()` * @tparam PTR how to refer to this container; can be defined as smart-ptr, * additionally allowing to manage this container automatically. - * @remark while a default constructed IterIndex and some _exhausted_ IterIndex + * @remark while a default constructed IndexIter and some _exhausted_ IndexIter * compare equal, only the latter can be re-set into active state. */ template - class IterIndex + class IndexIter : public iter::IndexAccessCore::IterWrapper { using _Cor = iter::IndexAccessCore; using _Par = typename _Cor::IterWrapper; public: - IterIndex() = default; - IterIndex (CON& container) : IterIndex{&container}{ }; - IterIndex (PTR pContainer) + IndexIter() = default; + IndexIter (CON& container) : IndexIter{&container}{ }; + IndexIter (PTR pContainer) : _Par{_Cor{pContainer, 0}} { } @@ -152,4 +152,4 @@ namespace lib { } // namespace lib -#endif /*SRC_LIB_ITER_INDEX_H*/ +#endif /*SRC_LIB_INDEX_ITER_H*/ diff --git a/src/lib/several.hpp b/src/lib/several.hpp index b54469c1d..ee74c0d27 100644 --- a/src/lib/several.hpp +++ b/src/lib/several.hpp @@ -61,7 +61,7 @@ #include "lib/nocopy.hpp" -#include "lib/iter-index.hpp" +#include "lib/index-iter.hpp" #include #include @@ -216,8 +216,8 @@ namespace lib { I& front() { return operator[] (0); } I& back() { return operator[] (data_? data_->cnt-1 : 0); } - using iterator = lib::IterIndex; - using const_iterator = lib::IterIndex; + using iterator = lib::IndexIter; + using const_iterator = lib::IndexIter; iterator begin() { return iterator{*this}; } iterator end() { return iterator{}; } diff --git a/src/lib/text-template.hpp b/src/lib/text-template.hpp index c4bdc9a8d..c0a5c631c 100644 --- a/src/lib/text-template.hpp +++ b/src/lib/text-template.hpp @@ -175,7 +175,7 @@ #include "lib/error.hpp" #include "lib/nocopy.hpp" -#include "lib/iter-index.hpp" +#include "lib/index-iter.hpp" #include "lib/iter-explorer.hpp" #include "lib/format-string.hpp" #include "lib/format-util.hpp" @@ -380,7 +380,7 @@ namespace lib { template class InstanceCore { - using ActionIter = IterIndex; + using ActionIter = IndexIter; using DataCtxIter = typename SRC::Iter; using NestedCtx = std::pair; using CtxStack = std::stack>; diff --git a/src/steam/engine/node-builder.hpp b/src/steam/engine/node-builder.hpp index 2136b7fae..459bf0700 100644 --- a/src/steam/engine/node-builder.hpp +++ b/src/steam/engine/node-builder.hpp @@ -100,7 +100,7 @@ #include "steam/engine/turnout.hpp" #include "lib/several-builder.hpp" #include "lib/format-string.hpp" -#include "lib/iter-index.hpp" +#include "lib/index-iter.hpp" #include "lib/test/test-helper.hpp"/////////////////////TODO TOD-oh #include @@ -341,7 +341,7 @@ namespace engine { connectLeadPort (ProcNode& leadNode, uint port) { uint knownEntry{0}; - for (auto& lead : lib::IterIndex{_Par::leads_}) + for (auto& lead : lib::IndexIter{_Par::leads_}) if (util::isSameObject (leadNode, lead)) break; else diff --git a/tests/12metaprogramming.tests b/tests/12metaprogramming.tests index 05097e1e4..4ac6980d1 100644 --- a/tests/12metaprogramming.tests +++ b/tests/12metaprogramming.tests @@ -317,6 +317,11 @@ return: 0 END +TEST "index-based iterator" IndexIter_test 20 < @@ -21,13 +21,13 @@ * *****************************************************/ /** @file iter-index-test.cpp - ** unit test \ref IterIndex_test + ** unit test \ref IndexIter_test */ #include "lib/test/run.hpp" -#include "lib/iter-index.hpp" +#include "lib/index-iter.hpp" #include "lib/test/test-helper.hpp" #include "lib/iter-explorer.hpp" #include "lib/format-util.hpp" @@ -57,9 +57,9 @@ namespace test{ const uint NUM_ELMS = 10; using Numz = vector; - using Iter = IterIndex; - using CIter = IterIndex; - using SMIter = IterIndex>; + using Iter = IndexIter; + using CIter = IndexIter; + using SMIter = IndexIter>; inline Numz makeNumz() @@ -86,7 +86,7 @@ namespace test{ * @see iter-adapter.hpp * @see [usage example](\ref event-log.hpp) */ - class IterIndex_test : public Test + class IndexIter_test : public Test { virtual void @@ -127,11 +127,11 @@ namespace test{ - /** @test verify the ability of IterIndex to access and manipulate + /** @test verify the ability of IndexIter to access and manipulate * the current index position, which can be done any time, while in * the middle of iteration, and even after iteration end. That means, * even an exhausted iterator can be „reanimated“. This manipulation - * is not allowed on a default constructed IterIndex, though. + * is not allowed on a default constructed IndexIter, though. */ void verify_randomAccess () @@ -289,7 +289,7 @@ namespace test{ } }; - LAUNCHER (IterIndex_test, "unit common"); + LAUNCHER (IndexIter_test, "unit common"); }} // namespace lib::test