Graphite
Version 3
An experimental 3D geometry processing program
|
Abstract base class for the GOM interpreter. More...
#include <OGF/gom/interpreter/interpreter.h>
Public Member Functions | |
Interpreter () | |
Interpreter constructor. | |
virtual void | reset ()=0 |
Clears all variables, restarts from initial state. | |
virtual Any | resolve (const std::string &id, bool quiet=true) const |
Finds a variable by id. More... | |
virtual void | bind (const std::string &id, const Any &value)=0 |
Binds a value to a variable. More... | |
virtual void | list_names (std::vector< std::string > &names) const |
Lists the global variable names in this Interpreter.. More... | |
virtual Any | eval (const std::string &expression, bool quiet=true) const |
Evaluates a string with an expression. More... | |
void | inspect_meta_type (MetaType *meta_type) |
Outputs to the logger the methods, slots, properties of a given MetaClass. More... | |
void | list_classes () |
Outputs to the logger the names of all classes registered to GOM. | |
void | bind_object (const std::string &id, Object *object) |
Binds an object to a variable. More... | |
Object * | resolve_object (const std::string &id, bool quiet=true) const |
Finds an objet by id. More... | |
Object * | resolve_object_by_global_id (const std::string &id, bool quiet=true) const |
Finds an objet by global id. More... | |
Object * | eval_object (const std::string &expression, bool quiet=true) const |
Evaluates a string with an expression. More... | |
std::string | eval_string (const std::string &expression, bool quiet=true) const |
Evaluates a string with an expression. More... | |
virtual MetaType * | resolve_meta_type (const std::string &type_name) const |
Finds a MetaType by name. More... | |
virtual bool | bind_meta_type (MetaType *mtype) |
Binds a MetaType. More... | |
virtual Object * | create (const ArgList &args) |
Creates an object. More... | |
virtual std::string | get_environment_value (const std::string &name) |
Gets the value of a Geogram environment value. More... | |
virtual void | set_environment_value (const std::string &name, const std::string &value) |
Sets the value of an environment variable. More... | |
virtual bool | execute (const std::string &command, bool save_in_history=true, bool log=true)=0 |
Executes a single line of code in the interpreted language. More... | |
virtual bool | execute_file (const std::string &file_name) |
Executes commands from a given file. More... | |
virtual void | out (const std::string &message, const std::string &tag="GOM") |
Displays a message in the terminal or console. More... | |
virtual void | err (const std::string &message, const std::string &tag="GOM") |
Displays an error message in the terminal or console. More... | |
virtual void | warn (const std::string &message, const std::string &tag="GOM") |
Displays a warning message in the terminal or console. More... | |
virtual void | status (const std::string &message) |
Displays a status message. More... | |
virtual void | append_dynamic_libraries_path (const std::string &path) |
Adds a path where dynamic libraries can be loaded. More... | |
virtual bool | load_module (const std::string &module_name) |
Loads a plug-in. More... | |
virtual Connection * | connect (Request *from, Callable *to) |
Connects a signal to a callable. More... | |
Interpreter * | interpreter (const std::string &language) |
Gets an interpreter for a given language. More... | |
Interpreter * | interpreter_by_file_extension (const std::string &extension) |
Gets an interpreter for a given language by file extension. More... | |
void | search (const std::string &needle, const std::string &path="") |
Displays the names of all objects that contain a substring. More... | |
const std::string & | get_language () const |
Gets the name of the interpreted language. More... | |
const std::string & | get_filename_extension () const |
Gets the filename extensions for the interpreted language. More... | |
Scope * | get_globals () const |
Gets the Scope with the global variables. More... | |
Scope * | get_meta_types () const |
Gets the Scope with the meta types. More... | |
virtual | ~Interpreter () |
Interpreter destructor. | |
Object * | create (const std::string &classname, const ArgList &args) |
Creates an object from a classname and arguments list. More... | |
virtual void | automatic_completion (const std::string &line, index_t startw, index_t endw, const std::string &cmpword, std::vector< std::string > &matches) |
Gets the possible automatic completions from a partial command entered by the user in the command line. More... | |
virtual void | save_history (const std::string &file_name) const |
Saves the history to a file. More... | |
virtual void | clear_history () |
Clears the history. | |
void | add_to_history (const std::string &command) |
Adds a command line to the history. More... | |
size_t | history_size () const |
Gets the size of the history. More... | |
std::string | history_line (unsigned int l) const |
Gets one of the commands in the history by line index. More... | |
Public Member Functions inherited from OGF::Object | |
Object (bool transient=false) | |
Object constructor. More... | |
virtual | ~Object () |
Object destructor. | |
virtual MetaClass * | meta_class () const |
Gets the meta class. More... | |
virtual void | set_meta_class (MetaClass *mclass) |
Sets the meta class. More... | |
unsigned int | id () const |
Gets the identifier of this object. More... | |
std::string | string_id () const |
Gets the unique string identifier. More... | |
bool | has_method (const std::string &method_name) const |
Tests whether a method is defined. More... | |
virtual bool | invoke_method (const std::string &method_name, const ArgList &args, Any &ret_val) |
Invokes a method by method name and argument list, and gets the return value. More... | |
bool | invoke_method (const std::string &method_name, const ArgList &args) |
Invokes a method by method name and argument list. More... | |
bool | invoke_method (const std::string &method_name) |
Invokes a method by method name. More... | |
bool | has_property (const std::string &prop_name) const |
Tests whether a property is defined. More... | |
virtual bool | get_property (const std::string &prop_name, std::string &prop_value) const |
Gets a property. More... | |
virtual Connection * | connect_signal_to_slot (const std::string &signal_name, Object *to, const std::string &slot_name) |
Connects a signal with a slot of another object. More... | |
virtual void | add_connection (Connection *connection) |
Adds a connection to this object. More... | |
virtual void | remove_connection (Connection *connection) |
Removes a connection to this object. More... | |
virtual void | get_element (index_t i, Any &value) const |
Gets an element by index. More... | |
virtual void | set_element (index_t i, const Any &value) |
Sets an element by index. More... | |
bool | get_signals_enabled () const |
Tests wheter signals are enabled. More... | |
void | set_signals_enabled (bool value) |
Enables or disables signals. More... | |
bool | get_slots_enabled () const |
Tests wheter slots are enabled. More... | |
void | set_slots_enabled (bool value) |
Enables or disables slots. More... | |
MetaClass * | get_meta_class () const |
Gets the meta class. More... | |
std::string | get_string_id () const |
Gets the unique string identifier. More... | |
virtual std::string | get_doc () const |
Gets the documentation. More... | |
virtual Sign | compare (const Object *other) const |
Compares this object with another one. More... | |
virtual bool | is_a (const MetaType *type) const |
Tests whether this object inherits a given type. More... | |
void | disconnect () |
Removes all connections from signals of this objects. More... | |
void | enable_signals () |
Enables signals. | |
void | disable_signals () |
Disables signals. | |
void | enable_slots () |
Enables slots. | |
void | disable_slots () |
Disables slots. | |
void | set_properties (const ArgList &args) |
Sets several properties in a single call. More... | |
virtual bool | set_property (const std::string &name, const std::string &value) |
Sets an individual property. More... | |
void | help () const |
Displays some help about this object. More... | |
virtual bool | set_property (const std::string &name, const Any &value) |
Sets an individual property. More... | |
virtual bool | get_property (const std::string &prop_name, Any &prop_value) const |
Gets a property. More... | |
Public Member Functions inherited from GEO::Counted | |
void | ref () const |
Increments the reference count. More... | |
void | unref () const |
Decrements the reference count. More... | |
bool | is_shared () const |
Check if the object is shared. More... | |
int | nb_refs () const |
Gets the number of references that point to this object. More... | |
Static Public Member Functions | |
static Interpreter * | default_interpreter () |
Gets the default interpreter. More... | |
static Interpreter * | instance_by_language (const std::string &language) |
Gets the instance of the interpreter that interprets a given language. More... | |
static Interpreter * | instance_by_file_extension (const std::string &extension) |
Gets the instance of the interpreter by file extension. More... | |
static void | initialize (Interpreter *instance, const std::string &language, const std::string &extension) |
Initializes the interpreter subsystem, and defines the interpreter to be used. More... | |
static void | terminate (const std::string &language, const std::string &extension) |
Terminates an interpreter and removes a given language from the list of interpreters. More... | |
static void | terminate () |
Terminates the interpreter subsystem, and deallocates the interpreter. More... | |
Static Public Member Functions inherited from OGF::Object | |
static Object * | id_to_object (unsigned int id) |
Gets an object from a unique object id. More... | |
Static Public Member Functions inherited from GEO::Counted | |
static void | ref (const Counted *counted) |
Increments the reference count. More... | |
static void | unref (const Counted *counted) |
Decrements the reference count. More... | |
Public Attributes | |
__pad0__: void inspect(Object* object) | |
__pad1__: virtual std::string get_history() const | |
Public Attributes inherited from OGF::Object | |
__pad0__: virtual index_t get_nb_elements() const | |
__pad1__: bool equals(const Object* other) const | |
Protected Member Functions | |
void | filename_completion (const std::string &prefix, std::vector< std::string > &completions) |
Gets all possible filenames starting from a certain prefix. More... | |
void | filter_completion_candidates (const std::string &prefix, std::vector< std::string > &completions) |
Keeps in a list of completion only those that start with a given prefix. More... | |
virtual void | get_keys (const std::string &context, std::vector< std::string > &keys) |
Gets all possible keys in a certain context. More... | |
virtual void | get_keys (Any &context, std::vector< std::string > &keys) |
Gets all possible keys in a certain context. More... | |
void | inspect_method (Object *object, MetaMethod *mmethod) |
Displays the prototype of a given method of an object. More... | |
void | inspect_meta_class (Object *object, MetaClass *mclass) |
Displays a meta class. More... | |
void | inspect_meta_method (MetaMethod *mmethod) |
Outputs to the logger the signature of a method. More... | |
void | set_language (const std::string &language) |
Sets the name of the interpreted language. More... | |
void | set_filename_extension (const std::string &extension) |
Sets the filename extensions for the interpreted language. More... | |
virtual std::string | stringify (const std::string &str) const |
Transforms a string into a string constant in the interpreted language. More... | |
virtual std::string | name_value_pair_call (const std::string &args) const |
Transforms a list of name-value pairs arguments. More... | |
Protected Member Functions inherited from OGF::Object | |
virtual bool | emit_signal (const std::string &signal_name, const ArgList &args, bool called_from_slot=false) |
Emits a signal and calls the slots it is connected to. More... | |
Protected Member Functions inherited from GEO::Counted | |
Counted () | |
Creates a reference counted object. More... | |
virtual | ~Counted () |
Destroys a reference counted object. More... | |
Protected Attributes | |
std::vector< std::string > | history_ |
std::string | language_ |
std::string | extension_ |
Abstract base class for the GOM interpreter.
It is completely independent of the used interpreted language. It is implemented in the gel_lua (and upcoming gel_python libraries).
Definition at line 222 of file interpreter.h.
void OGF::Interpreter::add_to_history | ( | const std::string & | command | ) |
Adds a command line to the history.
[in] | command | the command line to be added to the history |
|
virtual |
Adds a path where dynamic libraries can be loaded.
Under Windows, adds the path to the PATH environment variable. Under other OSes, does nothing.
[in] | path | the path to be added. |
|
virtual |
Gets the possible automatic completions from a partial command entered by the user in the command line.
[in] | line | the command line to be completed. |
[in] | startw,endw | the position of the word to be completed. |
[in] | cmpword | the word to be completed |
[out] | matches | the possible completions. |
|
pure virtual |
Binds a value to a variable.
The variable is then visible from the interpreter in the global scope.
[in] | id | the name of the variable. |
[in] | value | the value of the variable to be bound. |
Implemented in OGF::LuaInterpreter.
|
virtual |
void OGF::Interpreter::bind_object | ( | const std::string & | id, |
Object * | object | ||
) |
Binds an object to a variable.
The object is then visible from the interpreter in the global scope.
[in] | id | the name of the variable. |
[in] | object | the object to be bound |
|
virtual |
Creates an object.
[in] | args | the ArgList, with at least an argument classname. The other arguments are passed to the constructor. |
Creates an object from a classname and arguments list.
[in] | classname | the classname, with the 'OGF::' scope. |
[in] | args | the arguments list. |
|
inlinestatic |
Gets the default interpreter.
Definition at line 519 of file interpreter.h.
|
virtual |
Displays an error message in the terminal or console.
[in] | message | the message to be displayed. |
[in] | tag | an optional tag. |
|
virtual |
Evaluates a string with an expression.
[in] | expression | a string with an expression. |
[in] | quiet | if true, do not display error messages. |
Reimplemented in OGF::LuaInterpreter.
Object* OGF::Interpreter::eval_object | ( | const std::string & | expression, |
bool | quiet = true |
||
) | const |
Evaluates a string with an expression.
[in] | expression | a string with an expression. |
[in] | quiet | if true, do not display error messages. |
std::string OGF::Interpreter::eval_string | ( | const std::string & | expression, |
bool | quiet = true |
||
) | const |
Evaluates a string with an expression.
[in] | expression | a string with an expression. |
[in] | quiet | if true, do not display error messages. |
|
pure virtual |
Executes a single line of code in the interpreted language.
[in] | command | the line of code |
[in] | save_in_history | true if the command should be saved in the history |
[in] | log | true if the command should be displayed to the logging console |
true | if the command could be sucessfully executed |
false | otherwise |
Implemented in OGF::LuaInterpreter.
|
virtual |
Executes commands from a given file.
[in] | file_name | name of the file that contains the commands to be executed |
true | if the file could be sucessfully executed |
false | otherwise |
Reimplemented in OGF::LuaInterpreter.
|
protected |
Gets all possible filenames starting from a certain prefix.
[in] | prefix | either en empty string, or an escaped string with the beginning of a filename. |
[out] | completions | all the filenames that match the input prefix. |
|
protected |
Keeps in a list of completion only those that start with a given prefix.
[in] | prefix | the prefix |
[in,out] | completions | the vector of strings to be filtered. On exit, only those that start with prefix are kept. |
|
virtual |
Gets the value of a Geogram environment value.
[in] | name | name of the variable |
|
inline |
Gets the filename extensions for the interpreted language.
Definition at line 544 of file interpreter.h.
|
inline |
Gets the Scope with the global variables.
Definition at line 552 of file interpreter.h.
|
protectedvirtual |
Gets all possible keys in a certain context.
[in] | context | the name of a variable. |
[out] | keys | the name of all the data members and function members of the variable. |
|
protectedvirtual |
Gets all possible keys in a certain context.
[in] | context | the name of a variable. |
[out] | keys | the name of all the data members and function members of the variable. |
Reimplemented in OGF::LuaInterpreter.
|
inline |
Gets the name of the interpreted language.
Definition at line 535 of file interpreter.h.
|
inline |
Gets the Scope with the meta types.
Definition at line 560 of file interpreter.h.
|
inline |
Gets one of the commands in the history by line index.
[in] | l | the index of the line in the history |
Definition at line 678 of file interpreter.h.
|
inline |
Gets the size of the history.
Definition at line 669 of file interpreter.h.
|
static |
Initializes the interpreter subsystem, and defines the interpreter to be used.
This function is called at Graphite startup by the library that creates the interpreter (gel_python2 or gel_python3). Client code is not supposed to call this function directly.
[in] | instance | the interpreter to be used. |
[in] | language | the name of the interpreted language. |
[in] | extension | file extension for the interpreted language, without the point. |
Displays a meta class.
The meta class is displayed by the Logger.
[in] | object | the object. |
[in] | mclass | the meta class. |
|
protected |
Outputs to the logger the signature of a method.
[in] | mmethod | a pointer to the MetaMethod. |
void OGF::Interpreter::inspect_meta_type | ( | MetaType * | meta_type | ) |
|
protected |
Displays the prototype of a given method of an object.
The prototype is displayed by the Logger.
[in] | object | the object |
[in] | mmethod | the method |
|
static |
Gets the instance of the interpreter by file extension.
[in] | extension | file extension without the dot. |
|
static |
Gets the instance of the interpreter that interprets a given language.
[in] | language | the interpreted language. |
|
inline |
Gets an interpreter for a given language.
[in] | language | "Lua" for lua, "Python" for python... |
Definition at line 495 of file interpreter.h.
|
inline |
Gets an interpreter for a given language by file extension.
[in] | extension | "lua" for lua, "py" for python... |
Definition at line 503 of file interpreter.h.
|
virtual |
Lists the global variable names in this Interpreter..
[out] | names | a vector of strings with the names of the global variables. |
Reimplemented in OGF::LuaInterpreter.
|
virtual |
Loads a plug-in.
[in] | module_name | the name of the plug-in. |
true | if the module was successfully loaded. |
false | otherwise. |
|
protectedvirtual |
Transforms a list of name-value pairs arguments.
Some interpreters (e.g., Lua) need special syntax for name-value pair calls. Default implementation returns the input string.
[in] | args | a set of comma-separated name-value pairs. |
Reimplemented in OGF::LuaInterpreter.
|
virtual |
Displays a message in the terminal or console.
[in] | message | the message to be displayed. |
[in] | tag | an optional tag. |
|
virtual |
Finds a variable by id.
[in] | id | the id, can be either a previously bound id defined in the interpreter, or an id of the form "@ClassName::#instance", where ClassName is the name of a class registered to GOM, and instance an integer that refers to a specific instance of that class (the latter form of ids is used by the VCR system for recording events received by the GUI widgets). |
[in] | quiet | if true, do not display error messages. |
id
in the current Scope, or nil if there is no such a variable. Reimplemented in OGF::LuaInterpreter.
|
virtual |
Object* OGF::Interpreter::resolve_object | ( | const std::string & | id, |
bool | quiet = true |
||
) | const |
Finds an objet by id.
[in] | id | the id, can be either a previously bound id defined in the interpreter, or an id of the form "@ClassName::#instance", where ClassName is the name of a class registered to GOM, and instance an integer that refers to a specific instance of that class. |
[in] | quiet | if true, do not display error messages. |
Object* OGF::Interpreter::resolve_object_by_global_id | ( | const std::string & | id, |
bool | quiet = true |
||
) | const |
Finds an objet by global id.
[in] | id | the id in the form "@ClassName::#instance", where ClassName is the name of a class registered to GOM, and instance an integer that refers to a specific instance of that class. |
[in] | quiet | if true, do not display error messages. |
|
virtual |
Saves the history to a file.
[in] | file_name | name of the file where the history should be saved. |
|
virtual |
Displays the names of all objects that contain a substring.
[in] | needle | the substring |
[in] | path | the path to be prepended to the names |
Reimplemented from OGF::Object.
|
virtual |
Sets the value of an environment variable.
[in] | name | name of the variable |
[in] | value | new value of the environment variable |
|
inlineprotected |
Sets the filename extensions for the interpreted language.
[in] | extension | the extension. |
Definition at line 762 of file interpreter.h.
|
inlineprotected |
Sets the name of the interpreted language.
[in] | language | the name of the interpreted language. |
Definition at line 754 of file interpreter.h.
|
virtual |
Displays a status message.
[in] | message | the message. |
|
protectedvirtual |
Transforms a string into a string constant in the interpreted language.
Default implementation adds single quotes.
[in] | str | the string to be transformed. |
|
static |
Terminates the interpreter subsystem, and deallocates the interpreter.
This function is called at Graphite shutdown. Client code is not supposed to call this function directly.
|
static |
Terminates an interpreter and removes a given language from the list of interpreters.
[in] | language | the name of the language to be terminated. |
[in] | extension | file extension for the interpreted language, without the point. |
|
virtual |
Displays a warning message in the terminal or console.
[in] | message | the message to be displayed. |
[in] | tag | an optional tag. |