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

64 lines
1.1 KiB
C++
Raw Blame History

#ifndef __CODEVERSION_H__
#define __CODEVERSION_H__
#include <iostream>
using namespace std;
#include "Memento.h"
// ԭ<><D4AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>CodeVersion
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>
Memento* save(){
return new Memento(this->version, this->date, this->label);
}
Memento *commit()
{
return new Memento(this->version, this->date, this->label);
}
// <20><><EFBFBD>˰汾
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>
int version;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E1BDBB><EFBFBD><EFBFBD>
string date;
// <20><><EFBFBD><EFBFBD><EFBFBD>ǩ
string label;
};
#endif