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