37#ifndef H_OGF_GOM_INTERPRETER_H
38#define H_OGF_GOM_INTERPRETER_H
68 gom_attribute(abstract,
"true")
95 virtual void list_names(std::vector<std::string>& names)
const;
101 const std::string& needle,
const std::string& path=
""
104 virtual index_t get_nb_elements()
const override;
142 void list_names(std::vector<std::string>& names)
const override;
174 void list_names(std::vector<std::string>& names)
const override;
206 void list_names(std::vector<std::string>& names)
const override;
213 std::map<std::string, Scope_var> subscopes_;
226 gom_attribute(abstract,
"true")
255 virtual Any resolve(
const std::string&
id,
bool quiet=
true)
const;
264 virtual void bind(
const std::string&
id,
const Any& value) = 0;
271 virtual void list_names(std::vector<std::string>& names)
const;
280 const std::string& expression,
bool quiet=
true
291 void inspect(
Object*
object);
342 const std::string&
id,
bool quiet=
true
353 const std::string& expression,
bool quiet=
true
363 const std::string& expression,
bool quiet=
true
408 const std::string& name,
const std::string& value
422 const std::string& command,
423 bool save_in_history =
true,
442 const std::string& message,
const std::string& tag =
"GOM"
451 const std::string& message,
const std::string& tag =
"GOM"
460 const std::string& message,
const std::string& tag =
"GOM"
467 virtual void status(
const std::string& message);
501 return instance_by_language(language);
509 const std::string& extension
511 return instance_by_file_extension(extension);
518 const std::string& needle,
const std::string& path=
""
527 return default_interpreter_;
535 virtual std::string get_history()
const;
587 const std::string& extension
608 Interpreter* instance,
const std::string& language,
609 const std::string& extension
621 const std::string& language,
const std::string& extension
650 const std::string& cmpword, std::vector<std::string>& matches
677 return history_.size();
686 return l < history_size() ? history_[l] : std::string(
"");
699 const std::string& prefix,
700 std::vector<std::string>& completions
711 const std::string& prefix, std::vector<std::string>& completions
721 const std::string& context, std::vector<std::string>& keys
731 Any& context, std::vector<std::string>& keys
762 language_ = language;
770 extension_ = extension;
780 virtual std::string
stringify(
const std::string& str)
const;
794 std::vector<std::string> history_;
795 std::string language_;
796 std::string extension_;
802 static std::map<std::string, Interpreter*>
803 instance_by_file_extension_;
A smart pointer with reference-counted copy semantics.
A class that stores a variable of arbitrary type.
Represents a list of name-value pairs.
The Scope that contains all global variables of an Interpreter.
Any resolve(const std::string &name) override
Finds a variable by id.
GlobalScope(Interpreter *interpreter)
GlobalScope constructor.
void list_names(std::vector< std::string > &names) const override
Lists all the variable names available in this scope.
~GlobalScope() override
GlobalScope destructor.
The Scope that contains all interfaces of an object.
~InterfaceScope() override
InterfaceScope destructor.
InterfaceScope(Object *object)
InterfaceScope constructor.
void list_names(std::vector< std::string > &names) const override
Lists all the variable names available in this scope.
Any resolve(const std::string &name) override
Finds a variable by id.
Abstract base class for the GOM interpreter.
static void initialize(Interpreter *instance, const std::string &language, const std::string &extension)
Initializes the interpreter subsystem, and defines the interpreter to be used.
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 lin...
virtual void append_dynamic_libraries_path(const std::string &path)
Adds a path where dynamic libraries can be loaded.
virtual void list_names(std::vector< std::string > &names) const
Lists the global variable names in this Interpreter..
virtual void save_history(const std::string &file_name) const
Saves the history to a file.
Interpreter * interpreter(const std::string &language)
Gets an interpreter for a given language.
const std::string & get_language() const
Gets the name of the interpreted language.
virtual Object * create(const ArgList &args)
Creates an object.
virtual Any eval(const std::string &expression, bool quiet=true) const
Evaluates a string with an expression.
Object * create(const std::string &classname, const ArgList &args)
Creates an object from a classname and arguments list.
static Interpreter * default_interpreter()
Gets the default interpreter.
const std::string & get_filename_extension() const
Gets the filename extensions for the interpreted language.
void set_filename_extension(const std::string &extension)
Sets the filename extensions for the interpreted language.
virtual bool bind_meta_type(MetaType *mtype)
Binds a MetaType.
virtual void warn(const std::string &message, const std::string &tag="GOM")
Displays a warning message in the terminal or console.
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.
virtual Any resolve(const std::string &id, bool quiet=true) const
Finds a variable by id.
void inspect_meta_method(MetaMethod *mmethod)
Outputs to the logger the signature of a method.
Object * resolve_object(const std::string &id, bool quiet=true) const
Finds an objet by id.
static void terminate()
Terminates the interpreter subsystem, and deallocates the interpreter.
virtual std::string stringify(const std::string &str) const
Transforms a string into a string constant in the interpreted language.
std::string eval_string(const std::string &expression, bool quiet=true) const
Evaluates a string with an expression.
virtual void out(const std::string &message, const std::string &tag="GOM")
Displays a message in the terminal or console.
virtual Connection * connect(Request *from, Callable *to)
Connects a signal to a callable.
virtual void get_keys(const std::string &context, std::vector< std::string > &keys)
Gets all possible keys in a certain context.
Interpreter()
Interpreter constructor.
void inspect_meta_type(MetaType *meta_type)
Outputs to the logger the methods, slots, properties of a given MetaClass.
Object * eval_object(const std::string &expression, bool quiet=true) const
Evaluates a string with an expression.
virtual bool execute_file(const std::string &file_name)
Executes commands from a given file.
virtual void bind(const std::string &id, const Any &value)=0
Binds a value to a variable.
Interpreter * interpreter_by_file_extension(const std::string &extension)
Gets an interpreter for a given language by file extension.
virtual void clear_history()
Clears the history.
Scope * get_meta_types() const
Gets the Scope with the meta types.
virtual void reset()=0
Clears all variables, restarts from initial state.
virtual std::string get_environment_value(const std::string &name)
Gets the value of a Geogram environment value.
virtual void status(const std::string &message)
Displays a status message.
static Interpreter * instance_by_file_extension(const std::string &extension)
Gets the instance of the interpreter by file extension.
static Interpreter * instance_by_language(const std::string &language)
Gets the instance of the interpreter that interprets a given language.
void inspect_method(Object *object, MetaMethod *mmethod)
Displays the prototype of a given method of an object.
void bind_object(const std::string &id, Object *object)
Binds an object to a variable.
~Interpreter() override
Interpreter destructor.
void filename_completion(const std::string &prefix, std::vector< std::string > &completions)
Gets all possible filenames starting from a certain prefix.
virtual MetaType * resolve_meta_type(const std::string &type_name) const
Finds a MetaType by name.
void search(const std::string &needle, const std::string &path="") override
Displays the names of all objects that contain a substring.
virtual bool load_module(const std::string &module_name)
Loads a plug-in.
size_t history_size() const
Gets the size of the history.
virtual void err(const std::string &message, const std::string &tag="GOM")
Displays an error message in the terminal or console.
virtual std::string name_value_pair_call(const std::string &args) const
Transforms a list of name-value pairs arguments.
void add_to_history(const std::string &command)
Adds a command line to the history.
Object * resolve_object_by_global_id(const std::string &id, bool quiet=true) const
Finds an objet by global id.
void list_classes()
Outputs to the logger the names of all classes registered to GOM.
void inspect_meta_class(Object *object, MetaClass *mclass)
Displays a meta class.
std::string history_line(unsigned int l) const
Gets one of the commands in the history by line index.
Scope * get_globals() const
Gets the Scope with the global variables.
virtual void get_keys(Any &context, std::vector< std::string > &keys)
Gets all possible keys in a certain context.
void set_language(const std::string &language)
Sets the name of the interpreted language.
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.
static void terminate(const std::string &language, const std::string &extension)
Terminates an interpreter and removes a given language from the list of interpreters.
virtual void set_environment_value(const std::string &name, const std::string &value)
Sets the value of an environment variable.
Base class for all objects in the GOM system.
A pointer to an object and to a meta-method of that object (a very limited notion of "closure").
A naming scope in an Interpreter.
virtual void get_element(index_t i, Any &value) const override
Gets an element by index.
~Scope() override
Scope destructor.
virtual void list_names(std::vector< std::string > &names) const
Lists all the variable names available in this scope.
Scope(Object *object)
Scope constructor.
void search(const std::string &needle, const std::string &path="") override
Displays the names of all objects that contain a substring.
virtual Any resolve(const std::string &name)=0
Finds a variable by id.
geo_index_t index_t
The type for storing and manipulating indices.
Global Graphite namespace.
Types and functions for numbers manipulation.
The base class for all objects in the GOM system.
Definitions common to all include files in the gom library.