From 73adcdf2e0c1a8883406494dfc4fe78477337efe Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Fri, 29 Sep 2017 15:03:14 +0200 Subject: [PATCH] UI-Coordinates: initial draft for PathArray storage after various fruitless attempts to rely somehow on the array variant of unique_ptr, I ended up with a hand coded version of an heap allocated array, managed automatically --- src/lib/path-array.hpp | 49 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/src/lib/path-array.hpp b/src/lib/path-array.hpp index 738666925..f5d9529fc 100644 --- a/src/lib/path-array.hpp +++ b/src/lib/path-array.hpp @@ -62,9 +62,48 @@ namespace lib { using std::string; using lib::Literal; -// class GlobalCtx; - namespace { // Implementation helper: variadic init + namespace { // Implementation helper: flexible heap based extension storage.... + /** + * Heap-allocated extension storage for an immutable sequence of literal strings. + * The size of the allocation is determined and fixed once, at construction time, + * derived from the number of initialisers. The first slot within the allocation + * stores this length. Extension can be _empty_ (default constructed), + * in which case no heap allocation is performed. + */ + class Extension + { + using PStorage = const char**; + + PStorage storage_; + + + static size_t& + size (PStorage& p) + { + REQUIRE (p); + return reinterpret_cast (p[0]); + } + + public: + Extension() + : storage_{nullptr} + { } + + template + explicit + Extension (ELMS ...elms) + : storage_{new const char* [1 + sizeof...(ELMS)]} + { + size(storage_) = sizeof...(ELMS); + storage_[1] = {elms...}; + } + ~Extension() + { + if (storage_) + delete[] storage_; + } + }; }//(End)Implementation helper @@ -78,8 +117,10 @@ namespace lib { template class PathArray { - std::array elms_; - std::unique_ptr tail_; + using LitArray = std::array; + + LitArray elms_; + Extension tail_; public: template