ALib C++ Library
Library Version: 2511 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
scopedump.cpp
1//##################################################################################################
2// ALib C++ Library
3//
4// Copyright 2013-2025 A-Worx GmbH, Germany
5// Published under 'Boost Software License' (a free software license, see LICENSE.txt)
6//##################################################################################################
7#include "alib_precompile.hpp"
8#if !defined(ALIB_C20_MODULES) || ((ALIB_C20_MODULES != 0) && (ALIB_C20_MODULES != 1))
9# error "Symbol ALIB_C20_MODULES has to be given to the compiler as either 0 or 1"
10#endif
11#if ALIB_C20_MODULES
12 module;
13#endif
14//========================================= Global Fragment ========================================
16
17//============================================== Module ============================================
18#if ALIB_C20_MODULES
19 module ALib.ALox.Impl;
20 import ALib.Lang;
21 import ALib.Strings;
22 import ALib.Boxing;
23 import ALib.EnumRecords;
24 import ALib.EnumRecords.Bootstrap;
25 import ALib.Variables;
26 import ALib.Camp;
27 import ALib.Camp.Base;
28#else
29# include "ALib.Lang.H"
30# include "ALib.Strings.H"
31# include "ALib.Boxing.H"
34# include "ALib.Variables.H"
35# include "ALib.Camp.H"
36# include "ALib.Camp.Base.H"
37# include "ALib.Camp.H"
38# include "ALib.Camp.Base.H"
39# include "ALib.ALox.H"
40# include "ALib.ALox.Impl.H"
41#endif
42//========================================== Implementation ========================================
43namespace alib { namespace lox { namespace detail {
44
45//! @cond NO_DOX
46
47//##################################################################################################
48// template instantiations
49//##################################################################################################
50template int ScopeDump::writeStore ( ScopeStore<NString , true >* store, int indentSpaces );
51template int ScopeDump::writeStore ( ScopeStore<PrefixLogable* , true >* store, int indentSpaces );
52template int ScopeDump::writeStoreMap( ScopeStore<SSMap<int>*, false>* store );
53template int ScopeDump::writeStoreMap( ScopeStore<SSMap<Box>*, false>* store );
54
55//##################################################################################################
56// local helper functions (non members)
57//##################################################################################################
58namespace {
59
60template<typename T> void write( const T& val, NAString& target ) { target._(val); }
61
62template<typename T> void write( T* val, NAString& target ) {
63 // prefix logable?
64 if( std::is_same<T, Box*>::value ) {
65 String256 buffer;
66 buffer << '"';
67 integer actLen= buffer.Length();
68 buffer._( *val );
69 ESC::ReplaceToReadable( buffer, actLen );
70 buffer << Escape( lang::Switch::On, actLen );
71 buffer << '"';
72 target << buffer;
73 }
74 else
75 target._(*static_cast<Box*>(val));
76}
77} // anonymous namespace
78
79//##################################################################################################
80// protected methods
81//##################################################################################################
83 integer fileNameEnd= key.IndexOf('#');
84 integer methodEnd= fileNameEnd >= 0 ? key.IndexOf('#', fileNameEnd + 1) : -1;
85
86 targetBuffer._<NC>("Scope::");
87 if ( methodEnd >= 0 ) targetBuffer._<NC>( "Method [" );
88 else if ( fileNameEnd >= 0 ) targetBuffer._<NC>( "FileName [" );
89 else targetBuffer._<NC>( "Path [" );
90
91 integer targetStart= targetBuffer.Length();
92 targetBuffer._<NC>( key );
93
94 if ( methodEnd >= 0 ) {
95 targetBuffer.ReplaceSubstring<NC>( " @", targetStart + fileNameEnd +1, 2 ); // characters: "/#"
96 targetBuffer._<NC>( "()" );
97 }
98
99 if ( fileNameEnd >= 0 )
100 targetBuffer.ReplaceSubstring<NC>(".*", targetStart + fileNameEnd, 1);
101 else
102 targetBuffer._('/');
103
104 targetBuffer._(']');
105
106 return targetBuffer;
107}
108
109#if !ALIB_SINGLE_THREADED
111 auto it= threadDict.Find( threadID );
112 if ( it != threadDict.end() )
113 return targetBuffer._("[Thread=\"")._( it->second )._("\"]");
114
115 return targetBuffer._("[ThreadID=")._( threadID )._(']');
116}
117#endif
118
119template<typename T>
121 for ( auto& it : map ) {
122 targetBuffer._<NC>( prefix );
123
124 String64 keyString;
125
126 if ( it.first.template Equals<NC>( noKey ) )
127 keyString._<NC>( "<global>" );
128 else
129 keyString._<NC>( '"' )._( it.first )._( '"' );
130 if ( maximumKeyLength < keyString.Length() + 1 )
131 maximumKeyLength= keyString.Length() + 1;
132
133 targetBuffer._<NC>(NField(keyString, maximumKeyLength, lang::Alignment::Left))._<NC>( '=' );
134
135
136 write( it.second, targetBuffer);
137 targetBuffer.NewLine();
138 }
139 return maximumKeyLength;
140}
141
142//##################################################################################################
143// Interface
144//##################################################################################################
145template<typename T>
147 int cnt= 0;
148 bool firstEntry= true;
149 if ( store->globalStore && store->globalStore->Size() > 0) {
150 cnt+= int( store->globalStore->Size() );
151 firstEntry= false;
152 targetBuffer._<NC>( " Scope::Global:" ).NewLine();
153 maximumKeyLength= writeStoreMapHelper( *store->globalStore, " " );
154 }
155
156#if !ALIB_SINGLE_THREADED
157 for ( auto thread= store->threadStore.begin() ; thread != store->threadStore.end() ; ++thread ) {
158 if ( thread->first.first== false )
159 continue;
160 if( firstEntry ) firstEntry= false; else targetBuffer.NewLine();
161 targetBuffer._<NC>(" Scope::ThreadOuter "); storeThreadToScope( thread->first.second )._( ':' ).NewLine();
162 cnt+= int( thread->second->Size() );
163 maximumKeyLength= writeStoreMapHelper( *thread->second, " " );
164 }
165#endif
166
167
168 StringTreeIterator<typename ScopeStore<T, false>::TLanguageStore> iterator;
169 typename decltype(iterator)::NameSorter sorter;
170 iterator.SetSorting(&sorter);
171 iterator.SetPathGeneration( lang::Switch::On );
172 for( iterator.Initialize( store->languageStore.Root(), lang::Inclusion::Exclude)
173 ; iterator.IsValid()
174 ; iterator.Next() )
175 {
176 if( *iterator.Node() == nullptr )
177 continue;
178 cnt+= int( (*iterator.Node())->Size() );
179 if( firstEntry ) firstEntry= false; else targetBuffer.NewLine();
180 targetBuffer._<NC>( " " );
181 storeKeyToScope( iterator.Path() ).NewLine();
182 maximumKeyLength= writeStoreMapHelper( **iterator.Node(), " " );
183 }
184
185#if !ALIB_SINGLE_THREADED
186 for ( auto thread= store->threadStore.begin() ; thread != store->threadStore.end() ; ++thread ) {
187 if ( thread->first.first == true )
188 continue;
189 if( firstEntry ) firstEntry= false; else targetBuffer.NewLine();
190 targetBuffer._<NC>(" Scope::ThreadInner "); storeThreadToScope( thread->first.second )._( ':' ).NewLine();
191 cnt+= int( thread->second->Size() );
192 maximumKeyLength= writeStoreMapHelper( *thread->second, " " );
193 }
194#endif
195 return cnt;
196}
197
198template<typename T>
199int ScopeDump::writeStore( ScopeStore<T, true>* store, int indentSpaces ) {
200 int cnt= 0;
201
202 // global store
203 if ( store->globalStore != nullptr ) {
204 ++cnt;
205 targetBuffer.InsertChars( ' ', indentSpaces );
206 write( store->globalStore, targetBuffer );
207 targetBuffer._<NC>(NTab( 25, -1 ) )._<NC>( "Scope::Global " ).NewLine();
208 }
209
210 // outer thread store
211#if !ALIB_SINGLE_THREADED
212 for ( auto thread= store->threadStore.begin() ; thread != store->threadStore.end() ; ++thread )
213 if( thread->first.first == false )
214 for ( auto& it : thread->second ) {
215 ++cnt;
216 targetBuffer.InsertChars( ' ', indentSpaces );
217 write(it, targetBuffer);
218 targetBuffer._<NC>( NTab( 25, -1 ) )
219 ._<NC>( "Scope::ThreadOuter " );
220 storeThreadToScope( thread->first.second ).NewLine();
221 }
222#endif
223
224 // language store
225 {
226 StringTreeIterator<typename ScopeStore<T, true>::TLanguageStore> iterator;
227 typename decltype(iterator)::NameSorter sorter;
228 iterator.SetSorting(&sorter);
229 iterator.SetPathGeneration( lang::Switch::On );
230 for( iterator.Initialize( store->languageStore.Root(), lang::Inclusion::Exclude )
231 ; iterator.IsValid()
232 ; iterator.Next() )
233 {
234 if( *iterator.Node() == nullptr )
235 continue;
236 ++cnt;
237 targetBuffer.InsertChars( ' ', indentSpaces );
238 write( *iterator.Node(), targetBuffer );
239 targetBuffer._<NC>(NTab( 25, -1 ) );
240 storeKeyToScope( iterator.Path() ).NewLine();
241 } }
242
243 // inner thread store
244#if !ALIB_SINGLE_THREADED
245 for ( auto thread= store->threadStore.begin() ; thread != store->threadStore.end() ; ++thread )
246 if( thread->first.first == true )
247 for ( auto& it : thread->second ) {
248 ++cnt;
249 targetBuffer.InsertChars( ' ', indentSpaces );
250 write(it, targetBuffer);
251 targetBuffer._<NC>( NTab( 25, -1 ) )
252 ._<NC>( "Scope::ThreadInner " );
253 storeThreadToScope( thread->first.second ).NewLine();
254 }
255#endif
256 return cnt;
257}
258
259//! @endcond
260}}} // namespace [alib::lox::detail]
static ALIB_DLL void ReplaceToReadable(AString &target, integer startIdx)
Definition aloxinit.cpp:48
ALIB_DLL NAString & storeThreadToScope(ThreadID threadID)
ALIB_DLL NAString & storeKeyToScope(String key)
NAString & targetBuffer
The target to write to.
Definition scopedump.inl:24
ALIB_DLL int writeStore(ScopeStore< T, true > *store, int indentSpaces)
ScopeInfo::ThreadDictionary & threadDict
User-defined threads names.
Definition scopedump.inl:34
ALIB_DLL integer writeStoreMapHelper(SSMap< T > &map, const NString &prefix)
ALIB_DLL int writeStoreMap(ScopeStore< T, false > *store)
const NString noKey
String to identify global keys.
Definition scopedump.inl:27
integer maximumKeyLength
The maximum length of a key. Adjusts (increases) over life-cycle.
Definition scopedump.inl:30
TAString & _(const TAppendable &src)
integer IndexOf(TChar needle, integer startIdx=0) const
Definition string.inl:815
@ Left
Chooses left alignment.
@ On
Switch it on, switched on, etc.
@ Exclude
Chooses exclusion.
HashMap< PoolAllocator, NString, T, std::hash< NString >, std::equal_to< NString >, lang::Caching::Enabled, Recycling::None > SSMap
Shortcut to the ScopeStore's hashmap.
integer ThreadID
The ALib thread identifier type.
Definition thread.inl:23
strings::TEscape< character > Escape
Type alias in namespace alib.
Definition format.inl:532
LocalString< 256 > String256
Type alias name for TLocalString<character,256>.
LocalString< 64 > String64
Type alias name for TLocalString<character,64>.
lang::integer integer
Type alias in namespace alib.
Definition integers.inl:149
strings::TString< nchar > NString
Type alias in namespace alib.
Definition string.inl:2198
strings::TAString< nchar, lang::HeapAllocator > NAString
Type alias in namespace alib.
strings::TTab< nchar > NTab
Type alias in namespace alib.
Definition format.inl:515
boxing::Box Box
Type alias in namespace alib.
Definition box.inl:1149
strings::TField< nchar > NField
Type alias in namespace alib.
strings::TString< character > String
Type alias in namespace alib.
Definition string.inl:2189