ALib C++ Library
Library Version: 2402 R1
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. E.g., wee do not get the class name of the object or even its instance.

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

Collaboration diagram for ScopeInfo:
[legend]

Inner Type Index:

struct  Scope
 
struct  SourceFile
 
struct  SourcePathTrimRule
 

Public Type Index:

using ThreadDictionary = HashMap<threads::ThreadID, String32>
 

Public Static Field Index:

static ALIB_API int DefaultCacheSize = 5
 

Public Field Index:

NString loxName
 

Public Method Index:

ALIB_API ScopeInfo (const NString &name, MonoAllocator *allocator, config::Variable &tempVar)
 
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)
 
Ticks GetTimeStamp ()
 
void GetTrimmedPath (AString &target)
 
void Release ()
 
ALIB_API void Set (const NCString &source, int lineNumber, const NCString &method, threads::Thread *thread)
 
ALIB_API void SetSourcePathTrimRule (const NCString &path, lang::Inclusion includeString, int trimOffset, lang::Case sensitivity, const NString &trimReplacement, lang::Reach reach, Priorities priority)
 

Type Definition Details:

◆ ThreadDictionary

A std::map we use to translate thread IDs to thread names

Definition at line 74 of file scopeinfo.inl.

Field Details:

◆ actScopeDepth

int actScopeDepth = -1
protected

The current depth of recursive invocations.

Definition at line 216 of file scopeinfo.inl.

◆ AutoDetectTrimableSourcePath

bool AutoDetectTrimableSourcePath = true
protected

If true, next time a source path can not 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 122 of file scopeinfo.inl.

◆ cache

SourceFile* cache
protected

An array of source files. Its size is dependent on static field DefaultCacheSize.

Definition at line 190 of file scopeinfo.inl.

◆ cacheRun

uint64_t cacheRun = 0
protected

The 'timestamp' used to identify the LRU entry. Incremented, whenever a different source file is evaluated.

Definition at line 181 of file scopeinfo.inl.

◆ cacheSize

int cacheSize
protected

The number of source file path and corresponding, evaluated derived values. Determined in the constructor by reading static field DefaultCacheSize.

Definition at line 187 of file scopeinfo.inl.

◆ DefaultCacheSize

int DefaultCacheSize = 5
static

The number of source file path and corresponding, evaluated derived values. This might be modified, prior to creating any object of class Lox.
Defaults to 5.

Definition at line 83 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 106 of file scopeinfo.inl.

◆ GlobalSPTRsReadFromConfig

bool GlobalSPTRsReadFromConfig = false
staticprotected

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

Definition at line 113 of file scopeinfo.inl.

◆ lastSourceFile

SourceFile* lastSourceFile
protected

The last source file used. This is tried first with next invocation. If it does not match, the cache is searched for another matching one.

Definition at line 220 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 109 of file scopeinfo.inl.

◆ loxName

NString loxName

The name of the Lox we are attached to.

Definition at line 86 of file scopeinfo.inl.

◆ scopes

std::vector<Scope,StdContMA<Scope> > scopes
protected

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

Definition at line 213 of file scopeinfo.inl.

◆ thread

Thread* thread = nullptr
protected

The thread passed with Set.

Definition at line 127 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 136 of file scopeinfo.inl.

◆ threadName

String threadName
protected

The name of the thread that executed the log.

Definition at line 130 of file scopeinfo.inl.

Constructor(s) / Destructor Details::

◆ ScopeInfo()

ScopeInfo ( const NString & name,
MonoAllocator * allocator,
config::Variable & tempVar )

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
tempVarA temporary variable for internal use.

Definition at line 54 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 356 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 380 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 322 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 407 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 303 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 398 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 313 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 481 of file scopeinfo.inl.

Here is the call graph for this function:

◆ GetThreadID()

threads::ThreadID GetThreadID ( )
inline

Receives the thread ID of the caller.

Returns
The thread ID.

Definition at line 426 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 440 of file scopeinfo.inl.

Here is the call graph for this function:

◆ GetTimeStamp()

Ticks GetTimeStamp ( )
inline

The timestamp of the last invocation of Set.

Returns
The latest timestamp.

Definition at line 416 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 342 of file scopeinfo.inl.

Here is the call graph for this function:

◆ Release()

void Release ( )
inline

Releases latest scope information.

Definition at line 265 of file scopeinfo.inl.

◆ Set()

void Set ( const NCString & source,
int lineNumber,
const NCString & method,
threads::Thread * thread )

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
sourceName, including path, of the source code file of the actual log invocation (FILE).
lineNumberLine number within the source code file of the actual log invocation (LINE).
methodName of method or function of the actual log invocation (mostly func/ FUNCTION).
threadThe thread. If nullptr, it will be determined if needed.

Definition at line 132 of file scopeinfo.cpp.

Here is the call graph for this function:

◆ SetSourcePathTrimRule()

void SetSourcePathTrimRule ( const NCString & path,
lang::Inclusion includeString,
int trimOffset,
lang::Case sensitivity,
const NString & trimReplacement,
lang::Reach reach,
Priorities 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 188 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 255 of file scopeinfo.cpp.

Here is the call graph for this function:

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