1 #ifndef _TESTCLASS_HPP__
2 #define _TESTCLASS_HPP__
7 #include "TestClassInterface.hpp"
12 class TestClass : public TestClassInterface {
15 TestClass(int _int, float _float, string _string);
19 void setB(float _float);
20 void setC(string _string);
21 string sumArray(vector<string> newA);
22 //int64_t sumArray(vector<int> newA);
23 int setAndGetA(int newA);
24 int setACAndGetA(string newC, int newA);
25 void registerCallback(CallBackInterface* _cb);
26 void registerCallback(vector<CallBackInterface*> _cb);
28 vector<data> handleStruct(vector<data> vecData);
29 vector<EnumC> handleEnum(vector<EnumC> vecEn);
38 CallBackInterface *cb;
39 vector<CallBackInterface*> cbvec;
44 TestClass::TestClass() {
50 // cbvec doesn't need to be initialized again
54 TestClass::TestClass(int _int, float _float, string _string) {
60 // cbvec doesn't need to be initialized again
64 void TestClass::setA(int _int) {
70 void TestClass::setB(float _float) {
76 void TestClass::setC(string _string) {
82 string TestClass::sumArray(vector<string> newA) {
85 int len = newA.size();
86 for(int c = 0; c < len; c++) {
93 /*int64_t TestClass::sumArray(vector<int> newA) {
96 int len = newA.size();
97 for(int c = 0; c < len; c++) {
104 int TestClass::setAndGetA(int newA) {
111 int TestClass::setACAndGetA(string newC, int newA) {
119 void TestClass::registerCallback(CallBackInterface* _cb) {
125 void TestClass::registerCallback(vector<CallBackInterface*> _cb) {
127 for (CallBackInterface* cb : _cb) {
129 cout << "Registering callback object!" << endl;
134 vector<data> TestClass::handleStruct(vector<data> vecData) {
136 for (data dat : vecData) {
138 cout << "Name: " << dat.name << endl;
139 cout << "Value: " << dat.value << endl;
140 cout << "Year: " << dat.year << endl;
143 newData.name = "Anonymous";
144 newData.value = 1.33;
146 vecData.push_back(newData);
152 vector<EnumC> TestClass::handleEnum(vector<EnumC> vecEn) {
154 for (EnumC en : vecEn) {
155 cout << "Enum: " << en << endl;
162 //int TestClass::callBack() {
163 // return cb.printInt();
166 void TestClass::thread1() {
168 CallBackInterface* cb = cbvec[0];
169 for(int i = 0; i < 10; i++) {
171 this_thread::sleep_for(chrono::seconds(1));
175 void TestClass::thread2() {
177 CallBackInterface* cb = cbvec[1];
178 for(int i = 0; i < 10; i++) {
180 this_thread::sleep_for(chrono::seconds(1));
184 int TestClass::callBack() {
187 for (CallBackInterface* cb : cbvec) {
188 sum = sum + cb->printInt();
192 /* thread th1 (&TestClass::thread1, this);
193 thread th2 (&TestClass::thread2, this);