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

45 lines
1.2 KiB
C++
Raw Blame History

#ifndef __CODEMANAGER_H__
#define __CODEMANAGER_H__
#include "Memento.h"
#include <vector>
#include <string>
#include <stdio.h>
using namespace std;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
class CodeManager
{
public:
CodeManager(){}
~CodeManager(){
for(auto* memento: mementoList){
if(memento){
delete memento;
memento = nullptr;
}
}
}
CodeManager(const CodeManager&) = delete;
CodeManager& operator=(const CodeManager&) = delete;
void commit(Memento* m){
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>汾-%d, <20><><EFBFBD><EFBFBD>-%s, <20><>ǩ-%s\n", m->getVersion(), m->getDate().c_str(), m->getLabel().c_str());
mementoList.push_back(m);
}
// <20>л<EFBFBD><D0BB><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>İ汾<C4B0><E6B1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>
Memento* switchToPointedVersion(int index){
mementoList.erase(mementoList.begin() + mementoList.size() - index, mementoList.end());
return mementoList[mementoList.size() - 1];
}
// <20><>ӡ<EFBFBD><D3A1>ʷ<EFBFBD>
void codeLog(){
for (int i = 0; i < mementoList.size(); i++){
printf("[%d]<5D><><EFBFBD>汾-%d, <20><><EFBFBD><EFBFBD>-%s, <20><>ǩ-%s\n", i, mementoList[i]->getVersion(),
mementoList[i]->getDate().c_str(), mementoList[i]->getLabel().c_str());
}
}
private:
vector<Memento*> mementoList;
};
#endif