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