ALib C++ Framework
by
Library Version: 2605 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
scopedump.cpp
1namespace alib { namespace lox { namespace detail {
2
3//! @cond NO_DOX
4
5//##################################################################################################
6// template instantiations
7//##################################################################################################
8template int ScopeDump::writeStore ( ScopeStore<NString , true >* store, int indentSpaces );
9template int ScopeDump::writeStore ( ScopeStore<PrefixLogable* , true >* store, int indentSpaces );
10template int ScopeDump::writeStoreMap( ScopeStore<SSMap<int>*, false>* store );
11template int ScopeDump::writeStoreMap( ScopeStore<SSMap<Box>*, false>* store );
12
13//##################################################################################################
14// local helper functions (non members)
15//##################################################################################################
16namespace {
17
18template<typename T> void write( const T& val, NAString& target ) { target._(val); }
19
20template<typename T> void write( T* val, NAString& target ) {
21 // prefix logable?
22 if( std::is_same<T, Box*>::value ) {
23 String256 buffer;
24 buffer << '"';
25 integer actLen= buffer.Length();
26 buffer._( *val );
27 ESC::ReplaceToReadable( buffer, actLen );
28 buffer << Escape( lang::Switch::On, actLen );
29 buffer << '"';
30 target << buffer;
31 }
32 else
33 target._(*static_cast<Box*>(val));
34}
35} // anonymous namespace
36
37//##################################################################################################
38// protected methods
39//##################################################################################################
41 integer fileNameEnd= key.IndexOf('#');
42 integer methodEnd= fileNameEnd >= 0 ? key.IndexOf('#', fileNameEnd + 1) : -1;
43
44 targetBuffer._<NC>("Scope::");
45 if ( methodEnd >= 0 ) targetBuffer._<NC>( "Method [" );
46 else if ( fileNameEnd >= 0 ) targetBuffer._<NC>( "FileName [" );
47 else targetBuffer._<NC>( "Path [" );
48
49 integer targetStart= targetBuffer.Length();
50 targetBuffer._<NC>( key );
51
52 if ( methodEnd >= 0 ) {
53 targetBuffer.ReplaceSubstring<NC>( " @", targetStart + fileNameEnd +1, 2 ); // characters: "/#"
54 targetBuffer._<NC>( "()" );
55 }
56
57 if ( fileNameEnd >= 0 )
58 targetBuffer.ReplaceSubstring<NC>(".*", targetStart + fileNameEnd, 1);
59 else
60 targetBuffer._('/');
61
62 targetBuffer._(']');
63
64 return targetBuffer;
65}
66
67#if !ALIB_SINGLE_THREADED
69 auto it= threadDict.Find( threadID );
70 if ( it != threadDict.end() )
71 return targetBuffer._("[Thread=\"")._( it->second )._("\"]");
72
73 return targetBuffer._("[ThreadID=")._( threadID )._(']');
74}
75#endif
76
77template<typename T>
79 for ( auto& it : map ) {
80 targetBuffer._<NC>( prefix );
81
82 String64 keyString;
83
84 if ( it.first.template Equals<NC>( noKey ) )
85 keyString._<NC>( "<global>" );
86 else
87 keyString._<NC>( '"' )._( it.first )._( '"' );
88 if ( maximumKeyLength < keyString.Length() + 1 )
89 maximumKeyLength= keyString.Length() + 1;
90
91 targetBuffer._<NC>(NField(keyString, maximumKeyLength, lang::Alignment::Left))._<NC>( '=' );
92
93
94 write( it.second, targetBuffer);
95 targetBuffer.NewLine();
96 }
97 return maximumKeyLength;
98}
99
100//##################################################################################################
101// Interface
102//##################################################################################################
103template<typename T>
105 int cnt= 0;
106 bool firstEntry= true;
107 if ( store->globalStore && store->globalStore->Size() > 0) {
108 cnt+= int( store->globalStore->Size() );
109 firstEntry= false;
110 targetBuffer._<NC>( " Scope::Global:" ).NewLine();
111 maximumKeyLength= writeStoreMapHelper( *store->globalStore, " " );
112 }
113
114#if !ALIB_SINGLE_THREADED
115 for ( auto threadIt= store->threadStore.begin() ; threadIt != store->threadStore.end() ; ++threadIt ) {
116 if ( threadIt->first.first== false )
117 continue;
118 if( firstEntry ) firstEntry= false; else targetBuffer.NewLine();
119 targetBuffer._<NC>(" Scope::ThreadOuter "); storeThreadToScope( threadIt->first.second )._( ':' ).NewLine();
120 cnt+= int( threadIt->second->Size() );
121 maximumKeyLength= writeStoreMapHelper( *threadIt->second, " " );
122 }
123#endif
124
125
126 StringTreeIterator<typename ScopeStore<T, false>::TLanguageStore> iterator;
127 typename decltype(iterator)::NameSorter sorter;
128 iterator.SetSorting(&sorter);
129 iterator.SetPathGeneration( lang::Switch::On );
130 for( iterator.Initialize( store->languageStore.Root(), lang::Inclusion::Exclude)
131 ; iterator.IsValid()
132 ; iterator.Next() )
133 {
134 if( *iterator.Node() == nullptr )
135 continue;
136 cnt+= int( (*iterator.Node())->Size() );
137 if( firstEntry ) firstEntry= false; else targetBuffer.NewLine();
138 targetBuffer._<NC>( " " );
139 storeKeyToScope( iterator.Path() ).NewLine();
140 maximumKeyLength= writeStoreMapHelper( **iterator.Node(), " " );
141 }
142
143#if !ALIB_SINGLE_THREADED
144 for ( auto threadIt= store->threadStore.begin() ; threadIt != store->threadStore.end() ; ++threadIt ) {
145 if ( threadIt->first.first == true )
146 continue;
147 if( firstEntry ) firstEntry= false; else targetBuffer.NewLine();
148 targetBuffer._<NC>(" Scope::ThreadInner "); storeThreadToScope( threadIt->first.second )._( ':' ).NewLine();
149 cnt+= int( threadIt->second->Size() );
150 maximumKeyLength= writeStoreMapHelper( *threadIt->second, " " );
151 }
152#endif
153 return cnt;
154}
155
156template<typename T>
157int ScopeDump::writeStore( ScopeStore<T, true>* store, int indentSpaces ) {
158 int cnt= 0;
159
160 // global store
161 if ( store->globalStore != nullptr ) {
162 ++cnt;
163 targetBuffer.InsertChars( ' ', indentSpaces );
164 write( store->globalStore, targetBuffer );
165 targetBuffer._<NC>(NTab( 25, -1 ) )._<NC>( "Scope::Global " ).NewLine();
166 }
167
168 // outer thread store
169#if !ALIB_SINGLE_THREADED
170 for ( auto threadIt= store->threadStore.begin() ; threadIt != store->threadStore.end() ; ++threadIt )
171 if( threadIt->first.first == false )
172 for ( auto& it : threadIt->second ) {
173 ++cnt;
174 targetBuffer.InsertChars( ' ', indentSpaces );
175 write(it, targetBuffer);
176 targetBuffer._<NC>( NTab( 25, -1 ) )
177 ._<NC>( "Scope::ThreadOuter " );
178 storeThreadToScope( threadIt->first.second ).NewLine();
179 }
180#endif
181
182 // language store
183 {
184 StringTreeIterator<typename ScopeStore<T, true>::TLanguageStore> iterator;
185 typename decltype(iterator)::NameSorter sorter;
186 iterator.SetSorting(&sorter);
187 iterator.SetPathGeneration( lang::Switch::On );
188 for( iterator.Initialize( store->languageStore.Root(), lang::Inclusion::Exclude )
189 ; iterator.IsValid()
190 ; iterator.Next() )
191 {
192 if( *iterator.Node() == nullptr )
193 continue;
194 ++cnt;
195 targetBuffer.InsertChars( ' ', indentSpaces );
196 write( *iterator.Node(), targetBuffer );
197 targetBuffer._<NC>(NTab( 25, -1 ) );
198 storeKeyToScope( iterator.Path() ).NewLine();
199 } }
200
201 // inner thread store
202#if !ALIB_SINGLE_THREADED
203 for ( auto threadIt= store->threadStore.begin() ; threadIt != store->threadStore.end() ; ++threadIt )
204 if( threadIt->first.first == true )
205 for ( auto& it : threadIt->second ) {
206 ++cnt;
207 targetBuffer.InsertChars( ' ', indentSpaces );
208 write(it, targetBuffer);
209 targetBuffer._<NC>( NTab( 25, -1 ) )
210 ._<NC>( "Scope::ThreadInner " );
211 storeThreadToScope( threadIt->first.second ).NewLine();
212 }
213#endif
214 return cnt;
215}
216
217//! @endcond
218}}} // namespace [alib::lox::detail]
static void ReplaceToReadable(AString &target, integer startIdx)
Definition aloxinit.cpp:9
integer writeStoreMapHelper(SSMap< T > &map, const NString &prefix)
NAString & targetBuffer
The target to write to.
Definition scopedump.hpp:23
NAString & storeKeyToScope(String key)
ScopeInfo::ThreadDictionary & threadDict
User-defined threads names.
Definition scopedump.hpp:33
NAString & storeThreadToScope(ThreadID threadID)
const NString noKey
String to identify global keys.
Definition scopedump.hpp:26
integer maximumKeyLength
The maximum length of a key. Adjusts (increases) over life-cycle.
Definition scopedump.hpp:29
int writeStore(ScopeStore< T, true > *store, int indentSpaces)
int writeStoreMap(ScopeStore< T, false > *store)
TAString & _(const TAppendable &src)
integer IndexOf(TChar needle, integer startIdx=0) const
Definition string.hpp:799
@ 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.hpp:23
Definition alox.cpp:14
strings::TString< nchar > NString
Type alias in namespace #"%alib".
Definition string.hpp:2174
strings::TField< nchar > NField
Type alias in namespace #"%alib".
strings::TTab< nchar > NTab
Type alias in namespace #"%alib".
Definition format.hpp:514
strings::TEscape< character > Escape
Type alias in namespace #"%alib".
Definition format.hpp:531
LocalString< 64 > String64
Type alias name for #"TLocalString;TLocalString<character,64>".
strings::TAString< nchar, lang::HeapAllocator > NAString
Type alias in namespace #"%alib".
lang::integer integer
Type alias in namespace #"%alib".
Definition integers.hpp:149
boxing::Box Box
Type alias in namespace #"%alib".
Definition box.hpp:1128
strings::TString< character > String
Type alias in namespace #"%alib".
Definition string.hpp:2165
LocalString< 256 > String256
Type alias name for #"TLocalString;TLocalString<character,256>".