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