ContRap-Core
Data Structures | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes

crp::Scope Class Reference

Class Scope defines a relation between identifier names and their values within name scopes. More...

#include <scope.h>

Inheritance diagram for crp::Scope:
crp::Object crp::Class crp::Instance

Data Structures

class  ObjectProperty
 Object properties class. More...

Public Member Functions

 Scope (const SPtr< Scope > &parent=0)
 Creates a new scope.
virtual ~Scope ()
 Releases the memory.
virtual const DPtrget_value (const std::string &name) const
 Finds a value to the key within the current scope or in one of the parent scopes of the current scope.
virtual const DPtrget_local_value (const std::string &name) const
 Finds a value to the key within the current scope.
SPtr< Scopeget_scope (const std::string &name) const
 Returns a scope definition within the parents of the scope.
void declare (const std::string &name)
 Declares a name within the current scope.
virtual const DPtrassign (const std::string &name, const DPtr &value, bool declare=false)
 Reassigns a value to a key.
virtual const DPtrassign_local (const std::string &name, const DPtr &value)
 Reassigns a value to a key locally.
DPtr unassign (const std::string &name)
 Unassigns a value to a key.
void protect (const std::string &name)
 Protects an identifier from being rewritten.
void clear ()
 Clears the contents of the scope.
std::map< std::string, DPtrget_values () const
 Returns the scope value map.
const SPtr< Scope > & get_parent () const
 Returns the parent scope.
virtual Type get_type () const
 Returns the enumerated type of the object.
virtual std::string to_string () const
 Creates an unformatted scope representation as a string.

Protected Types

typedef std::map< std::string,
ObjectProperty
ScopeValueMap

Protected Member Functions

const DPtrassign_private (const std::string &name, ObjectProperty &property, const DPtr &value)
 Private assignment method.

Protected Attributes

ScopeValueMap values
 Relations between the hash keys and the values.
SPtr< Scopeparent
 Parent scopes.

Detailed Description

Class Scope defines a relation between identifier names and their values within name scopes.


Member Typedef Documentation

typedef std::map<std::string, ObjectProperty> crp::Scope::ScopeValueMap [protected]

Constructor & Destructor Documentation

crp::Scope::Scope ( const SPtr< Scope > &  parent = 0)

Creates a new scope.

Parameters:
parentScope where this scope was created
virtual crp::Scope::~Scope ( ) [virtual]

Releases the memory.

Notice: The virtual destructor makes the class Scope polymorphic, so it can be processed with dynamic cast.


Member Function Documentation

virtual const DPtr& crp::Scope::assign ( const std::string &  name,
const DPtr value,
bool  declare = false 
) [virtual]

Reassigns a value to a key.

If the value was not declared the method tries to assign the value within the parent scope. If there is no parent, the value is declared within the class and assigned.

This method, hence, assigns the value in any case.

Parameters:
nameIdentifier name
valueValue to assign
declareIf set to true the identifier is declared within the local scope.
Returns:
Value of the previous entry

Reimplemented in crp::Class.

virtual const DPtr& crp::Scope::assign_local ( const std::string &  name,
const DPtr value 
) [virtual]

Reassigns a value to a key locally.

As opposed to the assign()-method the method only tries to assign the value within the current scope. If the value is not declared in the current scope, the method returns an invalid pointer.

Parameters:
nameIdentifier name
valueValue to assign
Returns:
Value of the previous entry or an invalid pointer

Reimplemented in crp::Class.

const DPtr& crp::Scope::assign_private ( const std::string &  name,
ObjectProperty property,
const DPtr value 
) [protected]

Private assignment method.

void crp::Scope::clear ( )

Clears the contents of the scope.

Parameters:
keyNew scope key
void crp::Scope::declare ( const std::string &  name)

Declares a name within the current scope.

Parameters:
nameIdentifier name
virtual const DPtr& crp::Scope::get_local_value ( const std::string &  name) const [virtual]

Finds a value to the key within the current scope.

This function does neither look up in the parent no in the child classes. It is therefore faster than the get_value()-function.

Parameters:
nameIdentifier name
Returns:
Value of the name

Reimplemented in crp::Instance.

const SPtr<Scope>& crp::Scope::get_parent ( ) const [inline]

Returns the parent scope.

Returns:
Parent scope
SPtr<Scope> crp::Scope::get_scope ( const std::string &  name) const

Returns a scope definition within the parents of the scope.

This function always searches recursively.

virtual Type crp::Scope::get_type ( ) const [inline, virtual]

Returns the enumerated type of the object.

Returns:
Type of the object

Reimplemented from crp::Object.

Reimplemented in crp::Class, and crp::Instance.

virtual const DPtr& crp::Scope::get_value ( const std::string &  name) const [virtual]

Finds a value to the key within the current scope or in one of the parent scopes of the current scope.

Parameters:
nameIdentifier name
Returns:
Value of the name

Reimplemented in crp::Class, and crp::Instance.

std::map<std::string, DPtr> crp::Scope::get_values ( ) const

Returns the scope value map.

Returns:
Assignments of values in the scope
void crp::Scope::protect ( const std::string &  name)

Protects an identifier from being rewritten.

Parameters:
nameIdentifier name
virtual std::string crp::Scope::to_string ( ) const [virtual]

Creates an unformatted scope representation as a string.

Returns:
String representation of the scope

Reimplemented from crp::Object.

Reimplemented in crp::Class, and crp::Instance.

DPtr crp::Scope::unassign ( const std::string &  name)

Unassigns a value to a key.

The action of an unassign is always limited to the current scope.

Parameters:
nameIdentifier name
Returns:
Reference to a former object

Field Documentation

Parent scopes.

Relations between the hash keys and the values.


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