Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
SparseDataHyperRectangle_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_SparseDataHyperRectangle_Factory_h_
5#define _Stroika_Foundation_Containers_Concrete_SparseDataHyperRectangle_Factory_h_
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
9/**
10 * \file
11 */
12
14 template <typename T, typename... INDEXES>
15 class SparseDataHyperRectangle;
16}
17
18namespace Stroika::Foundation::Containers::Factory {
19
20 /**
21 * \brief Singleton factory object - Used to create the default backend implementation of a SparseDataHyperRectangle<> container; typically not called directly
22 *
23 * Note - you can override the underlying factory dynamically by calling SparseDataHyperRectangle_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, typename... INDEXES>
29 public:
30 /**
31 * The type of object produced by the factory.
32 */
34
35 public:
36 /**
37 * Function type to create an ConstructedType object.
38 */
40
41 public:
42 /**
43 */
44 struct Hints {};
45
46 public:
47 /**
48 * Construct a factory for producing new ConstructedType objects. The default is to use whatever was registered with
49 * SparseDataHyperRectangle_Factory::Register (), but a specific factory can easily be constructed with provided arguments.
50 */
52 constexpr SparseDataHyperRectangle_Factory (const Hints& hints);
55
56 public:
57 /**
58 * This can be called anytime, before main(), or after. BUT - beware, any calls to Register must
59 * be externally synchronized, meaning effectively that they must happen before the creation of any
60 * threads, to be safe. Also note, since this returns a const reference, any calls to Register() after
61 * a call to Default, even if synchronized, is suspect.
62 */
64
65 public:
66 /**
67 * You can call this directly, but there is no need, as the SparseDataHyperRectangle<T, INDEXES...> CTOR does so automatically.
68 */
69 nonvirtual ConstructedType operator() (Common::ArgByValueType<T> defaultItem = {}) const;
70
71 public:
72 /**
73 * Register a default global factory for ConstructedType objects (of the templated type/parameters).
74 * No need to call, typically, as the default factory is generally fine.
75 *
76 * \par Example Usage
77 * \code
78 * SparseDataHyperRectangle_Factory::Register(SparseDataHyperRectangle_Factory{SparseDataHyperRectangle_Factory::Hints{.fOptimizeForLookupSpeedOverUpdateSpeed=true});
79 * SparseDataHyperRectangle_Factory::Register(); // or use defaults
80 * \endcode
81 *
82 * \note \em Thread-Safety <a href="Thread-Safety.md#C++-Standard-Thread-Safety">C++-Standard-Thread-Safety</a>
83 * BUT - special note/restriction - must be called before any threads call Association_Factory::SparseDataHyperRectangle_Factory() OR
84 * SparseDataHyperRectangle_Factory::Default(), which effectively means must be called at the start of main, but before creating any threads
85 * which might use the factory).
86 *
87 * \note this differs markedly from Stroika 2.1, where Register could be called anytime, and was internally synchronized.
88 *
89 * \note If you wanted a dynamically changeable factory (change after main), you could write one yourself with its own internal synchronization,
90 * set the global one here, then perform the changes to its internal structure through another API.
91 */
92 static void Register (const optional<SparseDataHyperRectangle_Factory>& f = nullopt);
93
94 private:
95 FactoryFunctionType fFactory_;
96
97 private:
98 // function to assure magically constructed even if called before main
99 static SparseDataHyperRectangle_Factory& AccessDefault_ ();
100 };
101
102}
103
104/*
105 ********************************************************************************
106 ******************************* Implementation Details *************************
107 ********************************************************************************
108 */
109#include "SparseDataHyperRectangle_Factory.inl"
110
111#endif /*_Stroika_Foundation_Containers_Concrete_SparseDataHyperRectangle_Factory_h_ */
Singleton factory object - Used to create the default backend implementation of a SparseDataHyperRect...
nonvirtual ConstructedType operator()(Common::ArgByValueType< T > defaultItem={}) const
static void Register(const optional< SparseDataHyperRectangle_Factory > &f=nullopt)
function< ConstructedType(Common::ArgByValueType< T > defaultItem)> FactoryFunctionType
conditional_t<(sizeof(CHECK_T)<=2 *sizeof(void *)) and is_trivially_copyable_v< CHECK_T >, CHECK_T, const CHECK_T & > ArgByValueType
This is an alias for 'T' - but how we want to pass it on stack as formal parameter.
Definition TypeHints.h:32