f33dbf28b97c95294af1ad4d9e8632d4ede57d85
[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                            registerCallbackArray(vector<CallBackInterfaceWithCallBack*> _cb);
44                 void                            registerCallbackList(vector<CallBackInterfaceWithCallBack*> _cb);
45                 void                            registerCallbackComplex(int in, vector<CallBackInterfaceWithCallBack*> _cb, double db);
46                 int                                     callBack();
47
48                 // Enum
49                 Enum                            handleEnum(Enum en);
50                 vector<Enum>            handleEnumArray(vector<Enum> vecEn);
51                 vector<Enum>            handleEnumList(vector<Enum> vecEn);
52                 Enum                            handleEnumComplex(Enum en, int i, char c);
53                 vector<Enum>            handleEnumComplex2(vector<Enum> en, int i, char c);
54
55                 // Struct
56                 Struct                          handleStruct(Struct str);
57                 vector<Struct>          handleStructArray(vector<Struct> vecStr);
58                 vector<Struct>          handleStructList(vector<Struct> vecStr);
59                 Struct                          handleStructComplex(int in, char c, Struct str);
60                 vector<Struct>          handleStructComplex2(int in, char c, vector<Struct> vecStr);
61
62                 vector<Enum>            handleEnumStruct(vector<Enum> en, vector<Struct> str, char c);
63                 vector<Enum>            handleAll(vector<Enum> en, vector<Struct> str, char c, vector<CallBackInterfaceWithCallBack*> _cb);
64
65                 int                                     getA();
66                 void                            setA(int _int);
67                 void                            setB(float _float);
68                 void                            setC(string _string);
69                 string                          sumArray(vector<string> newA);
70                 int                                     setAndGetA(int newA);
71                 int                                     setACAndGetA(string newC, int newA);
72
73         private:                
74                 int                                                                             intA;
75                 float                                                                   floatB;
76                 string                                                                  stringC;
77                 vector<CallBackInterfaceWithCallBack*>  cbvec;
78 };
79
80
81 TestClass::TestClass() {
82
83         intA = 1;
84         floatB = 2;
85         stringC = "345";
86         // cbvec doesn't need to be initialized again
87 }
88
89
90 TestClass::TestClass(int _int, float _float, string _string) {
91
92         intA = _int;
93         floatB = _float;
94         stringC = _string;
95         // cbvec doesn't need to be initialized again
96 }
97
98
99 void TestClass::registerCallback(CallBackInterfaceWithCallBack* _cb) {
100
101         cbvec.push_back(_cb);
102         cout << "Registering callback object!" << endl;
103 }
104
105
106 void TestClass::registerCallbackArray(vector<CallBackInterfaceWithCallBack*> _cb) {
107
108         for (CallBackInterfaceWithCallBack* cb : _cb) {
109                 cbvec.push_back(cb);
110                 cout << "Registering callback object in array!" << endl;
111         }
112 }
113
114
115 void TestClass::registerCallbackList(vector<CallBackInterfaceWithCallBack*> _cb) {
116
117         for (CallBackInterfaceWithCallBack* cb : _cb) {
118                 cbvec.push_back(cb);
119                 cout << "Registering callback object in list!" << endl;
120         }
121 }
122
123
124 void TestClass::registerCallbackComplex(int in, vector<CallBackInterfaceWithCallBack*> _cb, double db) {
125
126         for (CallBackInterfaceWithCallBack* cb : _cb) {
127                 cbvec.push_back(cb);
128                 cout << "Registering callback object in list!" << endl;
129         }
130
131         cout << "Integer: " << in << endl;
132         cout << "Double: " << db << endl;
133 }
134
135
136 int TestClass::callBack() {
137
138         int sum = 0;
139         for (CallBackInterfaceWithCallBack* cb : cbvec) {
140                 sum = sum + cb->printInt();
141         }
142
143         return sum;
144 }
145
146
147 // Single variables
148 char TestClass::getByte(char in) {
149
150         return in;
151 }
152
153
154 short TestClass::getShort(short in) {
155
156         return in;
157 }
158
159
160 int64_t TestClass::getLong(int64_t in) {
161
162         return in;
163 }
164
165
166 float TestClass::getFloat(float in) {
167
168         return in;
169 }
170
171
172 double TestClass::getDouble(double in) {
173
174         return in;
175 }
176
177
178 bool TestClass::getBoolean(bool in) {
179
180         return in;
181 }
182
183
184 char TestClass::getChar(char in) {
185
186         return in;
187 }
188
189
190 // Arrays
191 vector<char> TestClass::getByteArray(vector<char> in) {
192
193         return in;
194 }
195
196
197 vector<short> TestClass::getShortArray(vector<short> in) {
198
199         return in;
200 }
201
202
203 vector<int64_t> TestClass::getLongArray(vector<int64_t> in) {
204
205         return in;
206 }
207
208
209 vector<float> TestClass::getFloatArray(vector<float> in) {
210
211         return in;
212 }
213
214
215 vector<double> TestClass::getDoubleArray(vector<double> in) {
216
217         return in;
218 }
219
220
221 vector<bool> TestClass::getBooleanArray(vector<bool> in) {
222
223         return in;
224 }
225
226
227 vector<char> TestClass::getCharArray(vector<char> in) {
228
229         return in;
230 }
231
232 // List
233 vector<char> TestClass::getByteList(vector<char> in) {
234
235         return in;
236 }
237
238
239 vector<short> TestClass::getShortList(vector<short> in) {
240
241         return in;
242 }
243
244
245 vector<int64_t> TestClass::getLongList(vector<int64_t> in) {
246
247         return in;
248 }
249
250
251 vector<float> TestClass::getFloatList(vector<float> in) {
252
253         return in;
254 }
255
256
257 vector<double> TestClass::getDoubleList(vector<double> in) {
258
259         return in;
260 }
261
262
263 vector<bool> TestClass::getBooleanList(vector<bool> in) {
264
265         return in;
266 }
267
268
269 vector<char> TestClass::getCharList(vector<char> in) {
270
271         return in;
272 }
273
274
275 int TestClass::getA() {
276
277         return intA;
278 }
279
280
281 void TestClass::setA(int _int) {
282
283         intA = _int;
284 }
285
286
287 void TestClass::setB(float _float) {
288
289         floatB = _float;
290 }
291
292
293 void TestClass::setC(string _string) {
294
295         stringC = _string;
296 }
297
298
299 // Enum
300 Enum TestClass::handleEnum(Enum en) {
301
302         cout << "Enum: " << en << endl;
303         
304         return en;
305 }
306
307
308 vector<Enum> TestClass::handleEnumArray(vector<Enum> vecEn) {
309
310         for (Enum en : vecEn) {
311                 cout << "Enum: " << en << endl;
312         }
313         
314         return vecEn;
315 }
316
317
318 vector<Enum> TestClass::handleEnumList(vector<Enum> vecEn) {
319
320         for (Enum en : vecEn) {
321                 cout << "Enum: " << en << endl;
322         }
323         
324         return vecEn;
325 }
326
327
328 Enum TestClass::handleEnumComplex(Enum en, int i, char c) {
329
330         cout << "Enum: " << en << endl;
331         cout << "Integer: " << i << endl;
332         cout << "Char: " << c << endl;
333         
334         return en;
335 }
336
337
338 vector<Enum> TestClass::handleEnumComplex2(vector<Enum> vecEn, int in, char c) {
339
340         for (Enum en : vecEn) {
341                 cout << "Enum: " << en << endl;
342         }
343         cout << "Integer: " << in << endl;
344         cout << "Char: " << c << endl;
345         
346         return vecEn;
347 }
348
349
350
351 // Struct
352 Struct TestClass::handleStruct(Struct str) {
353
354         cout << "Name: " << str.name << endl;
355         cout << "Value: " << str.value << endl;
356         cout << "Year: " << str.year << endl;
357
358         Struct test;
359         test.name = "Anonymous";
360         test.value = 1.33;
361         test.year = 2016;
362         str = test;
363
364         return str;
365 }
366
367
368 vector<Struct> TestClass::handleStructArray(vector<Struct> vecStr) {
369
370         for (Struct str : vecStr) {
371
372                 cout << "Name: " << str.name << endl;
373                 cout << "Value: " << str.value << endl;
374                 cout << "Year: " << str.year << endl;
375         }
376         Struct test;
377         test.name = "Anonymous";
378         test.value = 1.33;
379         test.year = 2016;
380         vecStr.push_back(test);
381
382         return vecStr;
383 }
384
385
386 vector<Struct> TestClass::handleStructList(vector<Struct> vecStr) {
387
388         for (Struct str : vecStr) {
389
390                 cout << "Name: " << str.name << endl;
391                 cout << "Value: " << str.value << endl;
392                 cout << "Year: " << str.year << endl;
393         }
394         Struct test;
395         test.name = "Trimananda";
396         test.value = 1.33;
397         test.year = 2016;
398         vecStr.push_back(test);
399
400         return vecStr;
401 }
402
403
404 Struct TestClass::handleStructComplex(int in, char c, Struct str) {
405
406         cout << "Name: " << str.name << endl;
407         cout << "Value: " << str.value << endl;
408         cout << "Year: " << str.year << endl;
409
410         cout << "Integer: " << in << endl;
411         cout << "Char: " << c << endl;
412
413         Struct test;
414         test.name = "Anonymous";
415         test.value = 1.33;
416         test.year = 2016;
417         str = test;
418
419         return str;
420 }
421
422
423 vector<Struct> TestClass::handleStructComplex2(int in, char c, vector<Struct> vecStr) {
424
425         for (Struct str : vecStr) {
426                 cout << "Name: " << str.name << endl;
427                 cout << "Value: " << str.value << endl;
428                 cout << "Year: " << str.year << endl;
429         }
430
431         cout << "Integer: " << in << endl;
432         cout << "Char: " << c << endl;
433
434         return vecStr;
435 }
436
437
438 vector<Enum> TestClass::handleEnumStruct(vector<Enum> en, vector<Struct> str, char c) {
439
440         for (Struct st : str) {
441                 cout << "Name: " << st.name << endl;
442                 cout << "Value: " << st.value << endl;
443                 cout << "Year: " << st.year << endl;
444         }
445
446         cout << "Char: " << c << endl;
447
448         return en;
449 }
450
451
452 vector<Enum> TestClass::handleAll(vector<Enum> en, vector<Struct> str, char c, vector<CallBackInterfaceWithCallBack*> _cb) {
453
454         for (CallBackInterfaceWithCallBack* cb : _cb) {
455                 cbvec.push_back(cb);
456                 cout << "Registering callback object in array!" << endl;
457         }
458
459         for (Struct st : str) {
460                 cout << "Name: " << st.name << endl;
461                 cout << "Value: " << st.value << endl;
462                 cout << "Year: " << st.year << endl;
463         }
464
465         cout << "Char: " << c << endl;
466
467         return en;
468 }
469
470
471 string TestClass::sumArray(vector<string> newA) {
472
473         string sum = "";
474         int len = newA.size();
475         for(int c = 0; c < len; c++) {
476                 sum = sum + newA[c];
477         }
478         return sum;
479 }
480
481
482 int TestClass::setAndGetA(int newA) {
483
484         intA = newA;
485         return intA;
486 }
487
488
489 int TestClass::setACAndGetA(string newC, int newA) {
490
491         stringC = newC;
492         intA = newA;
493         return intA;
494 }
495
496 #endif
497