// AlphaModel.h
#ifndef ALPHAPROJECT_ALPHAMODEL_H
#define ALPHAPROJECT_ALPHAMODEL_H
#include <vector>
#include <string>
#include "Stack.h"
using namespace std;
class AlphaModel {
public:
AlphaModel();
~AlphaModel();
void AddFuncStr(const string& funcStr);
void PushValue(const double& value);
double PopValue();
const vector<string>& GetFuncsStr();
private:
vector<string> m_funcsStr;
Stack* m_valueStack;
};
#endif //ALPHAPROJECT_ALPHAMODEL_H
// AlphaModel.cpp
#include "AlphaModel.h"
AlphaModel::AlphaModel(): m_valueStack(new Stack(this->m_funcsStr.size())) {
};
AlphaModel::~AlphaModel() {
if (this->m_valueStack) {
delete this->m_valueStack;
this->m_valueStack = nullptr;
}
}
void AlphaModel::AddFuncStr(const string& funcStr) {
this->m_funcsStr.push_back(funcStr);
// 如果 g++ 版本支持的话, 考虑以后换成智能指针;
delete this->m_valueStack;
this->m_valueStack = new Stack(this->m_funcsStr.size());
}
void AlphaModel::PushValue(const double& value) {
this->m_valueStack->push(value);
}
double AlphaModel::PopValue() {
return this->m_valueStack->pop();
}
const vector<string>& AlphaModel::GetFuncsStr() {
return this->m_funcsStr;
}