gfy-cpp
|
#include <memory.hpp>
Public Member Functions | |
void | set_variable (const string &name, const variable_t &value) |
Set the variable value. | |
unique_ptr< variable_t > | get_variable (const string &name) |
Get the variable value. | |
void | add_function (const string &name, const function_t &func) |
Add a function to the memory. | |
Static Public Member Functions | |
static int | cast_int (const unique_ptr< variable_t > &var) |
Cast a variable to integer. | |
static float | cast_float (const unique_ptr< variable_t > &var) |
Cast a variable to float. | |
static string | cast_string (const unique_ptr< variable_t > &var) |
Cast a variable to string. | |
static bool | cast_boolean (const unique_ptr< variable_t > &var) |
Cast a variable to boolean. | |
Private Attributes | |
map< string, variable_t > | variables |
map< string, function_t > | functions |
Memory class.
Memory class is used to store variables and functions. It is used by the interpreter to store the variables and functions that are created during the execution of the program
void Memory::add_function | ( | const string & | name, |
const function_t & | func ) |
Add a function to the memory.
Add a function to the memory. If the function already exists, the function throws an exception
name | Function name |
func | Function definition (arguments and body) |
runtime_error | If the function already exists |
|
static |
Cast a variable to boolean.
Cast a variable to boolean. If the variable type does not match the type to cast, the function throws an exception
var | Variable to cast |
runtime_error | If the variable type does not match the type to cast |
|
static |
Cast a variable to float.
Cast a variable to float. If the variable type does not match the type to cast, the function throws an exception
var | Variable to cast |
runtime_error | If the variable type does not match the type to cast |
|
static |
Cast a variable to integer.
Cast a variable to integer. If the variable type does not match the type to cast, the function throws an exception
var | Variable to cast |
runtime_error | If the variable type does not match the type to cast |
|
static |
Cast a variable to string.
Cast a variable to string. If the variable type does not match the type to cast, the function throws an exception
var | Variable to cast |
runtime_error | If the variable type does not match the type to cast |
unique_ptr< variable_t > Memory::get_variable | ( | const string & | name | ) |
Get the variable value.
Get the value of a variable. If the variable does not exist, return nullptr, otherwise return the variable value
name | Variable name |
void Memory::set_variable | ( | const string & | name, |
const variable_t & | value ) |
Set the variable value.
Change the value of a variable or create a new one
name | Variable name |
value | variable value |
|
private |
|
private |