61dd2e3bd79a6458becd64b5920b75ff42a5be08
[iot2.git] / iotjava / iotrmi / C++ / sample / TestClass.hpp
1 #ifndef _TESTCLASS_HPP__
2 #define _TESTCLASS_HPP__
3
4 #include <iostream>
5 #include "TestClassInterface.hpp"
6 #include "StructC.hpp"
7
8 using namespace std;
9
10 class TestClass : public TestClassInterface {
11         public:
12                 TestClass();
13                 TestClass(int _int, float _float, string _string);
14                 //~TestClass();
15
16                 void                            setA(int _int);
17                 void                            setB(float _float);
18                 void                            setC(string _string);
19                 string                          sumArray(vector<string> newA);
20                 //int64_t                               sumArray(vector<int> newA);
21                 int                                     setAndGetA(int newA);
22                 int                                     setACAndGetA(string newC, int newA);
23                 void                            registerCallback(CallBackInterface* _cb);
24                 void                            registerCallback(vector<CallBackInterface*> _cb);
25                 int                                     callBack();
26                 void                            handleStruct(vector<data> vecData);
27
28         private:                
29                 int                                                     intA;
30                 float                                           floatB;
31                 string                                          stringC;
32                 CallBackInterface                       *cb;
33                 vector<CallBackInterface*>      cbvec;
34
35 };
36
37
38 TestClass::TestClass() {
39
40         intA = 1;
41         floatB = 2;
42         stringC = "345";
43         cb = NULL;
44         // cbvec doesn't need to be initialized again
45 }
46
47
48 TestClass::TestClass(int _int, float _float, string _string) {
49
50         intA = _int;
51         floatB = _float;
52         stringC = _string;
53         cb = NULL;
54         // cbvec doesn't need to be initialized again
55 }
56
57
58 void TestClass::setA(int _int) {
59
60         intA = _int;
61 }
62
63
64 void TestClass::setB(float _float) {
65
66         floatB = _float;
67 }
68
69
70 void TestClass::setC(string _string) {
71
72         stringC = _string;
73 }
74
75
76 string TestClass::sumArray(vector<string> newA) {
77
78         string sum = "";
79         int len = newA.size();
80         for(int c = 0; c < len; c++) {
81                 sum = sum + newA[c];
82         }
83         return sum;
84 }
85
86
87 /*int64_t TestClass::sumArray(vector<int> newA) {
88
89         int64_t sum = 0;
90         int len = newA.size();
91         for(int c = 0; c < len; c++) {
92                 sum = sum + newA[c];
93         }
94         return sum;
95 }*/
96
97
98 int TestClass::setAndGetA(int newA) {
99
100         intA = newA;
101         return intA;
102 }
103
104
105 int TestClass::setACAndGetA(string newC, int newA) {
106
107         stringC = newC;
108         intA = newA;
109         return intA;
110 }
111
112
113 void TestClass::registerCallback(CallBackInterface* _cb) {
114
115         cb = _cb;
116 }
117
118
119 void TestClass::registerCallback(vector<CallBackInterface*> _cb) {
120
121         for (CallBackInterface* cb : _cb) {
122                 cbvec.push_back(cb);
123                 cout << "Registering callback object!" << endl;
124         }
125 }
126
127
128 void TestClass::handleStruct(vector<data> vecData) {
129
130         for (data dat : vecData) {
131
132                 cout << "Name: " << dat.name << endl;
133                 cout << "Value: " << dat.value << endl;
134                 cout << "Year: " << dat.year << endl;
135         }
136 }
137
138
139 //int TestClass::callBack() {
140 //      return cb.printInt();
141 //}
142
143
144 int TestClass::callBack() {
145
146         int sum = 0;
147         for (CallBackInterface* cb : cbvec) {
148                 //cout << "Sum: " << sum << endl;
149                 //sum = sum + cb->printInt();
150                 cb->setInt(sum++);
151         }
152         //CallBackInterface* cb = cbvec[0];
153         //sum = cb->printInt();
154         //sum = sum + cb->printInt();
155         //cb->printInt();
156         //CallBackInterface* cb1 = cbvec[0];
157         //cb1->printInt();
158
159
160         return sum;
161 }
162
163 #endif
164