File tree Expand file tree Collapse file tree 2 files changed +90
-1
lines changed Expand file tree Collapse file tree 2 files changed +90
-1
lines changed Original file line number Diff line number Diff line change @@ -19,4 +19,5 @@ set(CMAKE_CXX_STANDARD 20)
19
19
#add_executable(lsp LSP/lsp_classic_example.cpp)
20
20
#add_executable(lsp LSP/lsp_better_example.cpp)
21
21
#add_executable(lspcovarient LSP/lsp_covariance_example.cpp)
22
- add_executable (lspqueryset LSP/lsp_query_set.cpp )
22
+ #add_executable(lspqueryset LSP/lsp_query_set.cpp)
23
+ add_executable (isp_door ISP/isp_door_example.cpp )
Original file line number Diff line number Diff line change
1
+
2
+ //
3
+ // Created by sajith on 4/18/21.
4
+ //
5
+
6
+ #include < iostream>
7
+ #include < optional>
8
+ #include < stdexcept>
9
+
10
+ class TimerClient
11
+ {
12
+ public:
13
+ virtual ~TimerClient () = default ;
14
+ virtual void timeout () = 0;
15
+ };
16
+
17
+ class Door : public TimerClient
18
+ {
19
+ public:
20
+ virtual void open () = 0;
21
+ virtual void close () = 0;
22
+ };
23
+
24
+ class Timer
25
+ {
26
+ TimerClient &client;
27
+
28
+ public:
29
+ Timer (TimerClient &client) : client{client}
30
+ {
31
+ client.timeout ();
32
+ }
33
+ };
34
+
35
+
36
+ class TimedDoor : public Door
37
+ {
38
+ std::optional<Timer> timer;
39
+ public:
40
+ void open ()
41
+ {
42
+ std::cout << " Open\n " ;
43
+ timer.emplace (Timer (*this ));
44
+ }
45
+
46
+ void close ()
47
+ {
48
+ std::cout << " Close\n " ;
49
+ }
50
+
51
+ void timeout ()
52
+ {
53
+ std::cout << " Timeout\n " ;
54
+ close ();
55
+ timer = std::nullopt;
56
+ }
57
+ };
58
+
59
+
60
+ class NormalDoor : public Door
61
+ {
62
+ public:
63
+ void open ()
64
+ {
65
+ std::cout << " Open\n " ;
66
+ }
67
+
68
+ void close ()
69
+ {
70
+ std::cout << " Close\n " ;
71
+ }
72
+
73
+ void timeout ()
74
+ {
75
+ throw std::runtime_error{" Not implemented" };
76
+ }
77
+
78
+ };
79
+
80
+ int main ()
81
+ {
82
+ TimedDoor door;
83
+ door.open ();
84
+ door.open ();
85
+
86
+ return 0 ;
87
+ }
88
+
You can’t perform that action at this time.
0 commit comments