ALib C++ Library
Library Version: 2412 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
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 52 of file scopeinfo.inl.

Collaboration diagram for 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_API 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_API void Set (const lang::CallerInfo &ci)
 
void SetFileNameCacheCapacity (integer numberOfLists, integer entriesPerList)
 
ALIB_API 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_API std::vector< SourcePathTrimRuleGlobalSPTRs
 List of trim definitions for portions of source paths to be ignored.
 
static ALIB_API 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_API void trimPath ()
 

Type Definition Details:

◆ ThreadDictionary

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

Definition at line 57 of file scopeinfo.inl.

Field Details:

◆ AutoDetectTrimableSourcePath

bool 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 99 of file scopeinfo.inl.

◆ callStack

StdVectorMono<FrameRecord> callStack
protected

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

Definition at line 180 of file scopeinfo.inl.

◆ callStackSize

int callStackSize = -1
protected

The current depth of recursive invocations.

Definition at line 183 of file scopeinfo.inl.

◆ GlobalSPTRs

std::vector< ScopeInfo::SourcePathTrimRule > GlobalSPTRs
staticprotected

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

Definition at line 85 of file scopeinfo.inl.

◆ GlobalSPTRsReadFromConfig

bool GlobalSPTRsReadFromConfig = false
staticprotected

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

Definition at line 92 of file scopeinfo.inl.

◆ LocalSPTRs

std::vector<SourcePathTrimRule> LocalSPTRs
protected

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

Definition at line 88 of file scopeinfo.inl.

◆ loxName

NString loxName

The name of the Lox we are attached to.

Definition at line 190 of file scopeinfo.inl.

◆ parsedFileNameCache

LRUCacheTable< MonoAllocator, ValueDescriptorPFN, std::hash<NString> > parsedFileNameCache
protected

Least recently used cache of parsed file name.

Definition at line 156 of file scopeinfo.inl.

◆ thread

Thread* thread = nullptr
protected

The thread passed with Set.

Definition at line 106 of file scopeinfo.inl.

◆ threadDictionary

ThreadDictionary 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 113 of file scopeinfo.inl.

◆ threadName

String threadName
protected

The name of the thread that executed the log.

Definition at line 109 of file scopeinfo.inl.

◆ threadNativeIDx

std::thread::id threadNativeIDx
protected

The C++ native ID.

Definition at line 103 of file scopeinfo.inl.

Constructor(s) / Destructor Details:

◆ 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 38 of file scopeinfo.cpp.

Here is the call graph for this function:

Method Details:

◆ GetFileName()

const NString 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 317 of file scopeinfo.inl.

Here is the call graph for this function:

◆ GetFileNameWithoutExtension()

const NString 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 341 of file scopeinfo.inl.

Here is the call graph for this function:

◆ GetFullPath()

const NString GetFullPath ( )
inline

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

Returns
The path of the source file.

Definition at line 283 of file scopeinfo.inl.

Here is the call graph for this function:

◆ GetLineNumber()

int GetLineNumber ( )
inline

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

Returns
The source file line number.

Definition at line 368 of file scopeinfo.inl.

◆ GetLoxName()

const NString 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 264 of file scopeinfo.inl.

◆ GetMethod()

const NCString GetMethod ( )
inline

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

Returns
The method name.

Definition at line 359 of file scopeinfo.inl.

◆ GetOrigFile()

const NCString & 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 274 of file scopeinfo.inl.

◆ getPathLength()

integer 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 458 of file scopeinfo.inl.

◆ GetThreadID()

threads::ThreadID GetThreadID ( )
inline

Receives the thread ID of the caller.

Returns
The thread ID.

Definition at line 397 of file scopeinfo.inl.

Here is the call graph for this function:

◆ GetThreadNameAndID()

const alib::String & 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 417 of file scopeinfo.inl.

Here is the call graph for this function:

◆ GetThreadNativeID()

std::thread::id GetThreadNativeID ( )
inline

Receives the thread ID of the caller.

Returns
The thread ID.

Definition at line 408 of file scopeinfo.inl.

◆ GetTimeStamp()

Ticks GetTimeStamp ( )
inline

The timestamp of the last invocation of Set.

Returns
The latest timestamp.

Definition at line 377 of file scopeinfo.inl.

◆ GetTrimmedPath()

void 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 303 of file scopeinfo.inl.

Here is the call graph for this function:

◆ GetTypeInfo()

const std::type_info * 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 387 of file scopeinfo.inl.

◆ PopNestedScope()

void PopNestedScope ( )
inline

Releases latest scope information.

Definition at line 227 of file scopeinfo.inl.

◆ Set()

void 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 118 of file scopeinfo.cpp.

Here is the call graph for this function:

◆ SetFileNameCacheCapacity()

void 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 214 of file scopeinfo.inl.

◆ SetSourcePathTrimRule()

void 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 142 of file scopeinfo.cpp.

Here is the call graph for this function:

◆ trimPath()

void 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 206 of file scopeinfo.cpp.

Here is the call graph for this function:

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