Class Scope.

Inherits Garbage

A mechanism to save and restore context between scopes.

A scope allows parts of the code to change global state (such as the current log) during execution, and restore it afterwards. Objects of this class should be declared as automatic variables so that the destructor is called when execution leaves the lexical scope.

Note that the root scope must be declared with an explicit log, or the first logging statement will fail.

In order to keep track of scopes, there are some rules: If Scope a is created before Scope b, b must be deleted before a. Really deleted, Allocator::free() will not free them.

Scope::Scope( Log * l )

Creates and enters a new scope that has log l. The new scope is made current.

Scope::Scope()

Creates and enters a new scope that shares all the attributes of its enclosing scope. If there is no current scope, the new scope has no log.

The new scope is made current.

Reimplements Garbage::Garbage().

static Scope * Scope::current()

Returns a pointer to the current scope, or a null pointer if no scope has been created.

Log * Scope::log() const

Returns a pointer to the current scope log, or a null pointer if the current Scope has no Log.

void Scope::setLog( Log * l )

Sets the scope log to l. The previous Log is not affected. In particular, the previous Log is not commited. Should it be? Probably.

Scope::~Scope()

If this scope is the current scope, then the previous current scope is made current again.

If not, an exception is thrown. The case could be handled - we used to have code to handle this in Arena.

This web page based on source code belonging to The Archiveopteryx Developers. All rights reserved.