Making sure that C++ Set and Relation methods return pointers from a new set/map...
authorrtrimana <rtrimana@uci.edu>
Mon, 13 Feb 2017 16:36:32 +0000 (08:36 -0800)
committerrtrimana <rtrimana@uci.edu>
Mon, 13 Feb 2017 16:36:32 +0000 (08:36 -0800)
common.mk
iotjava/iotruntime/cpp/iotslave/Makefile
iotjava/iotruntime/cpp/iotslave/SetRelationTest.cpp [new file with mode: 0644]
iotjava/iotruntime/cpp/setrelation/IoTRelation.hpp
iotjava/iotruntime/cpp/setrelation/IoTSet.hpp

index fdf6b88..e5fcbb8 100644 (file)
--- 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
index 4157921..1d73cca 100755 (executable)
@@ -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 (file)
index 0000000..36769a5
--- /dev/null
@@ -0,0 +1,48 @@
+#include <iostream>
+#include "IoTSet.hpp"
+#include "IoTRelation.hpp"
+
+using namespace std;
+
+int main ()
+{
+       unordered_set<string> myset = { "red","green","blue" };
+
+       IoTSet<string> iotset(&myset);
+
+       unordered_set<string>::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<string,string> mymap = {
+               {"mom","church"},
+               {"mom","college"},
+               {"dad","office"},
+               {"bro","school"} };
+
+       unordered_set<string>* 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<string,string> iotrel(&mymap);
+
+       std::pair<unordered_multimap<string,string>::const_iterator, 
+               unordered_multimap<string,string>::const_iterator> ret;
+       ret = iotrel.equal_range("mom");
+       for (std::unordered_multimap<string,string>::const_iterator it=ret.first; it!=ret.second; ++it)
+               cout << ' ' << it->second << endl;
+
+       cout << "size: " << iotrel.size() << endl;
+
+       return 0;
+}
index 372f695..ad1f8bf 100644 (file)
@@ -69,7 +69,7 @@ IoTRelation<K,V>::~IoTRelation() {
 template <class K,class V>
 typename unordered_multimap<K,V>::const_iterator IoTRelation<K,V>::find(const K& k) {
 
-       return rel->find(k);
+       return (new unordered_multimap<K,V>(*rel))->find(k);
 }
 
 
@@ -79,7 +79,7 @@ typename unordered_multimap<K,V>::const_iterator IoTRelation<K,V>::find(const K&
 template <class K,class V>
 typename unordered_multimap<K,V>::const_iterator IoTRelation<K,V>::begin() {
 
-       return rel->begin();
+       return (new unordered_multimap<K,V>(*rel))->begin();
 }
 
 
@@ -89,7 +89,7 @@ typename unordered_multimap<K,V>::const_iterator IoTRelation<K,V>::begin() {
 template <class K,class V>
 typename unordered_multimap<K,V>::const_iterator IoTRelation<K,V>::end() {
 
-       return rel->end();
+       return (new unordered_multimap<K,V>(*rel))->end();
 }
 
 
@@ -101,7 +101,7 @@ std::pair<typename unordered_multimap<K,V>::const_iterator,
        typename unordered_multimap<K,V>::const_iterator> 
        IoTRelation<K,V>::equal_range(const K& k) {
 
-       return rel->equal_range(k);
+       return (new unordered_multimap<K,V>(*rel))->equal_range(k);
 }
 
 
index 60f34f7..0c45ca8 100644 (file)
@@ -64,7 +64,7 @@ IoTSet<T>::~IoTSet() {
 template <class T>
 typename unordered_set<T>::const_iterator IoTSet<T>::find(const T& k) {
 
-       return set->find(k);
+       return (new unordered_set<T>(*set))->find(k);
 }
 
 
@@ -74,7 +74,7 @@ typename unordered_set<T>::const_iterator IoTSet<T>::find(const T& k) {
 template <class T>
 typename unordered_set<T>::const_iterator IoTSet<T>::begin() {
 
-       return set->begin();
+       return (new unordered_set<T>(*set))->begin();
 }
 
 
@@ -84,7 +84,7 @@ typename unordered_set<T>::const_iterator IoTSet<T>::begin() {
 template <class T>
 typename unordered_set<T>::const_iterator IoTSet<T>::end() {
 
-       return set->end();
+       return (new unordered_set<T>(*set))->end();
 }