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