58a6d2a176cb8fa303090689d06cb4fba227fccc
[iot2.git] / iotjava / iotrmi / C++ / basics / TestClass.hpp
1 #ifndef _TESTCLASS_HPP__
2 #define _TESTCLASS_HPP__
3
4 #include <iostream>
5 #include <thread>
6 #include <chrono>
7 #include "TestClassInterface.hpp"
8 #include "CallBackInterfaceWithCallBack.hpp"
9
10 using namespace std;
11
12 class TestClass : public TestClassInterface {
13         public:
14                 TestClass();
15                 TestClass(int _int, float _float, string _string);
16
17                 char                            getByte(char in);
18                 short                           getShort(short in);
19                 int64_t                         getLong(int64_t in);
20                 float                           getFloat(float in);
21                 double                          getDouble(double in);
22                 bool                            getBoolean(bool in);
23                 char                            getChar(char in);
24
25                 vector<char>            getByteArray(vector<char> in);
26                 vector<short>           getShortArray(vector<short> in);
27                 vector<int64_t>         getLongArray(vector<int64_t> in);
28                 vector<float>           getFloatArray(vector<float> in);
29                 vector<double>          getDoubleArray(vector<double> in);
30                 vector<bool>            getBooleanArray(vector<bool> in);
31                 vector<char>            getCharArray(vector<char> in);
32
33                 vector<char>            getByteList(vector<char> in);
34                 vector<short>           getShortList(vector<short> in);
35                 vector<int64_t>         getLongList(vector<int64_t> in);
36                 vector<float>           getFloatList(vector<float> in);
37                 vector<double>          getDoubleList(vector<double> in);
38                 vector<bool>            getBooleanList(vector<bool> in);
39                 vector<char>            getCharList(vector<char> in);
40
41                 // Callbacks
42                 void                            registerCallback(CallBackInterfaceWithCallBack* _cb);
43                 //void                          registerCallback(vector<CallBackInterfaceWithCallBack*> _cb);
44                 int                                     callBack();
45
46                 // Enum
47                 Enum                            handleEnum(Enum en);
48                 vector<Enum>            handleEnumArray(vector<Enum> vecEn);
49                 vector<Enum>            handleEnumList(vector<Enum> vecEn);
50
51                 // Struct
52                 Struct                          handleStruct(Struct str);
53                 vector<Struct>          handleStructArray(vector<Struct> vecStr);
54                 vector<Struct>          handleStructList(vector<Struct> vecStr);
55
56                 int                                     getA();
57                 void                            setA(int _int);
58                 void                            setB(float _float);
59                 void                            setC(string _string);
60                 string                          sumArray(vector<string> newA);
61                 int                                     setAndGetA(int newA);
62                 int                                     setACAndGetA(string newC, int newA);
63
64         private:                
65                 int                                                                             intA;
66                 float                                                                   floatB;
67                 string                                                                  stringC;
68                 vector<CallBackInterfaceWithCallBack*>  cbvec;
69 };
70
71
72 TestClass::TestClass() {
73
74         intA = 1;
75         floatB = 2;
76         stringC = "345";
77         // cbvec doesn't need to be initialized again
78 }
79
80
81 TestClass::TestClass(int _int, float _float, string _string) {
82
83         intA = _int;
84         floatB = _float;
85         stringC = _string;
86         // cbvec doesn't need to be initialized again
87 }
88
89
90 void TestClass::registerCallback(CallBackInterfaceWithCallBack* _cb) {
91
92         cbvec.push_back(_cb);
93         cout << "Registering callback object!" << endl;
94 }
95
96
97 /*void TestClass::registerCallback(vector<CallBackInterfaceWithCallBack*> _cb) {
98
99         for (CallBackInterface* cb : _cb) {
100                 cbvec.push_back(cb);
101                 cout << "Registering callback object!" << endl;
102         }
103 }*/
104
105
106 int TestClass::callBack() {
107
108         int sum = 0;
109         for (CallBackInterfaceWithCallBack* cb : cbvec) {
110                 sum = sum + cb->printInt();
111         }
112
113         return sum;
114 }
115
116
117 // Single variables
118 char TestClass::getByte(char in) {
119
120         return in;
121 }
122
123
124 short TestClass::getShort(short in) {
125
126         return in;
127 }
128
129
130 int64_t TestClass::getLong(int64_t in) {
131
132         return in;
133 }
134
135
136 float TestClass::getFloat(float in) {
137
138         return in;
139 }
140
141
142 double TestClass::getDouble(double in) {
143
144         return in;
145 }
146
147
148 bool TestClass::getBoolean(bool in) {
149
150         return in;
151 }
152
153
154 char TestClass::getChar(char in) {
155
156         return in;
157 }
158
159
160 // Arrays
161 vector<char> TestClass::getByteArray(vector<char> in) {
162
163         return in;
164 }
165
166
167 vector<short> TestClass::getShortArray(vector<short> in) {
168
169         return in;
170 }
171
172
173 vector<int64_t> TestClass::getLongArray(vector<int64_t> in) {
174
175         return in;
176 }
177
178
179 vector<float> TestClass::getFloatArray(vector<float> in) {
180
181         return in;
182 }
183
184
185 vector<double> TestClass::getDoubleArray(vector<double> in) {
186
187         return in;
188 }
189
190
191 vector<bool> TestClass::getBooleanArray(vector<bool> in) {
192
193         return in;
194 }
195
196
197 vector<char> TestClass::getCharArray(vector<char> in) {
198
199         return in;
200 }
201
202 // List
203 vector<char> TestClass::getByteList(vector<char> in) {
204
205         return in;
206 }
207
208
209 vector<short> TestClass::getShortList(vector<short> in) {
210
211         return in;
212 }
213
214
215 vector<int64_t> TestClass::getLongList(vector<int64_t> in) {
216
217         return in;
218 }
219
220
221 vector<float> TestClass::getFloatList(vector<float> in) {
222
223         return in;
224 }
225
226
227 vector<double> TestClass::getDoubleList(vector<double> in) {
228
229         return in;
230 }
231
232
233 vector<bool> TestClass::getBooleanList(vector<bool> in) {
234
235         return in;
236 }
237
238
239 vector<char> TestClass::getCharList(vector<char> in) {
240
241         return in;
242 }
243
244
245 int TestClass::getA() {
246
247         return intA;
248 }
249
250
251 void TestClass::setA(int _int) {
252
253         intA = _int;
254 }
255
256
257 void TestClass::setB(float _float) {
258
259         floatB = _float;
260 }
261
262
263 void TestClass::setC(string _string) {
264
265         stringC = _string;
266 }
267
268
269 // Enum
270 Enum TestClass::handleEnum(Enum en) {
271
272         cout << "Enum: " << en << endl;
273         
274         return en;
275 }
276
277
278 vector<Enum> TestClass::handleEnumArray(vector<Enum> vecEn) {
279
280         for (Enum en : vecEn) {
281                 cout << "Enum: " << en << endl;
282         }
283         
284         return vecEn;
285 }
286
287
288 vector<Enum> TestClass::handleEnumList(vector<Enum> vecEn) {
289
290         for (Enum en : vecEn) {
291                 cout << "Enum: " << en << endl;
292         }
293         
294         return vecEn;
295 }
296
297
298 // Struct
299 Struct TestClass::handleStruct(Struct str) {
300
301         cout << "Name: " << str.name << endl;
302         cout << "Value: " << str.value << endl;
303         cout << "Year: " << str.year << endl;
304
305         Struct test;
306         test.name = "Anonymous";
307         test.value = 1.33;
308         test.year = 2016;
309         str = test;
310
311         return str;
312 }
313
314
315 vector<Struct> TestClass::handleStructArray(vector<Struct> vecStr) {
316
317         for (Struct str : vecStr) {
318
319                 cout << "Name: " << str.name << endl;
320                 cout << "Value: " << str.value << endl;
321                 cout << "Year: " << str.year << endl;
322         }
323         Struct test;
324         test.name = "Anonymous";
325         test.value = 1.33;
326         test.year = 2016;
327         vecStr.push_back(test);
328
329         return vecStr;
330 }
331
332
333 vector<Struct> TestClass::handleStructList(vector<Struct> vecStr) {
334
335         for (Struct str : vecStr) {
336
337                 cout << "Name: " << str.name << endl;
338                 cout << "Value: " << str.value << endl;
339                 cout << "Year: " << str.year << endl;
340         }
341         Struct test;
342         test.name = "Trimananda";
343         test.value = 1.33;
344         test.year = 2016;
345         vecStr.push_back(test);
346
347         return vecStr;
348 }
349
350
351 string TestClass::sumArray(vector<string> newA) {
352
353         string sum = "";
354         int len = newA.size();
355         for(int c = 0; c < len; c++) {
356                 sum = sum + newA[c];
357         }
358         return sum;
359 }
360
361
362 int TestClass::setAndGetA(int newA) {
363
364         intA = newA;
365         return intA;
366 }
367
368
369 int TestClass::setACAndGetA(string newC, int newA) {
370
371         stringC = newC;
372         intA = newA;
373         return intA;
374 }
375
376 #endif
377