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