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