X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=iotjava%2Fiotrmi%2FC%2B%2B%2Fbasics%2FTestClass.hpp;h=ca963490351ab0ad57adc281a7f45d58588ebda8;hb=e9a65a3fa878d7451ceb4f5a2cb1bc9ee846e035;hp=58a6d2a176cb8fa303090689d06cb4fba227fccc;hpb=2da700a5060b2fbbe59363070515db175a5ce222;p=iot2.git diff --git a/iotjava/iotrmi/C++/basics/TestClass.hpp b/iotjava/iotrmi/C++/basics/TestClass.hpp index 58a6d2a..ca96349 100644 --- a/iotjava/iotrmi/C++/basics/TestClass.hpp +++ b/iotjava/iotrmi/C++/basics/TestClass.hpp @@ -6,6 +6,8 @@ #include #include "TestClassInterface.hpp" #include "CallBackInterfaceWithCallBack.hpp" +#include "Enum.hpp" +#include "Struct.hpp" using namespace std; @@ -40,18 +42,34 @@ class TestClass : public TestClassInterface { // Callbacks void registerCallback(CallBackInterfaceWithCallBack* _cb); - //void registerCallback(vector _cb); + void registerCallbackArray(vector _cb); + void registerCallbackList(vector _cb); + void registerCallbackComplex(int in, vector _cb, double db); int callBack(); + vector handleCallbackEnum(vector en, char c, vector _cb); // Enum Enum handleEnum(Enum en); vector handleEnumArray(vector vecEn); vector handleEnumList(vector vecEn); + Enum handleEnumComplex(Enum en, int i, char c); + vector handleEnumComplex2(vector en, int i, char c); + vector handleEnumTwo(vector en1, vector en2); + vector handleEnumThree(vector en1, vector en2, vector str1, vector str2); // Struct Struct handleStruct(Struct str); vector handleStructArray(vector vecStr); vector handleStructList(vector vecStr); + Struct handleStructComplex(int in, char c, Struct str); + vector handleStructComplex2(int in, char c, vector vecStr); + vector handleStructTwo(vector str1, vector str2); + vector handleStructThree(vector str1, vector str2, vector str3); + + vector handleEnumStruct(vector en, vector str, char c); + vector handleAll(vector en, vector str, char c, vector _cb); + vector handleAllTwo(vector en1, vector en2, vector str1, vector str2, char c, + vector _cb1, vector _cb2); int getA(); void setA(int _int); @@ -87,28 +105,56 @@ TestClass::TestClass(int _int, float _float, string _string) { } -void TestClass::registerCallback(CallBackInterfaceWithCallBack* _cb) { +void TestClass::registerCallbackArray(vector _cb) { - cbvec.push_back(_cb); - cout << "Registering callback object!" << endl; + for (CallBackInterfaceWithCallBack* cb : _cb) { + cbvec.push_back(cb); + cout << "Registering callback object in array!" << endl; + } +} + + +void TestClass::registerCallbackList(vector _cb) { + + for (CallBackInterfaceWithCallBack* cb : _cb) { + cbvec.push_back(cb); + cout << "Registering callback object in list!" << endl; + } } -/*void TestClass::registerCallback(vector _cb) { +void TestClass::registerCallbackComplex(int in, vector _cb, double db) { - for (CallBackInterface* cb : _cb) { + for (CallBackInterfaceWithCallBack* cb : _cb) { cbvec.push_back(cb); - cout << "Registering callback object!" << endl; + cout << "Registering callback object in list!" << endl; } -}*/ + + cout << "Integer: " << in << endl; + cout << "Double: " << db << endl; +} + + +void TestClass::registerCallback(CallBackInterfaceWithCallBack* _cb) { + + cbvec.push_back(_cb); + cout << "Registering callback object!" << endl; +} int TestClass::callBack() { int sum = 0; for (CallBackInterfaceWithCallBack* cb : cbvec) { + //cout << "Sum: " << sum << endl; sum = sum + cb->printInt(); + cb->needCallback(this); + //cb->needCallback(this); + TestClass* tc = new TestClass(); + cb->needCallback(tc); + //cout << "Sum after: " << sum << endl; } + cout << "About to return sum: " << sum << endl; return sum; } @@ -295,6 +341,55 @@ vector TestClass::handleEnumList(vector vecEn) { } +Enum TestClass::handleEnumComplex(Enum en, int i, char c) { + + cout << "Enum: " << en << endl; + cout << "Integer: " << i << endl; + cout << "Char: " << c << endl; + + return en; +} + + +vector TestClass::handleEnumComplex2(vector vecEn, int in, char c) { + + for (Enum en : vecEn) { + cout << "Enum: " << en << endl; + } + cout << "Integer: " << in << endl; + cout << "Char: " << c << endl; + + return vecEn; +} + + +vector TestClass::handleEnumTwo(vector en1, vector en2) { + + for (Enum en : en1) { + cout << "Enum1: " << en << endl; + } + for (Enum en : en2) { + cout << "Enum2: " << en << endl; + } + + return en1; +} + + +vector TestClass::handleEnumThree(vector en1, vector en2, vector str1, vector str2) { + + for (Enum en : en1) { + cout << "Enum1: " << en << endl; + } + for (Enum en : en2) { + cout << "Enum2: " << en << endl; + } + + return en1; +} + + + // Struct Struct TestClass::handleStruct(Struct str) { @@ -348,6 +443,132 @@ vector TestClass::handleStructList(vector vecStr) { } +vector TestClass::handleStructTwo(vector str1, vector str2) { + + for (Struct str : str1) { + + cout << "Name: " << str.name << endl; + cout << "Value: " << str.value << endl; + cout << "Year: " << str.year << endl; + } + + return str2; +} + + +vector TestClass::handleStructThree(vector str1, vector str2, vector str3) { + + for (Struct str : str1) { + + cout << "Name: " << str.name << endl; + cout << "Value: " << str.value << endl; + cout << "Year: " << str.year << endl; + } + + return str2; +} + + +Struct TestClass::handleStructComplex(int in, char c, Struct str) { + + cout << "Name: " << str.name << endl; + cout << "Value: " << str.value << endl; + cout << "Year: " << str.year << endl; + + cout << "Integer: " << in << endl; + cout << "Char: " << c << endl; + + Struct test; + test.name = "Anonymous"; + test.value = 1.33; + test.year = 2016; + str = test; + + return str; +} + + +vector TestClass::handleStructComplex2(int in, char c, vector vecStr) { + + for (Struct str : vecStr) { + cout << "Name: " << str.name << endl; + cout << "Value: " << str.value << endl; + cout << "Year: " << str.year << endl; + } + + cout << "Integer: " << in << endl; + cout << "Char: " << c << endl; + + return vecStr; +} + + +vector TestClass::handleEnumStruct(vector en, vector str, char c) { + + for (Struct st : str) { + cout << "Name: " << st.name << endl; + cout << "Value: " << st.value << endl; + cout << "Year: " << st.year << endl; + } + + cout << "Char: " << c << endl; + + return en; +} + + +vector TestClass::handleAll(vector en, vector str, char c, vector _cb) { + + for (CallBackInterfaceWithCallBack* cb : _cb) { + cbvec.push_back(cb); + cout << "Registering callback object in array!" << endl; + } + + for (Struct st : str) { + cout << "Name: " << st.name << endl; + cout << "Value: " << st.value << endl; + cout << "Year: " << st.year << endl; + } + + cout << "Char: " << c << endl; + + return en; +} + + +vector TestClass::handleAllTwo(vector en1, vector en2, vector str1, vector str2, char c, + vector _cb1, vector _cb2) { + + for (CallBackInterfaceWithCallBack* cb : _cb1) { + cbvec.push_back(cb); + cout << "Registering callback object in array!" << endl; + } + + for (Struct st : str1) { + cout << "Name: " << st.name << endl; + cout << "Value: " << st.value << endl; + cout << "Year: " << st.year << endl; + } + + cout << "Char: " << c << endl; + + return en1; +} + + +vector TestClass::handleCallbackEnum(vector en, char c, vector _cb) { + + for (CallBackInterfaceWithCallBack* cb : _cb) { + cbvec.push_back(cb); + cout << "Registering callback object in array!" << endl; + } + + cout << "Char: " << c << endl; + + return en; +} + + string TestClass::sumArray(vector newA) { string sum = "";