ALib C++ Framework
by
Library Version: 2605 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
boxing_format_debug.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/// Copyright 2013-2026 A-Worx GmbH, Germany.
6/// Published under #"mainpage_license".
7//==================================================================================================
8#if ALIB_DEBUG_BOXING
11
12//==================================================================================================
13/// Template class implementing a monotonically allocated vector of variadic tuples whose first
14/// element is of type #"^String".
15///
16/// When new tuples are added with the method #".Add", then memory for copying the provided string is
17/// allocated using an internal field of type #"MonoAllocator".
18/// This allows adding single strings, which are allocated in bigger memory buffers.
19///
20/// Standard vector operations, including insertions and deletions are still allowed.
21/// In other words, it is allowed to store string objects which are pointing to string data that
22/// is \b not allocated in the internal buffers.
23///
24/// The associated values are especially useful when the vector is sorted (e.g., using
25/// \c std::sort), because such associations will be kept intact and allow referencing back
26/// to whatever the strings represents.
27///
28/// \par Availability
29/// This function is an extension, which is injected by the higher-level module \alib_format and
30/// is accessed through the header file #"F;ALib.Format.H".
31/// Furthermore, the configuration macro #"ALIB_DEBUG_BOXING" has to be set.
32//==================================================================================================
33template< typename... TAssociatedTypes >
34struct DbgStringTable : public std::vector<std::tuple<String, TAssociatedTypes...>> {
35 /// Shortcut to the <c>std::tuple</c>-type that instantiations of this template class store.
36 using ElementType= std::tuple<String, TAssociatedTypes...>;
37
38 /// Shortcut to the base type of this type.
39 using Base = std::vector<ElementType>;
40
41 /// Allocator for making copies of inserted strings
43
44 /// Constructor.
45 /// @param monoAllocator A mono allocator used to create copies of the inserted strings
46 DbgStringTable( MonoAllocator& monoAllocator )
47 : allocator(monoAllocator) {}
48
49 /// Adds a tuple. The contents of the string of the tuple (its first element) is copied
50 /// from the given string \p{src}. The memory for this string is allocated using
51 /// the allocator provided in the constructor.<br>
52 /// The other members of the tuple added are forwarded from variadic parameter block \p{args}.
53 ///
54 /// @param src The string to copy into the first member of the tuple.
55 /// @param args Variadic arguments to fill the rest of the inserted tuple.
56 ///
57 /// @return A reference to the string that was added.
58 template <typename... TArgs>
59 String& Add( const String& src, TArgs&&... args ) {
60 // on errors, see note above!
61 Base::emplace_back( String(allocator, src), std::forward<TArgs>(args)... );
62 return std::get<0>( std::vector<std::tuple<String, TAssociatedTypes...>>::back() );
63 }
64};
65
66/// See function #".TypeInfo(const String&, const String&)", which invokes this function using
67/// template parameter \p{TBoxable}
68/// \par Availability
69/// This function is an extension, which is injected by the higher-level module \alib_format and
70/// is accessed through the header file #"F;ALib.Format.H".
71/// Furthermore, the configuration macro #"ALIB_DEBUG_BOXING" has to be set.
72///
73/// @param[out] target The target string.
74/// @param vtable The vtable of the mapped type.
75/// @param indent Empty or a string of spaces that are alwys preprended
76/// before each entry.
77/// @param srcIsPointer Denotes if \p{TBoxable} is a pointer type.
78/// @param srcIsStringType Denotes if \p{TBoxable} is a string-type in the sense
79/// that a specialization of the
80/// struct #"ArrayTraits" allows implicit access
81/// to character array data.
82/// @param srcIsUnboxableStringType Denotes if \p{TBoxable} is a string-type that can,
83/// due to a specialization of the
84/// struct #"ArrayTraits" be implicitly
85/// constructed from character array types.
86/// @param isValueTypeCustomized Denotes if the value type of \p{TBoxable} is customized.
87/// @param isPointerTypeCustomized Denotes if the pointer type of \p{TBoxable} is
88/// customized.
89/// @param fitsToPlaceholder Denotes if the value type of \p{TBoxable} would fit to
90/// placeholder.
91/// @param copyConstructible Denotes if the value type of \p{TBoxable} is
92/// copy constructible.
93/// @param triviallyDestructible Denotes if the value type of \p{TBoxable} is
94/// trivially destructible.
95/// @param isUnboxable Denotes if \p{TBoxable} is unboxable.
97void typeInfo( AString& target,
98 const detail::VTable* vtable,
99 const String& indent,
100 bool srcIsPointer,
101 bool srcIsStringType,
102 bool srcIsUnboxableStringType,
103 bool isValueTypeCustomized,
104 bool isPointerTypeCustomized,
105 bool fitsToPlaceholder,
106 bool copyConstructible,
107 bool triviallyDestructible,
108 bool isUnboxable );
109
110
111/// Collects necessary information from template type \p{TBoxable} and invokes
112/// #".typeInfo".<br>
113/// See function #".TypeInfo(const String&, const String&)".
114///
115/// \par Availability
116/// This function is an extension, which is injected by the higher-level module \alib_format and
117/// is accessed through the header file #"F;ALib.Format.H".
118/// Furthermore, the configuration macro #"ALIB_DEBUG_BOXING" has to be set.
119///
120/// @tparam TBoxable The boxable type to investigate in.
121/// @param box A box containing a "sample" of \p{TBoxable.}. If this box contains a different
122/// type than \p{TBoxable}, this function has undefined behavior.
123/// @param headline The headline to write.
124/// @param indent Spaces to write before each entry.
125/// @return A string containing the requested information.
126template<typename TBoxable>
127AString TypeInfo( const Box& box,
128 const String& headline= A_CHAR("Boxing Information For Boxable Type: "),
129 const String& indent = A_CHAR(" " ) ) {
130 AString target;
131 using TSrc= std::remove_cv_t<TBoxable>;
132 using TVal= ALIB_TVALUE(TBoxable);
133
134 // repeat twice to get auto-tabs adjusted
136 Formatter& formatter= *Formatter::DEFAULT;
137 formatter.Reset();
138 for( int theSakeOfAutoTabs= 0 ; theSakeOfAutoTabs < 2 ; ++theSakeOfAutoTabs ) {
139 NString512 demangled(typeid(TSrc) );
140 target.Reset() << headline << demangled << NEW_LINE;
141 RemoveNamespaces( target, headline.Length() );
142
143 if( std::same_as<TSrc, std::nullptr_t> ) {
144 target << indent << "'std::nullptr_t' sets a box to void state" << NEW_LINE;
145 return target;
146 }
147
148 typeInfo( target,
149 box.DbgGetVTable(),
150 indent,
151 std::is_pointer_v<TSrc>,
156 sizeof(boxing::Placeholder) <= sizeof(TVal),
157 std::is_copy_constructible <TVal>::value,
158 std::is_trivially_destructible<TVal>::value,
159 boxing::IsUnboxable <TSrc > );
160
161 }
162 return target;
163}
164
165/// Returns human-readable information about the type \p{TBoxable} in respect to how boxing
166/// objects of this type is performed.
167///
168/// The implementation of this function creates a default value of \p{TBoxable}, boxes this
169/// and returns the result of #".TypeInfo(const Box&,const String&,const String&)".
170/// Hence, for types that are not default-constructible, the function #"%.TypeInfo(const Box&);()"
171/// has to be used with a accordingly boxed "sample" of type \p{TBoxable}
172///
173/// \note
174/// Does not work for type \c void*, which is not customizable anyhow
175/// (always boxed as \c void*).
176///
177///
178/// \par Availability
179/// This function is an extension, which is injected by the higher-level module \alib_format and
180/// is accessed through the header file #"F;ALib.Format.H".
181/// Furthermore, the configuration macro #"ALIB_DEBUG_BOXING" has to be set.
182///
183/// @tparam TBoxable The boxable type to investigate in.
184/// @param headline The headline to write.
185/// @param indent Spaces to write before each entry.
186/// @return A string containing the requested information.
187template<typename TBoxable>
188AString TypeInfo( const String& headline = A_CHAR( "Boxing Information For Boxable Type: ") ,
189 const String& indent = A_CHAR( " " ) )
190 { return TypeInfo<TBoxable>( TBoxable(), headline, indent ); }
191
192
193//##################################################################################################
194// Dump
195//##################################################################################################
196/// Takes a vector of pairs of \c std::type_info pointers and a usage counter and returns an
197/// #"%AString" with a sorted list of type names, including their counter information.
198///
199/// \par Availability
200/// This function is an extension, which is injected by the higher-level module \alib_format and
201/// is accessed through the header file #"F;ALib.Format.H".
202/// Furthermore, the configuration macro #"ALIB_DEBUG_BOXING" has to be set.
203///
204/// @param input A list of types.
205/// @param headline The headline to write.
206/// @param indent Spaces to write before each entry.
207/// @return A list of demangled type names.
210 const std::vector<std::pair<const std::type_info*,uinteger>>& input,
211 const String& headline = EMPTY_STRING,
212 const String& indent = EMPTY_STRING );
213
214/// Helper for (bigger part of) #".DumpFunctions".
215///
216/// \par Availability
217/// This function is an extension, which is injected by the higher-level module \alib_format and
218/// is accessed through the header file #"F;ALib.Format.H".
219/// Furthermore, the configuration macro #"ALIB_DEBUG_BOXING" has to be set.
220/// @param input A list of types and usage numbers.
221/// @param[out] output A string to write to.
222/// @param headline The headline to write.
223/// @param indent Spaces to write before each entry.
224/// @param tmpStrings A buffer needed for internal use.
226void dumpFunctions ( const std::vector<std::pair<const std::type_info*,uinteger>>& input,
227 AString& output,
228 const String& headline,
229 const String& indent,
230 DbgStringTable<uinteger>& tmpStrings );
231
232
233/// Lists all mapped types with either static or dynamic \e vtables.
234/// Along with each type, its default function implementations are given.
235///
236/// \par Availability
237/// This function is an extension, which is injected by the higher-level module \alib_format and
238/// is accessed through the header file #"F;ALib.Format.H".
239/// Furthermore, the configuration macro #"ALIB_DEBUG_BOXING" has to be set.
240/// @param staticVtables If \c true, only types with static vtables are listed.
241/// Otherwise only those with dynamic vtables.
242/// @param includeFunctions If \c true for each type, the list of specialized functions are
243/// listed.
244/// @return A string containing the dump.
246AString DumpVTables( bool staticVtables,
247 bool includeFunctions= false );
248
249/// Internally used by functions #".DumpVTables" and #".DumpAll".
250///
251/// \par Availability
252/// This function is an extension, which is injected by the higher-level module \alib_format and
253/// is accessed through the header file #"F;ALib.Format.H".
254/// Furthermore, the configuration macro #"ALIB_DEBUG_BOXING" has to be set.
255/// @param[out] target The target string to write to.
256/// @param[out] vtableNames Output parameter that receives the strings.
257/// @param staticVtables If \c true, only types with static vtables are listed.
258/// Otherwise only those with dynamic vtables.
259/// @param includeFunctions If \c true, For each \e vtable the list of specialized
260/// function is written.
262void dumpVTables( AString& target,
263 DbgStringTable<const detail::VTable*>& vtableNames,
264 bool staticVtables,
265 bool includeFunctions );
266
267#if ALIB_DEBUG_CONTAINERS
268 /// Invokes #"DbgDumpDistribution" on the internal hash table used to register
269 /// and fetch implementations of custom box-functions.
270 ///
271 /// \par Availability
272 /// This function is an extension, which is injected by the higher-level module \alib_format
273 /// and is accessed through the header file #"F;ALib.Format.H".
274 /// Furthermore, the configuration macros #"ALIB_DEBUG_BOXING" and #"ALIB_DEBUG_CONTAINERS"
275 /// are set.
276 /// @param[out] target The target string to write to.
277 /// @param detailedBucketList If \c true is given, for each bucket a line with its size
278 /// value and a "size bar" is written.
280 void DumpCustomFunctionHashMapMetrics( AString& target, bool detailedBucketList );
281#endif
282
283/// First, lists all mapped types with static, then those with dynamic \e vtables.
284/// Along with each type, its default function implementations are given.
285///
286/// \par Availability
287/// This function is an extension, which is injected by the higher-level module \alib_format and
288/// is accessed through the header file #"F;ALib.Format.H".
289/// Furthermore, the configuration macro #"ALIB_DEBUG_BOXING" has to be set.
290/// @return A string containing the dump.
293
294}; // namespace [alib::boxing::debug]
295
296#include "ALib.Lang.CIMethods.H"
297#endif // ALIB_DEBUG_BOXING
#define ALIB_DLL
#define A_CHAR(STR)
#define ALIB_TVALUE(T)
#define ALIB_LOCK_RECURSIVE_WITH(lock)
#define ALIB_EXPORT
const detail::VTable * DbgGetVTable() const
Definition box.hpp:379
static threads::RecursiveLock DEFAULT_LOCK
static SPFormatter DEFAULT
constexpr integer Length() const
Definition string.hpp:300
void typeInfo(AString &target, const detail::VTable *vtable, const String &indent, bool srcIsPointer, bool srcIsStringType, bool srcIsUnboxableStringType, bool isValueTypeCustomized, bool isPointerTypeCustomized, bool fitsToPlaceholder, bool copyConstructible, bool triviallyDestructible, bool isUnboxable)
AString & RemoveNamespaces(AString &string, integer startIndex)
AString TypeInfo(const Box &box, const String &headline=A_CHAR("Boxing Information For Boxable Type: "), const String &indent=A_CHAR(" "))
void dumpFunctions(const std::vector< std::pair< const std::type_info *, uinteger > > &input, AString &output, const String &headline, const String &indent, DbgStringTable< uinteger > &tmpStrings)
AString DumpFunctions(const std::vector< std::pair< const std::type_info *, uinteger > > &input, const String &headline, const String &indent)
void dumpVTables(AString &result, DbgStringTable< const detail::VTable * > &vtableNames, bool staticVtables, bool includeFunctions)
AString DumpVTables(bool staticVtables, bool includeFunctions)
void DumpCustomFunctionHashMapMetrics(AString &target, bool detailedBucketList)
monomem::TMonoAllocator< lang::HeapAllocator > MonoAllocator
format::Formatter Formatter
Type alias in namespace #"%alib".
constexpr CString NEW_LINE
A zero-terminated string containing the new-line character sequence.
Definition cstring.hpp:536
constexpr const String EMPTY_STRING
An empty string of the default character type.
Definition string.hpp:2227
strings::TString< character > String
Type alias in namespace #"%alib".
Definition string.hpp:2165
NLocalString< 512 > NString512
Type alias name for #"TLocalString;TLocalString<nchar,512>".
strings::TAString< character, lang::HeapAllocator > AString
Type alias in namespace #"%alib".
std::tuple< String, TAssociatedTypes... > ElementType
Shortcut to the std::tuple-type that instantiations of this template class store.
DbgStringTable(MonoAllocator &monoAllocator)
MonoAllocator & allocator
Allocator for making copies of inserted strings.
std::vector< ElementType > Base
Shortcut to the base type of this type.
String & Add(const String &src, TArgs &&... args)
The custom function hash.
Definition vtable.hpp:226