forked from FengJungle/DesignPattern
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
50 lines (39 loc) · 1.07 KB
/
main.cpp
File metadata and controls
50 lines (39 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "Originator.h"
#include "Memento.h"
#include "CodeManager.h"
int main()
{
CodeManager *Jungle = new CodeManager();
CodeVersion* codeVer = new CodeVersion(1001, "2019-11-03", "Initial version");
// 提交初始版本
printf("提交初始版本:\n");
Jungle->commit(codeVer->save());
// 修改一个版本,增加了日志功能
printf("\n提交一个版本,增加了日志功能:\n");
codeVer->setVersion(1002);
codeVer->setDate("2019-11-04");
codeVer->setLabel("Add log funciton");
Jungle->commit(codeVer->save());
// 修改一个版本,增加了Qt图片浏览器
printf("\n提交一个版本,增加了Qt图片浏览器:\n");
codeVer->setVersion(1003);
codeVer->setDate("2019-11-05");
codeVer->setLabel("Add Qt Image Browser");
Jungle->commit(codeVer->save());
// 查看提交历史
printf("\n查看提交历史\n");
Jungle->codeLog();
// 回退到上一个版本
printf("\n回退到上一个版本\n");
codeVer->restore(Jungle->switchToPointedVersion(1));
// 查看提交历史
printf("\n查看提交历史\n");
Jungle->codeLog();
printf("\n\n");
system("pause");
delete Jungle;
delete codeVer;
Jungle = nullptr;
codeVer = nullptr;
return 0;
}