ALib C++ Library
Library Version: 2510 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
alib::lox::detail::ScopeInfo Class Reference

Description:

Encapsulates information of the caller that can be collected. This is platform-specific, in this case, C++. What we receive from the C++ preprocessor is the source file name of the calling code, the line number within the source file name and the name of the method the call is placed in. Furthermore, we collect the std::type_info* in case the call was not placed in a static or namespace function.

The method has a list of interface functions that gets such source information and some derived variants of it. In addition, thread and timer information is stored and managed.

As far as possible, 'lazy' techniques come to practice with this class. This means, only the things that are queried in-between to invocations of method Set are calculated.

Friends

class Lox

Definition at line 27 of file scopeinfo.inl.

Collaboration diagram for alib::lox::detail::ScopeInfo:
[legend]

Inner Type Index:

struct  FrameRecord
 
struct  ParsedFileName
 Information of a single source file. Stored in field parsedFileNameCache. More...
 
struct  SourcePathTrimRule
 
struct  ValueDescriptorPFN
 Serves as template parameter TValueDescriptor of field parsedFileNameCache. More...
 

Public Type Index:

using ThreadDictionary = HashMap<MonoAllocator, threads::ThreadID, String32>
 A map we use to translate thread IDs to thread names.
 

Public Field Index:

NString loxName
 The name of the Lox we are attached to.
 

Public Method Index:

ALIB_DLL ScopeInfo (const NString &name, MonoAllocator &allocator)
 
const NString GetFileName ()
 
const NString GetFileNameWithoutExtension ()
 
const NString GetFullPath ()
 
int GetLineNumber ()
 
const NString GetLoxName ()
 
const NCString GetMethod ()
 
const NCStringGetOrigFile ()
 
threads::ThreadID GetThreadID ()
 
const alib::StringGetThreadNameAndID (threads::ThreadID *id)
 
std::thread::id GetThreadNativeID ()
 
Ticks GetTimeStamp ()
 
void GetTrimmedPath (AString &target)
 
const std::type_info * GetTypeInfo ()
 
void PopNestedScope ()
 Releases latest scope information.
 
ALIB_DLL void Set (const lang::CallerInfo &ci)
 
void SetFileNameCacheCapacity (integer numberOfLists, integer entriesPerList)
 
ALIB_DLL void SetSourcePathTrimRule (const NCString &path, lang::Inclusion includeString, int trimOffset, lang::Case sensitivity, const NString &trimReplacement, lang::Reach reach, Priority priority)
 

Protected Static Field Index:

static ALIB_DLL std::vector< SourcePathTrimRuleGlobalSPTRs
 List of trim definitions for portions of source paths to be ignored.
 
static ALIB_DLL bool GlobalSPTRsReadFromConfig = false
 Flag to determine if global rules have been read from config already.
 

Protected Field Index:

bool AutoDetectTrimableSourcePath = true
 
StdVectorMono< FrameRecordcallStack
 A stack of scopes (allows recursive calls/nested logging).
 
int callStackSize = -1
 The current depth of recursive invocations.
 
std::vector< SourcePathTrimRuleLocalSPTRs
 List of trim definitions for portions of source paths to be ignored.
 
LRUCacheTable< MonoAllocator, ValueDescriptorPFN, std::hash< NString > > parsedFileNameCache
 Least recently used cache of parsed file name.
 
Threadthread = nullptr
 The thread passed with Set.
 
ThreadDictionary threadDictionary
 
String threadName
 The name of the thread that executed the log.
 
std::thread::id threadNativeIDx
 The C++ native ID.
 

Protected Method Index:

integer getPathLength ()
 
ALIB_DLL void trimPath ()
 

Type Definition Details:

◆ ThreadDictionary

A map we use to translate thread IDs to thread names.

Definition at line 32 of file scopeinfo.inl.

Field Details:

◆ AutoDetectTrimableSourcePath

bool alib::lox::detail::ScopeInfo::AutoDetectTrimableSourcePath = true
protected

If true, next time a source path cannot be trimmed successfully with custom trim information provided with Lox::SetSourcePathTrimRule some trim information is automatically created by comparing such source file's path with the path of the executable of the current process.

Definition at line 74 of file scopeinfo.inl.

◆ callStack

StdVectorMono<FrameRecord> alib::lox::detail::ScopeInfo::callStack
protected

A stack of scopes (allows recursive calls/nested logging).

Definition at line 155 of file scopeinfo.inl.

◆ callStackSize

int alib::lox::detail::ScopeInfo::callStackSize = -1
protected

The current depth of recursive invocations.

Definition at line 158 of file scopeinfo.inl.

◆ GlobalSPTRs

std::vector< ScopeInfo::SourcePathTrimRule > alib::lox::detail::ScopeInfo::GlobalSPTRs
staticprotected

List of trim definitions for portions of source paths to be ignored.

Definition at line 60 of file scopeinfo.inl.

◆ GlobalSPTRsReadFromConfig

bool alib::lox::detail::ScopeInfo::GlobalSPTRsReadFromConfig = false
staticprotected

Flag to determine if global rules have been read from config already.

Definition at line 67 of file scopeinfo.inl.

◆ LocalSPTRs

std::vector<SourcePathTrimRule> alib::lox::detail::ScopeInfo::LocalSPTRs
protected

List of trim definitions for portions of source paths to be ignored.

Definition at line 63 of file scopeinfo.inl.

◆ loxName

NString alib::lox::detail::ScopeInfo::loxName

The name of the Lox we are attached to.

Definition at line 165 of file scopeinfo.inl.

◆ parsedFileNameCache

LRUCacheTable< MonoAllocator, ValueDescriptorPFN, std::hash<NString> > alib::lox::detail::ScopeInfo::parsedFileNameCache
protected

Least recently used cache of parsed file name.

Definition at line 131 of file scopeinfo.inl.

◆ thread

Thread* alib::lox::detail::ScopeInfo::thread = nullptr
protected

The thread passed with Set.

Definition at line 81 of file scopeinfo.inl.

◆ threadDictionary

ThreadDictionary alib::lox::detail::ScopeInfo::threadDictionary
protected

Dictionary to translate thread IDs into something maybe nicer/shorter. The dictionary may be filled by the user of the library using Lox.MapThreadName.

Definition at line 88 of file scopeinfo.inl.

◆ threadName

String alib::lox::detail::ScopeInfo::threadName
protected

The name of the thread that executed the log.

Definition at line 84 of file scopeinfo.inl.

◆ threadNativeIDx

std::thread::id alib::lox::detail::ScopeInfo::threadNativeIDx
protected

The C++ native ID.

Definition at line 78 of file scopeinfo.inl.

Constructor(s) / Destructor Details:

◆ ScopeInfo()

alib::lox::detail::ScopeInfo::ScopeInfo ( const NString & name,
MonoAllocator & allocator )

Constructs a scope info.

Parameters
nameThe name of the Lox that this object belongs to. Will be converted to upper case.
allocatorThe monotonic allocator of "our" Lox, used for long-term allocations

Definition at line 63 of file scopeinfo.cpp.

Here is the call graph for this function:

Method Details:

◆ GetFileName()

const NString alib::lox::detail::ScopeInfo::GetFileName ( )
inline

Receives the source file name excluding the path (usually provided by the preprocessor).

Returns
The source file name excluding the path

Definition at line 276 of file scopeinfo.inl.

Here is the call graph for this function:

◆ GetFileNameWithoutExtension()

const NString alib::lox::detail::ScopeInfo::GetFileNameWithoutExtension ( )
inline

Receives the source file name excluding the path and without an extension (usually provided by the preprocessor).

Returns
The source file name excluding the path and extension.

Definition at line 294 of file scopeinfo.inl.

Here is the call graph for this function:

◆ GetFullPath()

const NString alib::lox::detail::ScopeInfo::GetFullPath ( )
inline

Receives the path of the source file (not trimmed, see GetTrimmedPath).

Returns
The path of the source file.

Definition at line 246 of file scopeinfo.inl.

Here is the call graph for this function:

◆ GetLineNumber()

int alib::lox::detail::ScopeInfo::GetLineNumber ( )
inline

Receives the source file line number (usually provided by the preprocessor).

Returns
The source file line number.

Definition at line 317 of file scopeinfo.inl.

◆ GetLoxName()

const NString alib::lox::detail::ScopeInfo::GetLoxName ( )
inline

Receives the name of the Lox we are belonging to (this is a 1:1 relationship).

Returns
The name of the Lox.

Definition at line 231 of file scopeinfo.inl.

◆ GetMethod()

const NCString alib::lox::detail::ScopeInfo::GetMethod ( )
inline

Receives the method name (usually provided by the preprocessor).

Returns
The method name.

Definition at line 310 of file scopeinfo.inl.

◆ GetOrigFile()

const NCString & alib::lox::detail::ScopeInfo::GetOrigFile ( )
inline

Receives the original filename and path of the source file (usually provided by the preprocessor).

Returns
The full path and filename of the source file.

Definition at line 239 of file scopeinfo.inl.

◆ getPathLength()

integer alib::lox::detail::ScopeInfo::getPathLength ( )
inlineprotected

Gets position of path/filename separator. This is evaluated only once after an invocation of Set.

Returns
The index of the path separator in SourceFile::origFile.

Definition at line 393 of file scopeinfo.inl.

◆ GetThreadID()

threads::ThreadID alib::lox::detail::ScopeInfo::GetThreadID ( )
inline

Receives the thread ID of the caller.

Returns
The thread ID.

Definition at line 340 of file scopeinfo.inl.

Here is the call graph for this function:

◆ GetThreadNameAndID()

const alib::String & alib::lox::detail::ScopeInfo::GetThreadNameAndID ( threads::ThreadID * id)
inline

Receives information about the thread that the current call was invoked with.

Parameters
idOutput parameter receiving the ALib thread ID. If nullptr, it will be ignored.
Returns
The name of the current thread. The id is stored within the provided pointer.

Definition at line 356 of file scopeinfo.inl.

Here is the call graph for this function:

◆ GetThreadNativeID()

std::thread::id alib::lox::detail::ScopeInfo::GetThreadNativeID ( )
inline

Receives the thread ID of the caller.

Returns
The thread ID.

Definition at line 349 of file scopeinfo.inl.

◆ GetTimeStamp()

Ticks alib::lox::detail::ScopeInfo::GetTimeStamp ( )
inline

The timestamp of the last invocation of Set.

Returns
The latest timestamp.

Definition at line 324 of file scopeinfo.inl.

◆ GetTrimmedPath()

void alib::lox::detail::ScopeInfo::GetTrimmedPath ( AString & target)
inline

Writes the path of the source file, trimmed according to trim-information provided with SetSourcePathTrimRule or detected according to AutoDetectTrimableSourcePath.

Parameters
targetThe target string to append the trimmed path to.

Definition at line 264 of file scopeinfo.inl.

Here is the call graph for this function:

◆ GetTypeInfo()

const std::type_info * alib::lox::detail::ScopeInfo::GetTypeInfo ( )
inline

Receives the type information of the caller. If called from global function or static method, this will be nullptr.

Returns
The type information, if available.

Definition at line 332 of file scopeinfo.inl.

◆ PopNestedScope()

void alib::lox::detail::ScopeInfo::PopNestedScope ( )
inline

Releases latest scope information.

Definition at line 198 of file scopeinfo.inl.

◆ Set()

void alib::lox::detail::ScopeInfo::Set ( const lang::CallerInfo & ci)

Stores C++ specific caller parameters and some other values like the time stamp. Also, flags thread information as not received, yet. Counts the recursion counter up.

Parameters
ciThe caller information.

Definition at line 144 of file scopeinfo.cpp.

Here is the call graph for this function:

◆ SetFileNameCacheCapacity()

void alib::lox::detail::ScopeInfo::SetFileNameCacheCapacity ( integer numberOfLists,
integer entriesPerList )
inline

Changes the capacity of the LRUCacheTable for parsed file names by calling LRUCacheTable::Reserve.

Parameters
numberOfListsThe number of LRU-lists to use.
entriesPerListThe maximum length of each cache list.

Definition at line 187 of file scopeinfo.inl.

◆ SetSourcePathTrimRule()

void alib::lox::detail::ScopeInfo::SetSourcePathTrimRule ( const NCString & path,
lang::Inclusion includeString,
int trimOffset,
lang::Case sensitivity,
const NString & trimReplacement,
lang::Reach reach,
Priority priority )

Does the job for Lox::SetSourcePathTrimRule and Lox::ClearSourcePathTrimRules.

Parameters
pathThe path to search for. If not starting with '*', a prefix is searched.
includeStringDetermines if path should be included in the trimmed path or not.
trimOffsetAdjusts the portion of path that is trimmed. 999999 to clear!
sensitivityDetermines if the comparison of path with a source file's path is performed case-sensitive or not.
trimReplacementReplacement string for trimmed portion of the path.
reachDenotes whether the rule is applied locally (to this Lox only) or applies to all instances of class Lox. Defaults to Reach::Global.
priorityThe priority of the setting.

Definition at line 168 of file scopeinfo.cpp.

Here is the call graph for this function:

◆ trimPath()

void alib::lox::detail::ScopeInfo::trimPath ( )
protected

Tries to trim the source file's path. Sets variable SourceFile::trimmedPath to either the successfully trimmed path or to the non-trimmed one. This way, it is executed only once, at it is 'lazily' invoked by GetTrimmedPath()

Definition at line 232 of file scopeinfo.cpp.

Here is the call graph for this function:

The documentation for this class was generated from the following files: