From 4a7636fabd73892fd2095d07d68c4baf7259ae5e Mon Sep 17 00:00:00 2001 From: jimtahu Date: Fri, 26 Apr 2013 16:38:49 -0500 Subject: [PATCH] Moved Scalar Variable to its own class --- Scalar.cpp | 6 +++--- ScalarVariable.cpp | 29 +++++++++++++++++++++++++++++ ScalarVariable.h | 23 +++++++++++++++++++++++ Variable.cpp | 9 --------- Variable.h | 3 --- 5 files changed, 55 insertions(+), 15 deletions(-) create mode 100644 ScalarVariable.cpp create mode 100644 ScalarVariable.h diff --git a/Scalar.cpp b/Scalar.cpp index ba36025..cde6b10 100644 --- a/Scalar.cpp +++ b/Scalar.cpp @@ -2,14 +2,14 @@ #include #include -#include "Variable.h" +#include "ScalarVariable.h" using namespace std; void yyerror(std::string s); int yyparse (void); -map varTable; +map varTable; /** * Converts a string into a double. @@ -42,7 +42,7 @@ string num2str(double val){ * @return value, for convienace. */ string setValue(string name, string value){ - if(varTable.count(name)==0)varTable[name]=new Variable(name); + if(varTable.count(name)==0)varTable[name]=new ScalarVariable(name); varTable[name]->SetValue(value); return value; }//end setValue diff --git a/ScalarVariable.cpp b/ScalarVariable.cpp new file mode 100644 index 0000000..0a65c92 --- /dev/null +++ b/ScalarVariable.cpp @@ -0,0 +1,29 @@ +/* + * ScalarVariable.cpp + * + * Created on: Apr 26, 2013 + * Author: jimtahu + */ + +#include "ScalarVariable.h" + +ScalarVariable::ScalarVariable(string name):Variable(name){ + this->Value=""; +} + +ScalarVariable::ScalarVariable(ScalarVariable &other):Variable(other){ + this->Value=other.GetValue(); +} + +string ScalarVariable::GetValue(void){ + return this->Value; +} + +void ScalarVariable::SetValue(string value){ + this->Value=value; +} + +ScalarVariable::~ScalarVariable() { + // TODO Auto-generated destructor stub +} + diff --git a/ScalarVariable.h b/ScalarVariable.h new file mode 100644 index 0000000..0f906fb --- /dev/null +++ b/ScalarVariable.h @@ -0,0 +1,23 @@ +/* + * ScalarVariable.h + * + * Created on: Apr 26, 2013 + * Author: jimtahu + */ + +#ifndef SCALARVARIABLE_H_ +#define SCALARVARIABLE_H_ + +#include "Variable.h" + +class ScalarVariable: public Variable { + string Value; +public: + ScalarVariable(string name); + ScalarVariable(ScalarVariable &other); + string GetValue(); + void SetValue(string value); + virtual ~ScalarVariable(); +}; + +#endif /* SCALARVARIABLE_H_ */ diff --git a/Variable.cpp b/Variable.cpp index 6ad6801..1f6cf8f 100644 --- a/Variable.cpp +++ b/Variable.cpp @@ -13,21 +13,12 @@ Variable::Variable(string name){ Variable::Variable(Variable &other){ this->Name=other.GetName(); - this->Value=other.GetValue(); } string Variable::GetName(void){ return this->Name; } -string Variable::GetValue(void){ - return this->Value; -} - -void Variable::SetValue(string value){ - this->Value=value; -} - Variable::~Variable(){ // TODO Auto-generated destructor stub } diff --git a/Variable.h b/Variable.h index 4083d14..37564c6 100644 --- a/Variable.h +++ b/Variable.h @@ -15,13 +15,10 @@ using namespace std; class Variable { private: string Name; - string Value; public: Variable(string name); Variable(Variable &other); virtual string GetName(); - virtual string GetValue(); - virtual void SetValue(string value); virtual ~Variable(); };