Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Deque_Factory.h
Go to the documentation of this file.
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Foundation_Containers_Concrete_Deque_Factory_h_
5#define _Stroika_Foundation_Containers_Concrete_Deque_Factory_h_
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
9/**
10 * \file
11 */
12
14 template <typename T>
15 class Deque;
16}
17
18namespace Stroika::Foundation::Containers::Factory {
19
20 /**
21 * \brief Singleton factory object - Used to create the default backend implementation of a Deque<> container; typically not called directly
22 *
23 * Note - you can override the underlying factory dynamically by calling Deque_Factory<T>::Register ().
24 *
25 * \note \em Thread-Safety <a href="Thread-Safety.md#C++-Standard-Thread-Safety">C++-Standard-Thread-Safety</a>
26 */
27 template <typename T>
29 public:
30 static_assert (not is_reference_v<T>,
31 "typically if this fails its because a (possibly indirect) caller forgot to use forward<TTT>(), or remove_cvref_t");
32
33 public:
34 /**
35 */
37
38 public:
39 /**
40 * Function type to create an ConstructedType object.
41 */
43
44 public:
45 /**
46 * Hints can be used in factory constructor to guide the choice of the best container implementation/backend.
47 */
48 struct Hints {
49 /**
50 * Set false if expected large deque.
51 */
53 };
54
55 public:
56 /**
57 * Construct a factory for producing new ConstructedType objects. The default is to use whatever was registered with
58 * Deque_Factory::Register (), but a specific factory can easily be constructed with provided arguments.
59 */
60 constexpr Deque_Factory ();
61 constexpr Deque_Factory (const Hints& hints);
62 constexpr Deque_Factory (const FactoryFunctionType& f);
63 constexpr Deque_Factory (const Deque_Factory&) = default;
64
65 public:
66 /**
67 * This can be called anytime, before main(), or after. BUT - beware, any calls to Register must
68 * be externally synchronized, meaning effectively that they must happen before the creation of any
69 * threads, to be safe. Also note, since this returns a const reference, any calls to Register() after
70 * a call to Default, even if synchronized, is suspect.
71 */
72 static const Deque_Factory& Default ();
73
74 public:
75 /**
76 * You can call this directly, but there is no need, as the Deque<T> CTOR does so automatically.
77 */
78 nonvirtual ConstructedType operator() () const;
79
80 public:
81 /**
82 * Register a default global factory for ConstructedType objects (of the templated type/parameters).
83 * No need to call, typically, as the default factory is generally fine.
84 *
85 * \par Example Usage
86 * \code
87 * Deque_Factory::Register(Deque_Factory{Deque_Factory::Hints{.fOptimizeForLookupSpeedOverUpdateSpeed=true});
88 * Deque_Factory::Register(); // or use defaults
89 * \endcode
90 *
91 * \note \em Thread-Safety <a href="Thread-Safety.md#C++-Standard-Thread-Safety">C++-Standard-Thread-Safety</a>
92 * BUT - special note/restriction - must be called before any threads call Association_Factory::Deque_Factory() OR
93 * Deque_Factory::Default(), which effectively means must be called at the start of main, but before creating any threads
94 * which might use the factory).
95 *
96 * \note this differs markedly from Stroika 2.1, where Register could be called anytime, and was internally synchronized.
97 *
98 * \note If you wanted a dynamically changeable factory (change after main), you could write one yourself with its own internal synchronization,
99 * set the global one here, then perform the changes to its internal structure through another API.
100 */
101 static void Register (const optional<Deque_Factory>& f = nullopt);
102
103 private:
104 FactoryFunctionType fFactory_;
105
106 private:
107 // function to assure magically constructed even if called before main
108 static Deque_Factory& AccessDefault_ ();
109 };
110
111}
112
113/*
114 ********************************************************************************
115 ******************************* Implementation Details *************************
116 ********************************************************************************
117 */
118#include "Deque_Factory.inl"
119
120#endif /*_Stroika_Foundation_Containers_Concrete_Deque_Factory_h_ */
Singleton factory object - Used to create the default backend implementation of a Deque<> container; ...
static void Register(const optional< Deque_Factory > &f=nullopt)