Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
ArraySupport.h
Go to the documentation of this file.
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4
5#ifndef _Stroika_Foundation_Containers_Private_ArraySupport_h_
6#define _Stroika_Foundation_Containers_Private_ArraySupport_h_
7
8#include "Stroika/Foundation/StroikaPreComp.h"
9
10#include "Stroika/Foundation/Common/Common.h"
11
12#include "Stroika/Foundation/Containers/Common.h"
13#include "Stroika/Foundation/Containers/DataStructures/Array.h"
14
15/**
16 * \file
17 * support classes for Concrete classes 'extensions' of behavior specific to the Array data structure
18 */
19
21
22 /**
23 * \brief ArrayBasedContainer is a Stroika implementation detail, but its public methods are fair game and fully supported (as used in subclasses)
24 *
25 * This mechanism allows all the array based concrete containers (such as Set_Array, Sequence_Array) to all
26 * share the same API and implementation of the API access functions (shrink_to_fit, reserve etc) but without
27 * any genericity implied in the API (just code sharing).
28 *
29 * \note bool USING_IREP:
30 * Can we just peek from ArrayBasedContainer<> into the fData_ and do the array operations? Yes, if Rep_ is not
31 * type-erased, but no otherwise. If we specify false, we can avoid putting references to the ArrayBasedContainerIRep
32 * into the vtable, and linking a bunch of often not used code. But if we've got extra template parameters to the Rep_,
33 * we cannot peek at it from this container, so must indirect.
34 */
35 template <typename THIS_CONTAINER, typename BASE_CONTAINER, bool USING_IREP>
36 class ArrayBasedContainer : public BASE_CONTAINER {
37 public:
38 /**
39 */
40 template <typename... ARGS>
41 ArrayBasedContainer (ARGS... args);
42
43 public:
44 /*
45 * \brief Return the number of allocated vector/array elements.
46 *
47 * This optional API allows pre-reserving space as an optimization.
48 *
49 * @aliases GetCapacity ();
50 */
51 nonvirtual size_t capacity () const;
52
53 public:
54 /**
55 * This optional API allows pre-reserving space as an optimization.
56 *
57 * @aliases SetCapacity ();
58 *
59 * \note Note that this does not affect the semantics of the container.
60 *
61 * \pre slotsAllocated >= size ()
62 */
63 nonvirtual void reserve (size_t slotsAlloced);
64
65 public:
66 /**
67 * \brief Reduce the space used to store the container contents.
68 *
69 * This has no semantics, no observable behavior. But depending on the representation of
70 * the concrete container, calling this may save memory.
71 */
72 nonvirtual void shrink_to_fit ();
73 };
74
75 /**
76 * \brief impl detail for array based container support (see ArrayBasedContainer docs on bool USING_IREP)
77 */
78 template <typename CONTAINER_REP_BASE_CLASS>
79 class ArrayBasedContainerIRep : public CONTAINER_REP_BASE_CLASS {
80 public:
81 virtual void shrink_to_fit () = 0;
82 virtual size_t capacity () const = 0;
83 virtual void reserve (size_t slotsAlloced) = 0;
84 };
85
86 /**
87 * \brief CRTP applied when ArrayBasedContainerIRep used
88 */
89 template <typename THIS_CONTAINER_REP, typename BASE_CONTAINER_REP>
90 class ArrayBasedContainerRepImpl : public BASE_CONTAINER_REP {
91 public:
92 /**
93 */
94 template <typename... ARGS>
95 ArrayBasedContainerRepImpl (ARGS... args);
96 virtual void shrink_to_fit () override;
97 virtual size_t capacity () const override;
98 virtual void reserve (size_t slotsAlloced) override;
99 };
100
101}
102
103/*
104 ********************************************************************************
105 ***************************** Implementation Details ***************************
106 ********************************************************************************
107 */
108#include "ArraySupport.inl"
109
110#endif /*_Stroika_Foundation_Containers_Private_ArraySupport_h_ */
ArrayBasedContainer is a Stroika implementation detail, but its public methods are fair game and full...
nonvirtual void shrink_to_fit()
Reduce the space used to store the container contents.
impl detail for array based container support (see ArrayBasedContainer docs on bool USING_IREP)
CRTP applied when ArrayBasedContainerIRep used.