From: rtrimana Date: Mon, 13 Feb 2017 16:36:32 +0000 (-0800) Subject: Making sure that C++ Set and Relation methods return pointers from a new set/map... X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=7490661d4de271a8aba6a68847066691ab30abe3;p=iot2.git Making sure that C++ Set and Relation methods return pointers from a new set/map every time the method is called; this keeps the original set/map intact/immutable. --- diff --git a/common.mk b/common.mk index fdf6b88..e5fcbb8 100644 --- a/common.mk +++ b/common.mk @@ -1,5 +1,6 @@ G++ := g++ ARM_G++ := arm-linux-gnueabihf-g++ +#ARM_G++ := arm-linux-gnueabi-g++ JAVA := java JAR := jar JAVADOC := javadoc diff --git a/iotjava/iotruntime/cpp/iotslave/Makefile b/iotjava/iotruntime/cpp/iotslave/Makefile index 4157921..1d73cca 100755 --- a/iotjava/iotruntime/cpp/iotslave/Makefile +++ b/iotjava/iotruntime/cpp/iotslave/Makefile @@ -22,6 +22,10 @@ cpp-arm: $(ARM_G++) $(GCCFLAGS) -o IoTSlave.o IoTSlave.cpp $(INCLUDE) $(CCCLINKERFLAGS) cp IoTSlave.o $(BASE)/bin/iotruntime/slave/ +PHONY += cpp-test +cpp-test: + $(G++) $(GCCFLAGS) -o SetRelationTest.o SetRelationTest.cpp $(INCLUDE) $(CCCLINKERFLAGS) + PHONY += run run: java IoTSlave diff --git a/iotjava/iotruntime/cpp/iotslave/SetRelationTest.cpp b/iotjava/iotruntime/cpp/iotslave/SetRelationTest.cpp new file mode 100644 index 0000000..36769a5 --- /dev/null +++ b/iotjava/iotruntime/cpp/iotslave/SetRelationTest.cpp @@ -0,0 +1,48 @@ +#include +#include "IoTSet.hpp" +#include "IoTRelation.hpp" + +using namespace std; + +int main () +{ + unordered_set myset = { "red","green","blue" }; + + IoTSet iotset(&myset); + + unordered_set::const_iterator got = iotset.find ("red"); + + if ( got == iotset.end() ) + cout << "not found in myset" << endl; + else + cout << *got << " is in myset" << endl; + + cout << "size: " << iotset.size() << endl; + + unordered_multimap mymap = { + {"mom","church"}, + {"mom","college"}, + {"dad","office"}, + {"bro","school"} }; + + unordered_set* retset = iotset.values(); + cout << "Returned set: " << retset->size() << endl; + retset->erase("red"); + cout << "Returned set: " << retset->size() << endl; + cout << "Original set: " << myset.size() << endl; + + //cout << "one of the values for 'mom' is: "; + //cout << mymap.find("mom")->second; + //cout << endl; + IoTRelation iotrel(&mymap); + + std::pair::const_iterator, + unordered_multimap::const_iterator> ret; + ret = iotrel.equal_range("mom"); + for (std::unordered_multimap::const_iterator it=ret.first; it!=ret.second; ++it) + cout << ' ' << it->second << endl; + + cout << "size: " << iotrel.size() << endl; + + return 0; +} diff --git a/iotjava/iotruntime/cpp/setrelation/IoTRelation.hpp b/iotjava/iotruntime/cpp/setrelation/IoTRelation.hpp index 372f695..ad1f8bf 100644 --- a/iotjava/iotruntime/cpp/setrelation/IoTRelation.hpp +++ b/iotjava/iotruntime/cpp/setrelation/IoTRelation.hpp @@ -69,7 +69,7 @@ IoTRelation::~IoTRelation() { template typename unordered_multimap::const_iterator IoTRelation::find(const K& k) { - return rel->find(k); + return (new unordered_multimap(*rel))->find(k); } @@ -79,7 +79,7 @@ typename unordered_multimap::const_iterator IoTRelation::find(const K& template typename unordered_multimap::const_iterator IoTRelation::begin() { - return rel->begin(); + return (new unordered_multimap(*rel))->begin(); } @@ -89,7 +89,7 @@ typename unordered_multimap::const_iterator IoTRelation::begin() { template typename unordered_multimap::const_iterator IoTRelation::end() { - return rel->end(); + return (new unordered_multimap(*rel))->end(); } @@ -101,7 +101,7 @@ std::pair::const_iterator, typename unordered_multimap::const_iterator> IoTRelation::equal_range(const K& k) { - return rel->equal_range(k); + return (new unordered_multimap(*rel))->equal_range(k); } diff --git a/iotjava/iotruntime/cpp/setrelation/IoTSet.hpp b/iotjava/iotruntime/cpp/setrelation/IoTSet.hpp index 60f34f7..0c45ca8 100644 --- a/iotjava/iotruntime/cpp/setrelation/IoTSet.hpp +++ b/iotjava/iotruntime/cpp/setrelation/IoTSet.hpp @@ -64,7 +64,7 @@ IoTSet::~IoTSet() { template typename unordered_set::const_iterator IoTSet::find(const T& k) { - return set->find(k); + return (new unordered_set(*set))->find(k); } @@ -74,7 +74,7 @@ typename unordered_set::const_iterator IoTSet::find(const T& k) { template typename unordered_set::const_iterator IoTSet::begin() { - return set->begin(); + return (new unordered_set(*set))->begin(); } @@ -84,7 +84,7 @@ typename unordered_set::const_iterator IoTSet::begin() { template typename unordered_set::const_iterator IoTSet::end() { - return set->end(); + return (new unordered_set(*set))->end(); }