10# if !defined(HPP_ALIB_ALOX)
13# if !defined(HPP_ALIB_CAMP_MESSAGE_REPORT)
16# define HPP_ALIB_LOX_PROPPERINCLUDE
17# if !defined (HPP_ALOX_DETAIL_SCOPE)
20# if !defined (HPP_ALOX_DETAIL_SCOPEINFO)
23# undef HPP_ALIB_LOX_PROPPERINCLUDE
28namespace alib {
namespace lox {
namespace detail {
41template<
typename T,
bool TStackedThreadValues>
45 , languageStore( monoAllocator ,
'/' )
47 , scopeInfo ( pScopeInfo )
52template<
typename T,
bool TStackedThreadValues>
55 languageStore.DeleteRootValue();
63template<
typename T,
bool TStackedThreadValues>
68 languageStore.Reset();
72template<
typename T,
bool TStackedThreadValues>
76 walkLocalObject= localObject;
78 walkNextThreadIdx= -2;
79 lazyLanguageNode=
true;
90 case Scope::ThreadInner:
126 case Scope::Filename:
145 case Scope::ThreadOuter:
193 if( self.actScope == Scope::Global )
195 oldValue= self.globalStore;
196 if ( cmd == CMD_INSERT )
197 self.globalStore= value;
198 else if ( cmd == CMD_REMOVE )
206 if( self.actScope == Scope::ThreadOuter
207 || self.actScope == Scope::ThreadInner )
210 bool isInner= self.actScope == Scope::ThreadInner;
213 if ( cmd != CMD_INSERT && self.threadStore.Size() == 0 )
218 self.actThreadID= self.scopeInfo.GetThreadID();
225 auto hash=
typename decltype(self.threadStore)::HashType ()( key );
226 if ( cmd == CMD_GET )
228 auto it= self.threadStore.Find( key, hash );
229 if ( it != self.threadStore.end() )
237 self.threadStore.InsertUnique( std::make_pair( key, value), hash );
249 if ( self.lazyLanguageNode
250 || ( self.actStringTreeNode.IsInvalid() && cmd == CMD_INSERT ) )
251 self.initCursor(
true );
253 oldValue= self.actStringTreeNode.Value();
254 if ( cmd == CMD_INSERT ) self.actStringTreeNode.Value()= value;
265 case Scope::ThreadInner:
301 case Scope::Filename:
320 case Scope::ThreadOuter:
367 if( self.actScope == Scope::Global )
369 oldValue= self.globalStore;
370 if ( cmd == CMD_INSERT ) self.globalStore= value;
378 if( self.actScope == Scope::ThreadOuter
379 || self.actScope == Scope::ThreadInner )
382 bool isInner= self.actScope == Scope::ThreadInner;
385 if ( cmd != CMD_INSERT && self.threadStore.Size() == 0 )
390 self.actThreadID= self.scopeInfo.GetThreadID();
394 std::vector<T,StdContMA<T>>* values;
396 values= &self.threadStore.EmplaceIfNotExistent(
398 *self.threadStore.GetAllocator() ).first.Mapped();
402 if ( cmd == CMD_GET )
406 if ( cmd == CMD_INSERT )
408 values->emplace_back( value );
413 if ( cmd == CMD_REMOVE && values->size() > 0)
418 oldValue= values->back();
424 for (
auto rem= values->begin() ; rem != values->end(); ++rem )
430 values->erase( rem );
445 if ( self.lazyLanguageNode
446 || ( self.actStringTreeNode.IsInvalid() && cmd == CMD_INSERT ) )
447 self.initCursor(
true );
449 oldValue= self.actStringTreeNode.Value();
450 if ( cmd == CMD_INSERT ) self.actStringTreeNode.Value()= value;
462template<
typename T,
bool TStackedThreadValues>
465 lazyLanguageNode=
false;
466 actStringTreeNode= languageStore.Root();
470 scopeInfo.GetTrimmedPath( path );
471 #if defined( _WIN32 )
482 auto remainingPath= actStringTreeNode.GoToTraversedPath( path );
483 if ( remainingPath.IsNotEmpty() )
487 if ( !actStringTreeNode.GoToChild( path.
Reset<
false>( scopeInfo.GetFileNameWithoutExtension() ).
_(
'#' ) ) )
491 actStringTreeNode.GoToChild( path.
Reset<
false>(
'#' ).
_<
false>( scopeInfo.GetMethod() ) );
497 actStringTreeNode.GoToCreatedPathIfNotExistent( path );
498 if ( actScope == Scope::Path )
501 int pathLevel= actPathLevel;
502 while ( --pathLevel >= 0 && !actStringTreeNode.IsRoot() )
503 actStringTreeNode.GoToParent();
508 path.
Reset( scopeInfo.GetFileNameWithoutExtension() ).
_(
'#' );
511 if ( actScope == Scope::Method )
512 path.
_(
"/#" ).
_( scopeInfo.GetMethod() );
514 actStringTreeNode.GoToCreatedPathIfNotExistent( path );
517template<
typename T,
bool TStackedThreadValues>
521 actPathLevel= pathLevel;
523 actThreadID= threadID;
528 lazyLanguageNode=
true;
threads::ThreadID GetThreadID()
static ALIB_API T NullValue()
static ALIB_API bool AreEqual(T first, T second)
void initCursor(bool create)
ALIB_API void InitWalk(Scope startScope, const T localObject)
ALIB_API void InitAccess(Scope scope, int pathLevel, threads::ThreadID threadID)
LanguageStoreT languageStore
ThreadMapValueT * walkThreadValues
HashMap< ThreadMapKey, ThreadMapValueT, BoolThreadIDHash > threadStore
LanguageStoreT::Cursor actStringTreeNode
std::pair< bool, threads::ThreadID > ThreadMapKey
ALIB_API ScopeStore(ScopeInfo &scopeInfo, monomem::MonoAllocator *monoAllocator)
void ConstructRootValue(TArgs &&... args)
TAString & _(const TString< TChar > &src, integer regionStart, integer regionLength=MAX_LEN)
ALIB_API integer SearchAndReplace(TChar needle, TChar replacement, integer startIdx=0)
#define ALIB_IF_THREADS(...)
#define ALIB_ASSERT(cond)
static constexpr ThreadID UNDEFINED
T doWalk(ScopeStore< T, TStackedThreadValues > &self)
T doAccess(ScopeStore< T, TStackedThreadValues > &self, int cmd, T value)