-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
82 lines (63 loc) · 2.87 KB
/
main.cpp
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <iostream>
#include <memory>
#include <string>
#include <fstream>
#include <boost/archive/text_iarchive.hpp>
#include "document/document.h"
#include "compositor/simple_compositor/simple_compositor.h"
#include "executor/executor.h"
#include "executor/command/insert_character.h"
#include "executor/command/remove_character.h"
#include "executor/command/save_document.h"
#include "executor/command/load_document.h"
#include "executor/command/copy.h"
#include "executor/command/paste.h"
#include "executor/executor.h"
#include "executor/command/insert_character.h"
#include "executor/command/remove_character.h"
#include "executor/command/move_cursor_left.h"
#include "executor/command/move_cursor_right.h"
#include "compositor/simple_compositor/simple_compositor.h"
int main() {
auto d = std::make_shared<Document>(std::make_shared<SimpleCompositor>());
auto document = std::dynamic_pointer_cast<IDocument>(d);
auto controller = std::make_unique<Executor>(2);
controller->Do(std::make_shared<InsertCharacter>(document, 'H'));
controller->Do(std::make_shared<InsertCharacter>(document, 'E'));
controller->Do(std::make_shared<InsertCharacter>(document, 'L'));
controller->Do(std::make_shared<InsertCharacter>(document, 'L'));
controller->Do(std::make_shared<InsertCharacter>(document, '0'));
controller->Undo();
controller->Redo();
std::cout << "Source: " << document << "\n";
controller->Do(std::make_shared<SaveDocument>(document, "doc_save.file"));
std::cout << "Saved: " << document << "\n";
controller->Do(std::make_shared<RemoveCharacter>(document));
controller->Do(std::make_shared<RemoveCharacter>(document));
controller->Do(std::make_shared<RemoveCharacter>(document));
controller->Do(std::make_shared<RemoveCharacter>(document));
controller->Do(std::make_shared<LoadDocument>(&document, "doc_save.file"));
std::cout << "Loaded: " << document << "\n";
document->DrawDocument();
controller->Do(std::make_shared<InsertCharacter>(document, ' '));
controller->Do(std::make_shared<Copy>(document, Point(3, 5), Point(8, 5)));
controller->Do(std::make_shared<Paste>(document, Point(9, 5)));
controller->Do(std::make_shared<InsertCharacter>(document, '!'));
std::cout << "UNDO !\n";
controller->Undo();
std::cout << "UNDO PASTE\n";
controller->Undo();
std::cout << "REDO PASTE\n";
controller->Redo();
controller->Do(std::make_shared<MoveCursorLeft>(document));
std::cout << "MOVE CURSOR LEFT\n";
document->DrawDocument();
controller->Do(std::make_shared<InsertCharacter>(document, 'X'));
controller->Do(std::make_shared<MoveCursorRight>(document));
std::cout << "MOVE CURSOR RIGHT\n";
document->DrawDocument();
controller->Do(std::make_shared<MoveCursorRight>(document));
std::cout << "MOVE CURSOR RIGHT\n";
document->DrawDocument();
return 0;
}