From e3263717623402415fbe41877f93911d2108dcd5 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Thu, 16 Nov 2023 14:02:38 +0100 Subject: [PATCH] gems: make gems/dynamic_array.h publicly available The 'Dynamic_array' utility is used by the text_area as internal representation of text. As a prerequisite step of making the text editing features generally available as a text-area widget, the utility must become public. Issue #5008 --- .../gems}/dynamic_array.h | 35 ++++++------------- 1 file changed, 11 insertions(+), 24 deletions(-) rename repos/gems/{src/app/text_area => include/gems}/dynamic_array.h (84%) diff --git a/repos/gems/src/app/text_area/dynamic_array.h b/repos/gems/include/gems/dynamic_array.h similarity index 84% rename from repos/gems/src/app/text_area/dynamic_array.h rename to repos/gems/include/gems/dynamic_array.h index 04ced3ba4b..cc1582a154 100644 --- a/repos/gems/src/app/text_area/dynamic_array.h +++ b/repos/gems/include/gems/dynamic_array.h @@ -11,23 +11,16 @@ * under the terms of the GNU Affero General Public License version 3. */ -#ifndef _DYNAMIC_ARRAY_H_ -#define _DYNAMIC_ARRAY_H_ +#ifndef _INCLUDE__GEMS__DYNAMIC_ARRAY_H_ +#define _INCLUDE__GEMS__DYNAMIC_ARRAY_H_ -/* Genode includes */ #include -namespace Text_area { - - using namespace Genode; - - template - struct Dynamic_array; -} +namespace Genode { template struct Dynamic_array; } template -struct Text_area::Dynamic_array +struct Genode::Dynamic_array { public: @@ -89,8 +82,7 @@ struct Text_area::Dynamic_array destruct(Index{i - 1}); } - template - void insert(Index at, ARGS &&... args) + void insert(Index at, auto &&... args) { /* grow array if index exceeds current capacity or if it's full */ if (at.value >= _capacity || _upper_bound == _capacity) { @@ -132,8 +124,7 @@ struct Text_area::Dynamic_array _upper_bound = max(at.value + 1, _upper_bound + 1); } - template - void append(ARGS &&... args) { insert(Index{_upper_bound}, args...); } + void append(auto &&... args) { insert(Index{_upper_bound}, args...); } bool exists(Index at) const { return _index_valid(at); } @@ -154,15 +145,13 @@ struct Text_area::Dynamic_array _array[_upper_bound].destruct(); } - template - void apply(Index at, FN const &fn) + void apply(Index at, auto const &fn) { if (_index_valid(at)) fn(*_array[at.value]); } - template - void apply(Index at, FN const &fn) const + void apply(Index at, auto const &fn) const { if (_index_valid(at)) fn(*_array[at.value]); @@ -170,8 +159,7 @@ struct Text_area::Dynamic_array struct Range { Index at; unsigned length; }; - template - void for_each(Range range, FN const &fn) const + void for_each(Range range, auto const &fn) const { unsigned const first = range.at.value; unsigned const limit = min(_upper_bound, first + range.length); @@ -181,8 +169,7 @@ struct Text_area::Dynamic_array fn(Index{i}, *_array[i]); } - template - void for_each(FN const &fn) const + void for_each(auto const &fn) const { for_each(Range { .at = { 0U }, .length = ~0U }, fn); } @@ -195,4 +182,4 @@ struct Text_area::Dynamic_array } }; -#endif /* _DYNAMIC_ARRAY_H_ */ +#endif /* _INCLUDE__GEMS__DYNAMIC_ARRAY_H_ */