ALib C++ Library
Library Version: 2412 R0
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#pragma once
11#if !defined(DOXYGEN)
12# include "alib/alib.hpp"
13#endif
14
16
17
18#include "alib/lang/tmp.hpp"
22
23#if ALIB_STRINGS
24# include "alib/strings/fwds.hpp"
25#endif
26
27#include "alib/boxing/fwds.hpp"
29#include <typeindex>
30
31//##################################################################################################
32//################################### INL Headers ###################################
33//##################################################################################################
34
40#include "alib/boxing/box.inl"
41#include "alib/boxing/boxes.inl"
43
44//##################################################################################################
45//######## Namespace functions (Bootstrap, BootstrapRegister, RegisterDefault) ##########
46//##################################################################################################
48namespace alib { namespace boxing {
49
50//==================================================================================================
51/// This method needs to be called with bootstrapping a process.
52/// It mainly registers default and type-specific implementations of the built-in
53/// \ref alib_boxing_functions "box-functions".
54/// In addition, in debug-compilations, \ref alib_boxing_more_opt_staticvt "static vtables" are
55/// registered.
56///
57/// The \ref alib_manual_bootstrapping "standard bootstrap" code of \alib, hence the (overloaded)
58/// functions \ref alib::Bootstrap will call this function.
59///
60/// Multiple invocations of this method are forbidden.
61///
62/// \see
63/// For information about using this method, consult chapter
64/// \ref alib_manual_bootstrapping_nocamps of the \ref alib_manual.
65//==================================================================================================
67void Bootstrap();
68
69//==================================================================================================
70/// Frees resources and shuts down module \alib_boxing.
71/// Multiple invocations of this method are forbidden.
72/// The \ref alib_manual_bootstrapping "standard bootstrap" code of \alib, hence the (overloaded)
73/// functions \ref alib::Shutdown will call this function.
74///
75/// \see
76/// Sibling function \alib{boxing::Bootstrap}.
77//==================================================================================================
79void Shutdown();
80
81//==================================================================================================
82/// Registers \ref alib_boxing_functions "box-function" \p{function} of type \p{TFDecl} for
83/// boxes of mapped type \p{TMapping}.
84///
85/// \attention
86/// Function registration and function invocation are not protected against racing conditions
87/// of multithreaded access. For this reason, it is advised to invoke this function exclusively
88/// while \ref alib_manual_bootstrapping "bootstrapping" a software, when no threads are started,
89/// yet. Registrations can be made before bootstrapping \alib, respectively during or after
90/// phase \alib{BootstrapPhases::PrepareResources}.
91///
92/// \attention
93/// If for any reason registration is performed \b after bootstrapping \alib and module
94/// \alib_monomem is included in the \alibdist, and this function is invoked after
95/// \alib was bootstrapped, then before an invocation of this method, mutex
96/// \alib{monomem;GLOBAL_ALLOCATOR_LOCK} has to be acquired. This can be done with:
97/// \snippet "ut_monomem.cpp" DOX_MONOMEM_LOCK_GLOBALALLOCATOR
98///
99/// \attention
100/// Note that even when this lock is set, still multithreaded access to registration and/or
101/// box-function invocations is <b>not allowed</b>.
102///
103/// @tparam TFDecl The \ref alib_boxing_functions_concepts_decl "type of function" to register.
104/// @tparam TMapping The mapped type that boxes store, which are to be equipped with a specialized
105/// function implementation.<br>
106/// Must be either one of \alib{boxing;TMappedTo;TMappedTo<T>} or
107/// \alib{boxing;TMappedToArrayOf;TMappedToArrayOf<T>}.
108/// @param function Pointer to the function implementation.
109//==================================================================================================
110template<typename TFDecl, typename TMapping>
111inline
112void BootstrapRegister( typename TFDecl::Signature function )
113{
115 nullptr == detail::T_VTableFactory<TMapping>::Get()->Functions.template Get<TFDecl>(false),
116 "BOXING", "Doubly defined function" )
117
118 detail::T_VTableFactory<TMapping>::Get()->Functions.template Set<TFDecl>( function );
119}
120
121//==================================================================================================
122/// Registers a default implementation of a \ref alib_boxing_functions "box-function", which
123/// is invoked if no type-specific implementation is registered for a mapped type.
124///
125/// \attention
126/// Function registration and function invocation are not protected against racing conditions
127/// of multithreaded access. For this reason, it is advised to invoke this function exclusively
128/// while \ref alib_manual_bootstrapping "bootstrapping" a software, when no threads are started,
129/// yet. Registrations can be made before bootstrapping \alib, respectively during or after
130/// phase \alib{BootstrapPhases::PrepareResources}.
131///
132/// \attention
133/// If for any reason registration is performed \b after bootstrapping \alib and module
134/// \alib_monomem is included in the \alibdist, and this function is invoked after
135/// \alib was bootstrapped, then, before an invocation of this method, mutex
136/// \alib{monomem;GLOBAL_ALLOCATOR_LOCK} has to be acquired. This can be done with:
137/// \snippet "ut_monomem.cpp" DOX_MONOMEM_LOCK_GLOBALALLOCATOR
138///
139/// \attention
140/// Note that even when this lock is set, still multithreaded access to registration and/or
141/// box-function invocations is <b>not allowed</b>.
142///
143/// @tparam TFDecl The \ref alib_boxing_functions_concepts_decl "type of function" to register.
144/// @param function Pointer to the function's default implementation.
145//==================================================================================================
146template<typename TFDecl>
147inline
148void BootstrapRegisterDefault( typename TFDecl::Signature function )
149{
150 detail::DEFAULT_FUNCTIONS.Set<TFDecl>( function );
151}
152
153}} // namespace [alib::boxing]
155
156
157// #################################################################################################
158// T_Append<Box>
159// #################################################################################################
160#if ALIB_STRINGS
161#define HPP_ALIB_STRINGS_TASTRING_INLINING
163#undef HPP_ALIB_STRINGS_TASTRING_INLINING
164
165namespace alib { namespace strings {
166
167// Faking all template specializations of namespace strings for doxygen into namespace
168// strings::APPENDABLES to keep the documentation of namespace string clean!
169#if DOXYGEN
170namespace APPENDABLES {
171#endif
172
173 /// Specialization of template functor \alib{strings;T_Append} for type \alib{boxing;Box}.
174 /// @tparam TChar The character type of the target \b %Astring.
175 /// @tparam TAllocator The allocator that the target \b %AString uses, as prototyped with
176 /// \alib{lang;Allocator}.
177 template<typename TChar, typename TAllocator> struct T_Append<boxing::Box, TChar, TAllocator>
178 {
179 //==========================================================================================
180 /// Writes the given boxed object. This is done by invoking box-function
181 /// \alib{boxing;FAppend} on box \p{value}.
182 ///
183 /// @param target The \b AString that \b Append was invoked on.
184 /// @param box The box to its contents to \p{target}.
185 //==========================================================================================
187 {
189 }
190 };
191
192#if DOXYGEN
193} // namespace alib::strings[::appendables]
194#endif
195
196}} // namespace [alib::strings]
197
198#endif // ALIB_STRINGS
199
200#endif // HPP_ALIB_BOXING_BOXING
201
202
203
decltype(std::declval< typename TFDecl::Signature >()(std::declval< Box & >(), std::declval< TArgs >()...)) Call(TArgs &&... args) const
Definition box.inl:1175
#define ALIB_ASSERT_MODULE(modulename)
Definition alib.hpp:223
#define ALIB_API
Definition alib.hpp:639
#define ALIB_ASSERT_ERROR(cond,...)
Definition alib.hpp:1271
FunctionTable DEFAULT_FUNCTIONS
The default box-functions set.
Definition vtable.cpp:112
void Bootstrap()
Definition boxing.cpp:708
void BootstrapRegister(typename TFDecl::Signature function)
Definition boxing.hpp:112
void BootstrapRegisterDefault(typename TFDecl::Signature function)
Definition boxing.hpp:148
void Shutdown()
Definition boxing.cpp:701
Definition alib.cpp:69
void Set(typename TFDecl::Signature implementation)
static constexpr VTable * Get()
Definition vtable.inl:439
FunctionTable Functions
Box-functions attached with BootstrapRegister.
Definition vtable.inl:212
void operator()(TAString< TChar, TAllocator > &target, const boxing::Box &box)
Definition boxing.hpp:186