Adding enum support for method argument; need to emulate the same functionality for...
[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                 void                            handleEnum(vector<EnumC> vecEn);
28
29         private:                
30                 int                                                     intA;
31                 float                                           floatB;
32                 string                                          stringC;
33                 CallBackInterface                       *cb;
34                 vector<CallBackInterface*>      cbvec;
35
36 };
37
38
39 TestClass::TestClass() {
40
41         intA = 1;
42         floatB = 2;
43         stringC = "345";
44         cb = NULL;
45         // cbvec doesn't need to be initialized again
46 }
47
48
49 TestClass::TestClass(int _int, float _float, string _string) {
50
51         intA = _int;
52         floatB = _float;
53         stringC = _string;
54         cb = NULL;
55         // cbvec doesn't need to be initialized again
56 }
57
58
59 void TestClass::setA(int _int) {
60
61         intA = _int;
62 }
63
64
65 void TestClass::setB(float _float) {
66
67         floatB = _float;
68 }
69
70
71 void TestClass::setC(string _string) {
72
73         stringC = _string;
74 }
75
76
77 string TestClass::sumArray(vector<string> newA) {
78
79         string sum = "";
80         int len = newA.size();
81         for(int c = 0; c < len; c++) {
82                 sum = sum + newA[c];
83         }
84         return sum;
85 }
86
87
88 /*int64_t TestClass::sumArray(vector<int> newA) {
89
90         int64_t sum = 0;
91         int len = newA.size();
92         for(int c = 0; c < len; c++) {
93                 sum = sum + newA[c];
94         }
95         return sum;
96 }*/
97
98
99 int TestClass::setAndGetA(int newA) {
100
101         intA = newA;
102         return intA;
103 }
104
105
106 int TestClass::setACAndGetA(string newC, int newA) {
107
108         stringC = newC;
109         intA = newA;
110         return intA;
111 }
112
113
114 void TestClass::registerCallback(CallBackInterface* _cb) {
115
116         cb = _cb;
117 }
118
119
120 void TestClass::registerCallback(vector<CallBackInterface*> _cb) {
121
122         for (CallBackInterface* cb : _cb) {
123                 cbvec.push_back(cb);
124                 cout << "Registering callback object!" << endl;
125         }
126 }
127
128
129 void TestClass::handleStruct(vector<data> vecData) {
130
131         for (data dat : vecData) {
132
133                 cout << "Name: " << dat.name << endl;
134                 cout << "Value: " << dat.value << endl;
135                 cout << "Year: " << dat.year << endl;
136         }
137 }
138
139
140 void TestClass::handleEnum(vector<EnumC> vecEn) {
141
142         for (EnumC en : vecEn) {
143                 cout << "Enum: " << en << endl;
144         }
145 }
146
147
148 //int TestClass::callBack() {
149 //      return cb.printInt();
150 //}
151
152
153 int TestClass::callBack() {
154
155         int sum = 0;
156         for (CallBackInterface* cb : cbvec) {
157                 sum = sum + cb->printInt();
158         }
159
160         return sum;
161 }
162
163 #endif
164