-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
149 lines (134 loc) · 2.84 KB
/
main.cpp
File metadata and controls
149 lines (134 loc) · 2.84 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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
////////////////////////////////
// Workfile : main.cpp
// Date : 10.01.2021
// Description : Testing Driver
////////////////////////////////
#include <iostream>
#include <cassert>
#include <string>
#include <memory>
//#include <vld.h>
#include "RemoteControl.h"
#include "Client.h"
#include "TStateCD.h"
#include "TStatePower.h"
#include "Device.h"
#include "TV.h"
#include "Heating.h"
#include "Stereo.h"
#include "On.h"
#include "Off.h"
#include "Open.h"
#include "Close.h"
#include "NoCommand.h"
using namespace std;
int main()
{
try
{
RemoteControl::SPtr ferni{ make_shared<RemoteControl>() };
TV::SPtr tv{ make_shared<TV>() };
Heating::SPtr heizung{ make_shared<Heating>() };
Stereo::SPtr anlage{ make_shared<Stereo>(nullptr) };
StereoCD::SPtr CD{ make_shared<StereoCD>() };
Stereo::SPtr anlage2{ make_shared<Stereo>(CD) };
Client client{ ferni };
client.AddDevice("Samsung", 3, tv, make_shared<On>(tv), make_shared<Off>(tv));
client.AddDevice("Heizung", 1, heizung, make_shared<On>(heizung), make_shared<Off>(heizung));
client.AddDevice("Stereo ohne CD", 4, anlage, make_shared<On>(anlage), make_shared<Off>(anlage));
client.AddDevice("Stereo mit CD", 5, anlage2, make_shared<On>(anlage2), make_shared<Off>(anlage2));
client.AddDevice("Laufwerk", 6, CD, make_shared<Open>(CD), make_shared<Close>(CD));
string input = "";
size_t slot = 0;
ferni->PrintRemoteInfo(cout);
while (true)
{
getline(cin, input);
slot = 0;
if (input.length() == 2)
{
switch (input[0])
{
case '1':
slot = 1;
break;
case '2':
slot = 2;
break;
case '3':
slot = 3;
break;
case '4':
slot = 4;
break;
case '5':
slot = 5;
break;
case '6':
slot = 6;
break;
default:
slot = 0;
cout << "slot number must be between 1 and 6!" << endl;
break;
}
if (slot != 0)
{
switch (input[1])
{
case 'o':
ferni->OnButtonPressed(slot);
break;
case 'f':
ferni->OffButtonPressed(slot);
break;
default:
cout << "wrong input!" << endl;
break;
}
}
}
else if (input.length() == 1)
{
switch (input[0])
{
case 'u':
ferni->UndoButtonPressed();
break;
case 'i':
client.PrintDeviceInfo(cout);
break;
default:
cout << "wrong input!" << endl;
break;
}
}
else
{
cout << "wrong input!" << endl;
}
}
}
catch (string const& error)
{
assert(!error.empty());
cerr << error << endl;
return 1; // Programm mit Fehlercode beenden
}
catch (bad_alloc const& error)
{
cerr << "memory allocation: " << error.what() << endl;
return 1;
}
catch (exception const& error)
{
cerr << "standard exception: " << error.what() << endl;
return 1;
}
catch (...)
{
cerr << "unhandled exception" << endl;
return 1;
}
return 0;
}