ContRap-Core
|
Class Scope defines a relation between identifier names and their values within name scopes. More...
#include <scope.h>
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 DPtr & | get_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 DPtr & | get_local_value (const std::string &name) const |
Finds a value to the key within the current scope. | |
SPtr< Scope > | get_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 DPtr & | assign (const std::string &name, const DPtr &value, bool declare=false) |
Reassigns a value to a key. | |
virtual const DPtr & | assign_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, DPtr > | get_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 DPtr & | assign_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< Scope > | parent |
Parent scopes. |
typedef std::map<std::string, ObjectProperty> crp::Scope::ScopeValueMap [protected] |
Creates a new scope.
parent | Scope 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.
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.
name | Identifier name |
value | Value to assign |
declare | If set to true the identifier is declared within the local scope. |
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.
name | Identifier name |
value | Value to assign |
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.
key | New scope key |
void crp::Scope::declare | ( | const std::string & | name | ) |
Declares a name within the current scope.
name | Identifier 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.
name | Identifier name |
Reimplemented in crp::Instance.
Returns the parent scope.
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.
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.
name | Identifier name |
Reimplemented in crp::Class, and crp::Instance.
std::map<std::string, DPtr> crp::Scope::get_values | ( | ) | const |
Returns the scope value map.
void crp::Scope::protect | ( | const std::string & | name | ) |
Protects an identifier from being rewritten.
name | Identifier name |
virtual std::string crp::Scope::to_string | ( | ) | const [virtual] |
Creates an unformatted scope representation as a string.
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.
name | Identifier name |
SPtr<Scope> crp::Scope::parent [protected] |
Parent scopes.
ScopeValueMap crp::Scope::values [protected] |
Relations between the hash keys and the values.