Skip to content

Commit

Permalink
Moved Scalar Variable to its own class
Browse files Browse the repository at this point in the history
  • Loading branch information
jimtahu committed Apr 26, 2013
1 parent cc96900 commit 4a7636f
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 15 deletions.
6 changes: 3 additions & 3 deletions Scalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
#include <iostream>
#include <map>

#include "Variable.h"
#include "ScalarVariable.h"

using namespace std;

void yyerror(std::string s);
int yyparse (void);

map<string, Variable*> varTable;
map<string, ScalarVariable*> varTable;

/**
* Converts a string into a double.
Expand Down Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions ScalarVariable.cpp
Original file line number Diff line number Diff line change
@@ -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
}

23 changes: 23 additions & 0 deletions ScalarVariable.h
Original file line number Diff line number Diff line change
@@ -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_ */
9 changes: 0 additions & 9 deletions Variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 0 additions & 3 deletions Variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};

Expand Down

0 comments on commit 4a7636f

Please sign in to comment.