ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
boxing.hpp
Go to the documentation of this file.
1/** ************************************************************************************************
2 * \file
3 * This header file is part of module \alib_boxing of the \aliblong.
4 *
5 * \emoji :copyright: 2013-2024 A-Worx GmbH, Germany.
6 * Published under \ref mainpage_license "Boost Software License".
7 **************************************************************************************************/
8#ifndef HPP_ALIB_BOXING_BOXING
9#define HPP_ALIB_BOXING_BOXING 1
10
11#if !defined(HPP_ALIB) && !defined(ALIB_DOX)
12# include "alib/alib.hpp"
13#endif
14
16
17
18#if !defined(HPP_ALIB_LANG_TMP) && !defined(ALIB_DOX)
19# include "alib/lang/tmp.hpp"
20#endif
21
22#if !defined(HPP_ALIB_LANG_INTEGERS)
23# include "alib/lang/integers.hpp"
24#endif
25
26#if !defined(HPP_ALIB_SINGLETONS_SINGLETON)
28#endif
29
30#if !defined(HPP_ALIB_CHARACTERS_CHARACTERS)
32#endif
33
34#if ALIB_STRINGS && !defined(HPP_ALIB_STRINGS_FWDS)
35# include "alib/strings/fwds.hpp"
36#endif
37
38#if !defined(HPP_ALIB_BOXING_FWDS)
39# include "alib/boxing/fwds.hpp"
40#endif
41
42#if !defined(HPP_ALIB_LANG_COMMONENUMS_DEFS)
44#endif
45
46#if !defined (_GLIBCXX_TYPEINDEX) && !defined(_TYPEINDEX_)
47# include <typeindex>
48#endif
49
50
51//##################################################################################################
52//################################### INL Headers ###################################
53//##################################################################################################
54
60#include "alib/boxing/box.inl"
61#include "alib/boxing/boxes.inl"
63
64//##################################################################################################
65//######## Namespace functions (Bootstrap, BootstrapRegister, RegisterDefault) ##########
66//##################################################################################################
67namespace alib { namespace boxing {
68
69/** ************************************************************************************************
70 * This method needs to be called with bootstrapping a software.
71 * It mainly registers default and type-specific implementations of the built-in
72 * \ref alib_boxing_functions "box-functions".
73 * In addition, in debug-compilations, \ref alib_boxing_more_opt_staticvt "static vtables" are
74 * registered.
75 *
76 * The \ref alib_manual_bootstrapping "standard bootstrap" code of \alib, hence the (overloaded)
77 * functions \ref alib::Bootstrap will call this function.
78 *
79 * Multiple invocations of this method are ignored.
80 *
81 * \see
82 * For information about using this method, consult chapter
83 * \ref alib_manual_bootstrapping_nocamps of the \ref alib_manual.
84 * ************************************************************************************************/
86void Bootstrap();
87
88/** ************************************************************************************************
89 * Registers \ref alib_boxing_functions "box-function" \p{function} of type \p{TFDecl} for
90 * boxes of mapped type \p{TMapping}.
91 *
92 * \attention
93 * Function registration and function invocation are not protected against racing conditions
94 * of multi-threaded access. For this reason, it is advised to invoke this function exclusively
95 * while \ref alib_manual_bootstrapping "bootstrapping" a software, when no threads are started,
96 * yet. Registrations can be made prior to bootstrapping \alib, respectively during or after
97 * phase \alib{BootstrapPhases::PrepareResources}.
98 *
99 * \attention
100 * If for any reason registration is performed \b after bootstrapping \alib and module
101 * \alib_monomem is included in the \alibdist, and this function is invoked after
102 * \alib was bootstrapped, then prior to an invocation of this method, mutex
103 * \alib{monomem;GlobalAllocatorLock} has to be acquired. This can be done with:
104 *
105 * ALIB_LOCK_WITH( alib::monomem::GlobalAllocatorLock )
106 *
107 * \attention
108 * Note that even when this lock is set, still multi-threaded access to registration and/or
109 * box-function invocations is <b>not allowed</b>.
110 *
111 * @tparam TFDecl The \ref alib_boxing_functions_concepts_decl "type of function" to register.
112 * @tparam TMapping The mapped type that boxes store, which are to be equipped with a specialized
113 * function implementation.<br>
114 * Must be either one of \alib{boxing;TMappedTo;TMappedTo<T>} or
115 * \alib{boxing;TMappedToArrayOf;TMappedToArrayOf<T>}.
116 * @param function Pointer to the function implementation.
117 * ************************************************************************************************/
118template<typename TFDecl, typename TMapping>
119inline
120void BootstrapRegister( typename TFDecl::Signature function )
121{
122 ALIB_ASSERT_ERROR( nullptr == detail::T_VTableFactory<TMapping>::Get()->Functions.template Get<TFDecl>(false),
123 "BOXING", "Doubly defined function" )
124
125 detail::T_VTableFactory<TMapping>::Get()->Functions.template Set<TFDecl>( function );
126}
127
128/** ************************************************************************************************
129 * Registers a default implementation of a \ref alib_boxing_functions "box-function", which
130 * is invoked if no type-specific implementation is registered for a mapped type.
131 *
132 * \attention
133 * Function registration and function invocation are not protected against racing conditions
134 * of multi-threaded access. For this reason, it is advised to invoke this function exclusively
135 * while \ref alib_manual_bootstrapping "bootstrapping" a software, when no threads are started,
136 * yet. Registrations can be made prior to bootstrapping \alib, respectively during or after
137 * phase \alib{BootstrapPhases::PrepareResources}.
138 *
139 * \attention
140 * If for any reason registration is performed \b after bootstrapping \alib and module
141 * \alib_monomem is included in the \alibdist, and this function is invoked after
142 * \alib was bootstrapped, then prior to an invocation of this method, mutex
143 * \alib{monomem;GlobalAllocatorLock} has to be acquired. This can be done with:
144 *
145 * ALIB_LOCK_WITH( alib::monomem::GlobalAllocatorLock )
146 *
147 * \attention
148 * Note that even when this lock is set, still multi-threaded access to registration and/or
149 * box-function invocations is <b>not allowed</b>.
150 *
151 * @tparam TFDecl The \ref alib_boxing_functions_concepts_decl "type of function" to register.
152 * @param function Pointer to the function's default implementation.
153 * ************************************************************************************************/
154template<typename TFDecl>
155inline
156void BootstrapRegisterDefault( typename TFDecl::Signature function )
157{
158 detail::DEFAULT_FUNCTIONS.Set<TFDecl>( function );
159}
160
161
162}} // namespace [alib::boxing]
163
164
165// #################################################################################################
166// T_Append<Box>
167// #################################################################################################
168#if ALIB_STRINGS
170
171namespace alib { namespace strings {
172
173// Faking all template specializations of namespace strings for doxygen into namespace
174// strings::APPENDABLES to keep the documentation of namespace string clean!
175#if defined(ALIB_DOX)
176namespace APPENDABLES {
177#endif
178
179 /**
180 * Specialization of template functor \alib{strings;T_Append} for type \alib{boxing;Box}.
181 */
182 template<typename TChar> struct T_Append<boxing::Box, TChar>
183 {
184 /** ****************************************************************************************
185 * Writes the given boxed object. This is done by invoking box-function
186 * \alib{boxing;FAppend} on box \p{value}.
187 *
188 * @param target The \b AString that \b Append was invoked on.
189 * @param box The box to its contents to \p{target}.
190 ******************************************************************************************/
191 void operator()( TAString<TChar>& target, const boxing::Box& box )
192 {
193 box.Call<boxing::FAppend<TChar>>( target );
194 }
195 };
196
197#if defined(ALIB_DOX)
198} // namespace alib::strings[::appendables]
199#endif
200
201}} // namespace [alib::strings]
202
203#endif // ALIB_STRINGS
204
205#endif // HPP_ALIB_BOXING_BOXING
decltype(std::declval< typename TFDecl::Signature >()(std::declval< Box & >(), std::declval< TArgs >()...)) Call(TArgs &&... args) const
Definition box.inl:1135
#define ALIB_ASSERT_MODULE(modulename)
Definition alib.hpp:190
#define ALIB_API
Definition alib.hpp:538
#define ALIB_ASSERT_ERROR(cond,...)
Definition alib.hpp:984
FunctionTable DEFAULT_FUNCTIONS
Definition vtable.cpp:128
void Bootstrap()
Definition boxing.cpp:732
void BootstrapRegister(typename TFDecl::Signature function)
Definition boxing.hpp:120
void BootstrapRegisterDefault(typename TFDecl::Signature function)
Definition boxing.hpp:156
Definition alib.cpp:57
void Set(typename TFDecl::Signature implementation)
static constexpr VTable * Get()
Definition vtable.inl:456
void operator()(TAString< TChar > &target, const boxing::Box &box)
Definition boxing.hpp:191