DesignPattern/19.MementoPattern/2.Code/Originator.h

64 lines
1.1 KiB
C
Raw Normal View History

2019-11-05 14:47:55 +00:00
#ifndef __CODEVERSION_H__
#define __CODEVERSION_H__
#include <iostream>
using namespace std;
#include "Memento.h"
// ԭ<><D4AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>CodeVersion
2019-11-05 14:47:55 +00:00
class CodeVersion
{
public:
CodeVersion(){
version = 0;
date = "1900-01-01";
label = "none";
}
CodeVersion(int iVersion, string iDate, string iLabel){
version = iVersion;
date = iDate;
label = iLabel;
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2019-11-05 14:47:55 +00:00
Memento* save(){
return new Memento(this->version, this->date, this->label);
}
Memento *commit()
{
return new Memento(this->version, this->date, this->label);
}
// <20><><EFBFBD>˰汾
2019-11-05 14:47:55 +00:00
void restore(Memento* memento){
setVersion(memento->getVersion());
setDate(memento->getDate());
setLabel(memento->getLabel());
}
void setVersion(int iVersion){
version = iVersion;
}
int getVersion(){
return version;
}
void setLabel(string iLabel){
label = iLabel;
}
string getLabel(){
return label;
}
void setDate(string iDate){
date = iDate;
}
string getDate(){
return date;
}
private:
// <20><><EFBFBD><EFBFBD>
2019-11-05 14:47:55 +00:00
int version;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E1BDBB><EFBFBD><EFBFBD>
2019-11-05 14:47:55 +00:00
string date;
// <20><><EFBFBD><EFBFBD><EFBFBD>ǩ
2019-11-05 14:47:55 +00:00
string label;
};
#endif