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