From b01fc6e350a375dd54294ec5edf3ffc6bf5e6ce7 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 7 Jul 2024 04:20:46 +0200 Subject: [PATCH] Invocation: adjustments to `lib::Several` to prepare for allocator use MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * conduct analysis regarding allocator handling in the Builder * turns out we'll have to keep around two different allocators while building * ⟹ establish the goal to confine usage of the Node allocator to the lower Levels * consequently must open up the `lib::SeveralBuilder` to be usable as an intermediary data structure, while building up the target data * in the initial design, the `SeveralBuilder` was kept opaque, since contents can be expected to be re-located frequently and thus exposing elements and taking references could be dangerous — yet this is also true for `std::vector` however, so people are assumed to know when they want to shoot themselves into their own foot --- src/lib/several-builder.hpp | 16 +++ src/lib/several.hpp | 4 +- tests/library/several-builder-test.cpp | 6 +- wiki/thinkPad.ichthyo.mm | 172 +++++++++++++++++++++---- 4 files changed, 167 insertions(+), 31 deletions(-) diff --git a/src/lib/several-builder.hpp b/src/lib/several-builder.hpp index a5709364f..65075969f 100644 --- a/src/lib/several-builder.hpp +++ b/src/lib/several-builder.hpp @@ -147,6 +147,8 @@ namespace lib { using std::is_const_v; using std::is_same_v; using lib::meta::is_Subclass; + + using several::ArrayBucket; /** @@ -507,6 +509,20 @@ namespace lib { size_t capacity() const { return Coll::storageBuffSiz() / Coll::spread(); } size_t capReserve() const { return capacity() - size(); } + /** allow to peek into data emplaced thus far... + * @warning contents may be re-allocated until the final \ref build() + */ + I& + operator[] (size_t idx) + { + if (idx >= Coll::size()) + throw err::Invalid{_Fmt{"Access index %d >= size(%d)."} + % idx % Coll::size() + ,LERR_(INDEX_BOUNDS) + }; + return Coll::operator[] (idx); + } + private: /* ========= Implementation of element placement ================ */ template diff --git a/src/lib/several.hpp b/src/lib/several.hpp index 1c04411bf..b54469c1d 100644 --- a/src/lib/several.hpp +++ b/src/lib/several.hpp @@ -69,7 +69,7 @@ namespace lib { - namespace {// Storage header implementation details + namespace several {// Storage header implementation details /** @internal mix-in for self-destruction capabilities * @remark the destructor function is assumed to perform deallocation; @@ -166,7 +166,7 @@ namespace lib { : util::MoveAssign { protected: - using Bucket = ArrayBucket*; + using Bucket = several::ArrayBucket*; Bucket data_{nullptr}; diff --git a/tests/library/several-builder-test.cpp b/tests/library/several-builder-test.cpp index baba90255..a0fea46e7 100644 --- a/tests/library/several-builder-test.cpp +++ b/tests/library/several-builder-test.cpp @@ -55,6 +55,8 @@ using util::join; namespace lib { namespace test{ + using LERR_(INDEX_BOUNDS); + namespace { // invocation tracking diagnostic subclass... /** @@ -193,7 +195,9 @@ namespace test{ builder.emplace>() .emplace>(1); - CHECK (2 == builder.size()); + CHECK (2 == builder.size()); // use information functions... + CHECK (3 == builder[1].getVal()); // to peek into contents assembled thus far... + VERIFY_ERROR (INDEX_BOUNDS, builder[2] ); // runtime bounds check on the builder (but not on the product!) builder.fillElm(2); CHECK (4 == builder.size()); builder.fillElm(3, 5); diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 58194df1b..e5f6bf7e3 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -1248,9 +1248,7 @@ - - - +

...denn eigentlich geht es nur um ein einfaches Producer-Interface, @@ -2032,9 +2030,7 @@ - - - +

wenn nämlich das "Expandieren" in einen weiter reichenden Zusammenhang integriert ist, @@ -3328,9 +3324,7 @@ - - - +

Konzept ist nicht, sie gleich in die description zu übernehmen @@ -4483,9 +4477,7 @@ - - - +

meint: zwei gekoppelte Statusvariable @@ -6883,9 +6875,7 @@ - - - +

...und der wird in der Tat an vielen Stellen includiert @@ -8795,9 +8785,7 @@ - - - +

...da IterExplorer einen Template-Template-Parameter nimmt, @@ -10154,9 +10142,7 @@ - - - +

will sagen, das ist ja auch eine durchgeknallte Idee.... @@ -10167,9 +10153,7 @@ - - - +

wenn eine Funktion in einem Layer expanded @@ -10179,9 +10163,7 @@ - - - +

...d.h, entweder man gibt aus dem Functor das zurück, @@ -82083,6 +82065,9 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + @@ -82410,6 +82395,51 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + + + + + + + + + + + +

+ ...da der Typ des Builders vom Allocator abhängt +

+ + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + @@ -86140,6 +86170,17 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + + + + + + + + + @@ -87449,13 +87490,53 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -88674,6 +88755,41 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + + + + + + + + + + + + +

+ alle Werte müssen zuverlässig in die Zieldatenstruktur kopiert  werden +

+ + +
+
+ + + + + + + + + + + + + +