gfy-cpp
Loading...
Searching...
No Matches
Memory Class Reference

Memory class. More...

#include <memory.hpp>

Public Member Functions

void set_variable (const string &name, const variable_t &value)
 Set the variable value.
 
unique_ptr< variable_tget_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_tvariables
 
map< string, function_tfunctions
 

Detailed Description

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

Member Function Documentation

◆ add_function()

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

Parameters
nameFunction name
funcFunction definition (arguments and body)
Exceptions
runtime_errorIf the function already exists

◆ cast_boolean()

bool Memory::cast_boolean ( const unique_ptr< variable_t > & var)
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

Parameters
varVariable to cast
Returns
bool The casted variable
Exceptions
runtime_errorIf the variable type does not match the type to cast

◆ cast_float()

float Memory::cast_float ( const unique_ptr< variable_t > & var)
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

Parameters
varVariable to cast
Returns
double The casted variable
Exceptions
runtime_errorIf the variable type does not match the type to cast

◆ cast_int()

int Memory::cast_int ( const unique_ptr< variable_t > & var)
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

Parameters
varVariable to cast
Returns
int The casted variable
Exceptions
runtime_errorIf the variable type does not match the type to cast

◆ cast_string()

string Memory::cast_string ( const unique_ptr< variable_t > & var)
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

Parameters
varVariable to cast
Returns
string The casted variable
Exceptions
runtime_errorIf the variable type does not match the type to cast

◆ get_variable()

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

Parameters
nameVariable name
Returns
unique_ptr<variable_t> Variable value

◆ set_variable()

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

Parameters
nameVariable name
valuevariable value

Field Documentation

◆ functions

map<string, function_t> Memory::functions
private

◆ variables

map<string, variable_t> Memory::variables
private

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