ContRap-Core
Public Member Functions | Protected Member Functions | Protected Attributes

crp::Engine Class Reference

Class Engine is a combination of a parser and an interpreter. More...

#include <engine.h>

Public Member Functions

 Engine (bool debugger=false)
 Creates a new engine.
 ~Engine ()
 Releases the memory.
void clear ()
 Clears the engine and loads the default libraries.
const SPtr< Scope > & get_global_scope ()
 Returns the root scope of the interpreter.
Parserget_parser ()
 Returns the parser of the engine.
Interpreterget_interpreter ()
 Returns the interpreter of the engine.
PluginManagerget_plugin_manager ()
 Returns the instance of the plugin manager.
DPtr parse (const std::string &command)
 Parses a command and returns the resulting code object.
DPtr parse_debug (const std::string &command)
 Parses a command and returns the resulting code object.
DPtr evaluate (const std::string &statement, const SPtr< Scope > &scope=0)
 Evaluates a statement given by a string.
DPtr evaluate (const DPtr &object, const SPtr< Scope > &scope=0)
 Evaluates a statement.
DPtr call (const std::string &function, const SPtr< List > &arguments, const SPtr< Scope > &scope=0, std::map< std::string, DPtr > &options=Interpreter::empty_options)
 Calls a function.
DPtr call (const DPtr &function, const SPtr< List > &arguments, const SPtr< Scope > &scope=0, std::map< std::string, DPtr > &options=Interpreter::empty_options)
 Calls a function.
DPtr type_cast (const DPtr &object, const std::string &type_name, const SPtr< Scope > &scope=0)
 Tries to make a type cast using the interpreter.
SPtr< Stringxmlprint (const DPtr &object, const SPtr< Scope > &scope=0)
 Calls the internal XML-based printer by invoking the xmlprint function on the argument.
template<class T >
SPtr< T > cast (const DPtr &object, const SPtr< Scope > &scope=0)
 Templated type cast using the engine.
template<class T >
SPtr< T > abort_cast (const DPtr &object, const std::string &message="Invalid type cast", const SPtr< Scope > &scope=0)
 Templated hard type cast using the engine.
template<class T >
SPtr< T > hard_cast (const DPtr &object, const std::string &message, const SPtr< Scope > &scope=0)
 Templated hard type cast using the engine.
std::ostringstream & get_stream ()
 Returns a reference to the output stream.

Protected Member Functions

void init (bool debugger=false)
 Initializes the internal constants.
void destroy ()
 Finilazes the internal constants.

Protected Attributes

PluginManagerplugin_manager
 Plugin manager.
Parserparser
 Parser of the engine.
Interpreterinterpreter
 Interpreter of the engine.
std::ostringstream stream
 Output stream.

Detailed Description

Class Engine is a combination of a parser and an interpreter.


Constructor & Destructor Documentation

crp::Engine::Engine ( bool  debugger = false)

Creates a new engine.

This function should be used to initialize the symbolic engine.

Parameters:
debuggerDebugging status at startup
crp::Engine::~Engine ( )

Releases the memory.


Member Function Documentation

template<class T >
SPtr<T> crp::Engine::abort_cast ( const DPtr object,
const std::string &  message = "Invalid type cast",
const SPtr< Scope > &  scope = 0 
) [inline]

Templated hard type cast using the engine.

An error message is produced after a unsuccessful cast.

See the documentation of the cast() method for additional information.

Parameters:
objectObject to cast
messageAbort message to create if the cast does not succeed
scopeEvaluation scope
DPtr crp::Engine::call ( const DPtr function,
const SPtr< List > &  arguments,
const SPtr< Scope > &  scope = 0,
std::map< std::string, DPtr > &  options = Interpreter::empty_options 
) [inline]

Calls a function.

Parameters:
functionFunction expression
argumentsObject to evaluate
scopeCurrent scope
Returns:
Result of the evaluation
DPtr crp::Engine::call ( const std::string &  function,
const SPtr< List > &  arguments,
const SPtr< Scope > &  scope = 0,
std::map< std::string, DPtr > &  options = Interpreter::empty_options 
) [inline]

Calls a function.

Parameters:
functionFunction name
argumentsObject to evaluate
scopeCurrent scope
Returns:
Result of the evaluation
template<class T >
SPtr<T> crp::Engine::cast ( const DPtr object,
const SPtr< Scope > &  scope = 0 
) [inline]

Templated type cast using the engine.

Notice that the interpreter type casts are heavy weighted, since more than one type cast function can be called to determine the best cast. This might result in inefficient programs.

Use light weighted casts whenever it is possible.

You should additionally avoid heavy casts for big objects whenever it is possible. Use interface-casts (casts on procedure call instead).

Parameters:
objectObject to cast
scopeEvaluation scope
void crp::Engine::clear ( )

Clears the engine and loads the default libraries.

void crp::Engine::destroy ( ) [protected]

Finilazes the internal constants.

DPtr crp::Engine::evaluate ( const DPtr object,
const SPtr< Scope > &  scope = 0 
) [inline]

Evaluates a statement.

Parameters:
objectObject to evaluate
scopeCurrent scope
Returns:
Result of the evaluation
DPtr crp::Engine::evaluate ( const std::string &  statement,
const SPtr< Scope > &  scope = 0 
)

Evaluates a statement given by a string.

Parameters:
statementStatement to evaluate
scopescope Evaluation scope
Returns:
Result of the evaluation
const SPtr<Scope>& crp::Engine::get_global_scope ( ) [inline]

Returns the root scope of the interpreter.

Returns:
Global scope of the interpreter
Interpreter* crp::Engine::get_interpreter ( ) [inline]

Returns the interpreter of the engine.

Returns:
Interpreter of the engine
Parser* crp::Engine::get_parser ( ) [inline]

Returns the parser of the engine.

Returns:
Parser of the engine
PluginManager* crp::Engine::get_plugin_manager ( ) [inline]

Returns the instance of the plugin manager.

Returns:
Plugin manager
std::ostringstream& crp::Engine::get_stream ( ) [inline]

Returns a reference to the output stream.

The stream contents are prepended to the output of each command.

Returns:
Output stream reference
template<class T >
SPtr<T> crp::Engine::hard_cast ( const DPtr object,
const std::string &  message,
const SPtr< Scope > &  scope = 0 
) [inline]

Templated hard type cast using the engine.

An error message is produced after a unsuccessful cast.

See the documentation of the cast() method for additional information.

Parameters:
objectObject to cast
messageError message to create if the cast does not succeed
scopeEvaluation scope
void crp::Engine::init ( bool  debugger = false) [protected]

Initializes the internal constants.

DPtr crp::Engine::parse ( const std::string &  command) [inline]

Parses a command and returns the resulting code object.

Parameters:
commandCommand to parse
Returns:
Object which can be passed to the evaluation method of the engine or the interpreter.
DPtr crp::Engine::parse_debug ( const std::string &  command)

Parses a command and returns the resulting code object.

If the debug mode is not set to Interpreter::DEEP_DEBUG then this method disables logging messages.

Parameters:
commandCommand to parse
Returns:
Object which can be passed to the evaluation method of the engine or the interpreter.
DPtr crp::Engine::type_cast ( const DPtr object,
const std::string &  type_name,
const SPtr< Scope > &  scope = 0 
) [inline]

Tries to make a type cast using the interpreter.

This not only involves native C/C++ dynamic type casting but also the user defined ContRap casting procedures.

Parameters:
objectObject to cast
type_nameName of the target type
scopeCurrent scope
Returns:
Result of the cast or a zero pointer
SPtr<String> crp::Engine::xmlprint ( const DPtr object,
const SPtr< Scope > &  scope = 0 
)

Calls the internal XML-based printer by invoking the xmlprint function on the argument.

This method sets the debug level of the interpreter if no Interpreter::DEEP_DEBUG flag is set.

Parameters:
objectObject to print.
Returns:
String representation of the object.

Field Documentation

Interpreter of the engine.

Parser of the engine.

Plugin manager.

std::ostringstream crp::Engine::stream [protected]

Output stream.


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