Skip to content

Commit b755d97

Browse files
author
sajith
committed
Improved
1 parent 761f9f6 commit b755d97

File tree

2 files changed

+90
-1
lines changed

2 files changed

+90
-1
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ set(CMAKE_CXX_STANDARD 20)
1919
#add_executable(lsp LSP/lsp_classic_example.cpp)
2020
#add_executable(lsp LSP/lsp_better_example.cpp)
2121
#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)

ISP/isp_door_example.cpp

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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+

0 commit comments

Comments
 (0)