Fixed compiler for Java code generation (not heavily tested yet, but fixes include...
[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 #include "Enum.hpp"
10 #include "Struct.hpp"
11
12 using namespace std;
13
14 class TestClass : public TestClassInterface {
15         public:
16                 TestClass();
17                 TestClass(int _int, float _float, string _string);
18
19                 char                            getByte(char in);
20                 short                           getShort(short in);
21                 int64_t                         getLong(int64_t in);
22                 float                           getFloat(float in);
23                 double                          getDouble(double in);
24                 bool                            getBoolean(bool in);
25                 char                            getChar(char in);
26
27                 vector<char>            getByteArray(vector<char> in);
28                 vector<short>           getShortArray(vector<short> in);
29                 vector<int64_t>         getLongArray(vector<int64_t> in);
30                 vector<float>           getFloatArray(vector<float> in);
31                 vector<double>          getDoubleArray(vector<double> in);
32                 vector<bool>            getBooleanArray(vector<bool> in);
33                 vector<char>            getCharArray(vector<char> in);
34
35                 vector<char>            getByteList(vector<char> in);
36                 vector<short>           getShortList(vector<short> in);
37                 vector<int64_t>         getLongList(vector<int64_t> in);
38                 vector<float>           getFloatList(vector<float> in);
39                 vector<double>          getDoubleList(vector<double> in);
40                 vector<bool>            getBooleanList(vector<bool> in);
41                 vector<char>            getCharList(vector<char> in);
42
43                 // Callbacks
44                 void                            registerCallback(CallBackInterfaceWithCallBack* _cb);
45                 void                            registerCallbackArray(vector<CallBackInterfaceWithCallBack*> _cb);
46                 void                            registerCallbackList(vector<CallBackInterfaceWithCallBack*> _cb);
47                 void                            registerCallbackComplex(int in, vector<CallBackInterfaceWithCallBack*> _cb, double db);
48                 int                                     callBack();
49                 vector<Enum>            handleCallbackEnum(vector<Enum> en, char c, vector<CallBackInterfaceWithCallBack*> _cb);
50
51                 // Enum
52                 Enum                            handleEnum(Enum en);
53                 vector<Enum>            handleEnumArray(vector<Enum> vecEn);
54                 vector<Enum>            handleEnumList(vector<Enum> vecEn);
55                 Enum                            handleEnumComplex(Enum en, int i, char c);
56                 vector<Enum>            handleEnumComplex2(vector<Enum> en, int i, char c);
57                 vector<Enum>            handleEnumTwo(vector<Enum> en1, vector<Enum> en2);
58                 vector<Enum>            handleEnumThree(vector<Enum> en1, vector<Enum> en2, vector<Struct> str1, vector<Struct> str2);
59
60                 // Struct
61                 Struct                          handleStruct(Struct str);
62                 vector<Struct>          handleStructArray(vector<Struct> vecStr);
63                 vector<Struct>          handleStructList(vector<Struct> vecStr);
64                 Struct                          handleStructComplex(int in, char c, Struct str);
65                 vector<Struct>          handleStructComplex2(int in, char c, vector<Struct> vecStr);
66                 vector<Struct>          handleStructTwo(vector<Struct> str1, vector<Struct> str2);
67                 vector<Struct>          handleStructThree(vector<Struct> str1, vector<Struct> str2, vector<Struct> str3);
68
69                 vector<Enum>            handleEnumStruct(vector<Enum> en, vector<Struct> str, char c);
70                 vector<Enum>            handleAll(vector<Enum> en, vector<Struct> str, char c, vector<CallBackInterfaceWithCallBack*> _cb);
71                 vector<Enum>            handleAllTwo(vector<Enum> en1, vector<Enum> en2, vector<Struct> str1, vector<Struct> str2, char c, 
72                                                                         vector<CallBackInterfaceWithCallBack*> _cb1, vector<CallBackInterfaceWithCallBack*> _cb2);
73
74                 int                                     getA();
75                 void                            setA(int _int);
76                 void                            setB(float _float);
77                 void                            setC(string _string);
78                 string                          sumArray(vector<string> newA);
79                 int                                     setAndGetA(int newA);
80                 int                                     setACAndGetA(string newC, int newA);
81
82         private:                
83                 int                                                                             intA;
84                 float                                                                   floatB;
85                 string                                                                  stringC;
86                 vector<CallBackInterfaceWithCallBack*>  cbvec;
87 };
88
89
90 TestClass::TestClass() {
91
92         intA = 1;
93         floatB = 2;
94         stringC = "345";
95         // cbvec doesn't need to be initialized again
96 }
97
98
99 TestClass::TestClass(int _int, float _float, string _string) {
100
101         intA = _int;
102         floatB = _float;
103         stringC = _string;
104         // cbvec doesn't need to be initialized again
105 }
106
107
108 void TestClass::registerCallbackArray(vector<CallBackInterfaceWithCallBack*> _cb) {
109
110         for (CallBackInterfaceWithCallBack* cb : _cb) {
111                 cbvec.push_back(cb);
112                 cout << "Registering callback object in array!" << endl;
113         }
114 }
115
116
117 void TestClass::registerCallbackList(vector<CallBackInterfaceWithCallBack*> _cb) {
118
119         for (CallBackInterfaceWithCallBack* cb : _cb) {
120                 cbvec.push_back(cb);
121                 cout << "Registering callback object in list!" << endl;
122         }
123 }
124
125
126 void TestClass::registerCallbackComplex(int in, vector<CallBackInterfaceWithCallBack*> _cb, double db) {
127
128         for (CallBackInterfaceWithCallBack* cb : _cb) {
129                 cbvec.push_back(cb);
130                 cout << "Registering callback object in list!" << endl;
131         }
132
133         cout << "Integer: " << in << endl;
134         cout << "Double: " << db << endl;
135 }
136
137
138 void TestClass::registerCallback(CallBackInterfaceWithCallBack* _cb) {
139
140         cbvec.push_back(_cb);
141         cout << "Registering callback object!" << endl;
142 }
143
144
145 int TestClass::callBack() {
146
147         int sum = 0;
148         for (CallBackInterfaceWithCallBack* cb : cbvec) {
149                 //cout << "Sum: " << sum << endl;
150                 sum = sum + cb->printInt();
151                 cb->needCallback(this);
152                 //cb->needCallback(this);
153                 TestClass* tc = new TestClass();
154                 cb->needCallback(tc);
155                 //cout << "Sum after: " << sum << endl;
156         }
157         cout << "About to return sum: " << sum << endl;
158
159         return sum;
160 }
161
162
163 // Single variables
164 char TestClass::getByte(char in) {
165
166         return in;
167 }
168
169
170 short TestClass::getShort(short in) {
171
172         return in;
173 }
174
175
176 int64_t TestClass::getLong(int64_t in) {
177
178         return in;
179 }
180
181
182 float TestClass::getFloat(float in) {
183
184         return in;
185 }
186
187
188 double TestClass::getDouble(double in) {
189
190         return in;
191 }
192
193
194 bool TestClass::getBoolean(bool in) {
195
196         return in;
197 }
198
199
200 char TestClass::getChar(char in) {
201
202         return in;
203 }
204
205
206 // Arrays
207 vector<char> TestClass::getByteArray(vector<char> in) {
208
209         return in;
210 }
211
212
213 vector<short> TestClass::getShortArray(vector<short> in) {
214
215         return in;
216 }
217
218
219 vector<int64_t> TestClass::getLongArray(vector<int64_t> in) {
220
221         return in;
222 }
223
224
225 vector<float> TestClass::getFloatArray(vector<float> in) {
226
227         return in;
228 }
229
230
231 vector<double> TestClass::getDoubleArray(vector<double> in) {
232
233         return in;
234 }
235
236
237 vector<bool> TestClass::getBooleanArray(vector<bool> in) {
238
239         return in;
240 }
241
242
243 vector<char> TestClass::getCharArray(vector<char> in) {
244
245         return in;
246 }
247
248 // List
249 vector<char> TestClass::getByteList(vector<char> in) {
250
251         return in;
252 }
253
254
255 vector<short> TestClass::getShortList(vector<short> in) {
256
257         return in;
258 }
259
260
261 vector<int64_t> TestClass::getLongList(vector<int64_t> in) {
262
263         return in;
264 }
265
266
267 vector<float> TestClass::getFloatList(vector<float> in) {
268
269         return in;
270 }
271
272
273 vector<double> TestClass::getDoubleList(vector<double> in) {
274
275         return in;
276 }
277
278
279 vector<bool> TestClass::getBooleanList(vector<bool> in) {
280
281         return in;
282 }
283
284
285 vector<char> TestClass::getCharList(vector<char> in) {
286
287         return in;
288 }
289
290
291 int TestClass::getA() {
292
293         return intA;
294 }
295
296
297 void TestClass::setA(int _int) {
298
299         intA = _int;
300 }
301
302
303 void TestClass::setB(float _float) {
304
305         floatB = _float;
306 }
307
308
309 void TestClass::setC(string _string) {
310
311         stringC = _string;
312 }
313
314
315 // Enum
316 Enum TestClass::handleEnum(Enum en) {
317
318         cout << "Enum: " << en << endl;
319         
320         return en;
321 }
322
323
324 vector<Enum> TestClass::handleEnumArray(vector<Enum> vecEn) {
325
326         for (Enum en : vecEn) {
327                 cout << "Enum: " << en << endl;
328         }
329         
330         return vecEn;
331 }
332
333
334 vector<Enum> TestClass::handleEnumList(vector<Enum> vecEn) {
335
336         for (Enum en : vecEn) {
337                 cout << "Enum: " << en << endl;
338         }
339         
340         return vecEn;
341 }
342
343
344 Enum TestClass::handleEnumComplex(Enum en, int i, char c) {
345
346         cout << "Enum: " << en << endl;
347         cout << "Integer: " << i << endl;
348         cout << "Char: " << c << endl;
349         
350         return en;
351 }
352
353
354 vector<Enum> TestClass::handleEnumComplex2(vector<Enum> vecEn, int in, char c) {
355
356         for (Enum en : vecEn) {
357                 cout << "Enum: " << en << endl;
358         }
359         cout << "Integer: " << in << endl;
360         cout << "Char: " << c << endl;
361         
362         return vecEn;
363 }
364
365
366 vector<Enum> TestClass::handleEnumTwo(vector<Enum> en1, vector<Enum> en2) {
367
368         for (Enum en : en1) {
369                 cout << "Enum1: " << en << endl;
370         }
371         for (Enum en : en2) {
372                 cout << "Enum2: " << en << endl;
373         }
374         
375         return en1;
376 }
377
378
379 vector<Enum> TestClass::handleEnumThree(vector<Enum> en1, vector<Enum> en2, vector<Struct> str1, vector<Struct> str2) {
380
381         for (Enum en : en1) {
382                 cout << "Enum1: " << en << endl;
383         }
384         for (Enum en : en2) {
385                 cout << "Enum2: " << en << endl;
386         }
387         
388         return en1;
389 }
390
391
392
393 // Struct
394 Struct TestClass::handleStruct(Struct str) {
395
396         cout << "Name: " << str.name << endl;
397         cout << "Value: " << str.value << endl;
398         cout << "Year: " << str.year << endl;
399
400         Struct test;
401         test.name = "Anonymous";
402         test.value = 1.33;
403         test.year = 2016;
404         str = test;
405
406         return str;
407 }
408
409
410 vector<Struct> TestClass::handleStructArray(vector<Struct> vecStr) {
411
412         for (Struct str : vecStr) {
413
414                 cout << "Name: " << str.name << endl;
415                 cout << "Value: " << str.value << endl;
416                 cout << "Year: " << str.year << endl;
417         }
418         Struct test;
419         test.name = "Anonymous";
420         test.value = 1.33;
421         test.year = 2016;
422         vecStr.push_back(test);
423
424         return vecStr;
425 }
426
427
428 vector<Struct> TestClass::handleStructList(vector<Struct> vecStr) {
429
430         for (Struct str : vecStr) {
431
432                 cout << "Name: " << str.name << endl;
433                 cout << "Value: " << str.value << endl;
434                 cout << "Year: " << str.year << endl;
435         }
436         Struct test;
437         test.name = "Trimananda";
438         test.value = 1.33;
439         test.year = 2016;
440         vecStr.push_back(test);
441
442         return vecStr;
443 }
444
445
446 vector<Struct> TestClass::handleStructTwo(vector<Struct> str1, vector<Struct> str2) {
447
448         for (Struct str : str1) {
449
450                 cout << "Name: " << str.name << endl;
451                 cout << "Value: " << str.value << endl;
452                 cout << "Year: " << str.year << endl;
453         }
454
455         return str2;
456 }
457
458
459 vector<Struct> TestClass::handleStructThree(vector<Struct> str1, vector<Struct> str2, vector<Struct> str3) {
460
461         for (Struct str : str1) {
462
463                 cout << "Name: " << str.name << endl;
464                 cout << "Value: " << str.value << endl;
465                 cout << "Year: " << str.year << endl;
466         }
467
468         return str2;
469 }
470
471
472 Struct TestClass::handleStructComplex(int in, char c, Struct str) {
473
474         cout << "Name: " << str.name << endl;
475         cout << "Value: " << str.value << endl;
476         cout << "Year: " << str.year << endl;
477
478         cout << "Integer: " << in << endl;
479         cout << "Char: " << c << endl;
480
481         Struct test;
482         test.name = "Anonymous";
483         test.value = 1.33;
484         test.year = 2016;
485         str = test;
486
487         return str;
488 }
489
490
491 vector<Struct> TestClass::handleStructComplex2(int in, char c, vector<Struct> vecStr) {
492
493         for (Struct str : vecStr) {
494                 cout << "Name: " << str.name << endl;
495                 cout << "Value: " << str.value << endl;
496                 cout << "Year: " << str.year << endl;
497         }
498
499         cout << "Integer: " << in << endl;
500         cout << "Char: " << c << endl;
501
502         return vecStr;
503 }
504
505
506 vector<Enum> TestClass::handleEnumStruct(vector<Enum> en, vector<Struct> str, char c) {
507
508         for (Struct st : str) {
509                 cout << "Name: " << st.name << endl;
510                 cout << "Value: " << st.value << endl;
511                 cout << "Year: " << st.year << endl;
512         }
513
514         cout << "Char: " << c << endl;
515
516         return en;
517 }
518
519
520 vector<Enum> TestClass::handleAll(vector<Enum> en, vector<Struct> str, char c, vector<CallBackInterfaceWithCallBack*> _cb) {
521
522         for (CallBackInterfaceWithCallBack* cb : _cb) {
523                 cbvec.push_back(cb);
524                 cout << "Registering callback object in array!" << endl;
525         }
526
527         for (Struct st : str) {
528                 cout << "Name: " << st.name << endl;
529                 cout << "Value: " << st.value << endl;
530                 cout << "Year: " << st.year << endl;
531         }
532
533         cout << "Char: " << c << endl;
534
535         return en;
536 }
537
538
539 vector<Enum> TestClass::handleAllTwo(vector<Enum> en1, vector<Enum> en2, vector<Struct> str1, vector<Struct> str2, char c, 
540                 vector<CallBackInterfaceWithCallBack*> _cb1, vector<CallBackInterfaceWithCallBack*> _cb2) {
541
542         for (CallBackInterfaceWithCallBack* cb : _cb1) {
543                 cbvec.push_back(cb);
544                 cout << "Registering callback object in array!" << endl;
545         }
546
547         for (Struct st : str1) {
548                 cout << "Name: " << st.name << endl;
549                 cout << "Value: " << st.value << endl;
550                 cout << "Year: " << st.year << endl;
551         }
552
553         cout << "Char: " << c << endl;
554
555         return en1;
556 }
557
558
559 vector<Enum> TestClass::handleCallbackEnum(vector<Enum> en, char c, vector<CallBackInterfaceWithCallBack*> _cb) {
560
561         for (CallBackInterfaceWithCallBack* cb : _cb) {
562                 cbvec.push_back(cb);
563                 cout << "Registering callback object in array!" << endl;
564         }
565
566         cout << "Char: " << c << endl;
567
568         return en;
569 }
570
571
572 string TestClass::sumArray(vector<string> newA) {
573
574         string sum = "";
575         int len = newA.size();
576         for(int c = 0; c < len; c++) {
577                 sum = sum + newA[c];
578         }
579         return sum;
580 }
581
582
583 int TestClass::setAndGetA(int newA) {
584
585         intA = newA;
586         return intA;
587 }
588
589
590 int TestClass::setACAndGetA(string newC, int newA) {
591
592         stringC = newC;
593         intA = newA;
594         return intA;
595 }
596
597 #endif
598