ContRap-Core
|
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. | |
Parser * | get_parser () |
Returns the parser of the engine. | |
Interpreter * | get_interpreter () |
Returns the interpreter of the engine. | |
PluginManager * | get_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< String > | xmlprint (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 | |
PluginManager * | plugin_manager |
Plugin manager. | |
Parser * | parser |
Parser of the engine. | |
Interpreter * | interpreter |
Interpreter of the engine. | |
std::ostringstream | stream |
Output stream. |
crp::Engine::Engine | ( | bool | debugger = false | ) |
Creates a new engine.
This function should be used to initialize the symbolic engine.
debugger | Debugging status at startup |
crp::Engine::~Engine | ( | ) |
Releases the memory.
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).
object | Object to cast |
scope | Evaluation scope |
void crp::Engine::clear | ( | ) |
Clears the engine and loads the default libraries.
void crp::Engine::destroy | ( | ) | [protected] |
Finilazes the internal constants.
Evaluates a statement.
object | Object to evaluate |
scope | Current scope |
Evaluates a statement given by a string.
statement | Statement to evaluate |
scope | scope Evaluation scope |
Returns the root scope of the interpreter.
Interpreter* crp::Engine::get_interpreter | ( | ) | [inline] |
Returns the interpreter of the engine.
Parser* crp::Engine::get_parser | ( | ) | [inline] |
Returns the parser of the engine.
PluginManager* crp::Engine::get_plugin_manager | ( | ) | [inline] |
Returns the instance of the 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.
void crp::Engine::init | ( | bool | debugger = false | ) | [protected] |
Initializes the internal constants.
DPtr crp::Engine::parse | ( | const std::string & | command | ) | [inline] |
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.
command | Command to parse |
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.
object | Object to cast |
type_name | Name of the target type |
scope | Current scope |
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.
object | Object to print. |
Interpreter* crp::Engine::interpreter [protected] |
Interpreter of the engine.
Parser* crp::Engine::parser [protected] |
Parser of the engine.
PluginManager* crp::Engine::plugin_manager [protected] |
Plugin manager.
std::ostringstream crp::Engine::stream [protected] |
Output stream.