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