#include "StdAfx.h"
#include "Function.h"
CFunction::CFunction(void)
: m_Name(""),
m_Builtin(false),
m_Expression(""),
m_Coderef(NULL)
{
}
// Construct a new builtin function
CFunction::CFunction(string Name, float (*coderef)(float))
: m_Name(Name),
m_Builtin(true),
m_Expression(""),
m_Coderef(coderef)
{
}
// Construct a new user-defined function
CFunction::CFunction(string Name, string Expression)
: m_Name(Name),
m_Builtin(false),
m_Expression(Expression),
m_Coderef(NULL)
{
}
CFunction::~CFunction(void)
{
}
// Set the name of a function
void CFunction::SetName(string Name)
{
this->m_Name = Name;
}
// Get the name of the current function
string CFunction::GetName(void)
{
return this->m_Name;
}
// Set the builtin flag to either true or false
void CFunction::SetBuiltin(bool Value)
{
this->m_Builtin = Value;
}
// Returns true if the function is a builtin
bool CFunction::GetBuiltin(void)
{
return this->m_Builtin;
}
// Set the expression to run when the function is called
void CFunction::SetExpression(string Expression)
{
this->m_Expression = Expression;
}
// Get the runtime expression of the function
string CFunction::GetExpression(void)
{
return this->m_Expression;
}
// Set the coderef for a builtin function
void CFunction::SetCoderef(float (*coderef)(float))
{
this->m_Coderef = coderef;
}
// Execute the builtin function by coderef
float CFunction::ExecuteBuiltin(float Value)
{
// Make sure that this is a builtin function
if(this->m_Builtin == false || this->m_Coderef == NULL)
{
throw UNDEFINED_FUNCTION;
}
// If so, run it and return
return this->m_Coderef(Value);
}
// Set the symbol used as a parameter
void CFunction::SetSymbol(CSymbol * Symbol)
{
this->m_Symbol = Symbol;
}
// Get the symbol used for the function parameter
CSymbol * CFunction::GetSymbol(void)
{
return this->m_Symbol;
}