ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
Scope Struct Reference

Description:


This type is used as the default class to provide access to program data when evaluating ALib expressions. Usually a derived type which contains references to necessary application data is passed to method Expression::Evaluate . Then, custom callback functions may cast this object back to its original type and access such application data.

Also, scope objects are used to store intermediate results and of-course the final one, in the case that such results are not of a simple type that can be boxed Box "by value".

For this, different simple allocator objects are provided. A custom, derived type may add own storage facilities, for example vectors of custom objects which are deleted when the vector is deleted.

A scope object can be reused for evaluating the same expression several times. Prior to evaluation, the custom "scoped data" has to be set. With each reuse, method Reset will be invoked internally. Hence, if custom 'allocators' are added in derived types, this method has to be overwritten to a) invoke the original method and b) clean such custom types.

One singleton of this type, used to store compile-time data is created with virtual method Compiler::getCompileTimeScope . If compile-time invokable custom callback methods use custom storage allocators, this method has to be overridden to return the proper custom version of this class. (Note, this is not needed for the evaluation-time instances, as this is created in the custom code unit anyhow and passed to method Expression::Evaluate .

See also
For details on the use of scopes see manual chapter 8 Scopes.

Definition at line 81 of file scope.hpp.

#include <scope.hpp>

Inheritance diagram for Scope:
[legend]
Collaboration diagram for Scope:
[legend]

Public Field Index:

MonoAllocator Allocator
 
ScopeCTScope
 
SPFormatter Formatter
 
HashMap< NString, ScopeResource * > NamedResources
 
std::vector< Expression *, StdContMA< Expression * > > NestedExpressions
 
std::vector< ScopeResource *, StdContMA< ScopeResource * > > Resources
 
std::vector< alib::BoxStack
 

Public Method Index:

ALIB_API Scope (SPFormatter &formatter)
 
virtual ~Scope ()
 
bool IsCompileTime ()
 
virtual ALIB_API void Reset ()
 

Field Details:

◆ Allocator

MonoAllocator Allocator

Block-allocator used to store temporary data and results. The allocated data within this object becomes cleared automatically by method Reset, in the moment an expression is evaluated a next time (usually with different custom scope data).

Note that this allocator is not cleared for the compile-time scope object CTScope.

Definition at line 90 of file scope.hpp.

◆ CTScope

Scope* CTScope

This is a pointer to the compile-time scope. This is available only at evaluation time and primarily is used to access field NamedResources. This allows to create resources at compile-time, which can be used for evaluation.

A sample use case is implemented with built-in compiler plug-in Strings . When wildcard or regex matching is performed on constant pattern strings, the matching class (which itself "compiles" the pattern once) is created once and reused during evaluation.

Definition at line 102 of file scope.hpp.

◆ Formatter

Used to convert numbers to strings and vice versa. In addition expression function Format of built-in compiler plugin Strings uses this object to perform the formatting of arbitrary objects according to a given format string.

Hence, to support customized format strings, a different formatter is to be passed here. Default format string conventions provided with ALib are python style and java/printf-like style .

The default implementation of method Compiler::getCompileTimeScope provides field Compiler::CfgFormatter with the constructor of the default compile-time scope.

Definition at line 139 of file scope.hpp.

◆ NamedResources

HashMap<NString, ScopeResource*> NamedResources

A list of user-defined, named resources. Named resources may be allocated at compile-time and used at evaluation-time.

Definition at line 123 of file scope.hpp.

◆ NestedExpressions

std::vector<Expression*, StdContMA<Expression*> > NestedExpressions

Stack of nested expressions called during evaluation. Used to detect cyclic expressions.

Definition at line 111 of file scope.hpp.

◆ Resources

std::vector<ScopeResource*,StdContMA<ScopeResource*> > Resources

Simple list of user-defined, virtually deletable objects. The objects in this vector will be deleted with Reset.

Definition at line 117 of file scope.hpp.

◆ Stack

std::vector<alib::Box> Stack

This is the argument stack used by class detail::VirtualMachine when evaluating expressions.

Definition at line 108 of file scope.hpp.

Constructor(s) / Destructor Details::

◆ Scope()

Scope ( SPFormatter & formatter)

Constructor.
Usually, for parameter formatter field Compiler::CfgFormatter should be provided.

Parameters
formatterA reference to a std::shared_ptr holding a formatter. Usually Compiler::CfgFormatter .

Definition at line 54 of file compiler.cpp.

◆ ~Scope()

virtual ~Scope ( )
inlinevirtual

Virtual destructor

Definition at line 155 of file scope.hpp.

Here is the call graph for this function:

Method Details:

◆ IsCompileTime()

bool IsCompileTime ( )
inline

This function may be called (respectively provides reliable results) only from within callback functions that this scope is passed to.

Note
Usually, this method is not needed to be checked. It is useful and provided to support more complicated management of resources, i.e. allocation of resources at compile-time which are later used for evaluation.
Returns
true if this is a compile-time invocation, false otherwise.

Definition at line 171 of file scope.hpp.

◆ Reset()

void Reset ( )
virtual

Scope objects usually are reused, either for evaluating the same expression using different scoped data (attached to derived versions of this class), or for evaluating different expression.
Such reuse is internally detected and if so, this method is invoked.

Instances of this class used as compilation scope, are not reset during the life-cycle of an expression.

Derived versions of this class need to free allocations performed by callback functions.

Definition at line 67 of file compiler.cpp.

Here is the call graph for this function:

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