Making sure that C++ Set and Relation methods return pointers from a new set/map...
[iot2.git] / iotjava / iotruntime / cpp / setrelation / IoTSet.hpp
1 #ifndef _IOTSET_HPP__
2 #define _IOTSET_HPP__
3 #include <iostream>
4 #include <string>
5 #include <unordered_set>
6
7 using namespace std;
8
9 /** This is the IoTSet implementation for C++
10  *
11  * @author      Rahmadi Trimananda <rahmadi.trimananda @ uci.edu>
12  * @version     1.0
13  * @since       2016-09-06
14  */
15 template <class T>
16 class IoTSet {
17         private:
18                 const unordered_set<T>* set;
19         public:
20                 IoTSet();
21                 IoTSet(const unordered_set<T>* s);
22                 ~IoTSet();
23         public:
24                 typename unordered_set<T>::const_iterator find(const T& k);     // Find the object
25                 bool empty();                                                                                           // Test is empty?
26                 typename unordered_set<T>::const_iterator begin();                      // Iterator
27                 typename unordered_set<T>::const_iterator end();                        // Iterator
28                 int size();                                                                                                     // Set size
29                 unordered_set<T>* values();                                                                     // Return set contents
30 };
31
32
33 /**
34  * Default constructor
35  */
36 template <class T>
37 IoTSet<T>::IoTSet() {
38
39 }
40
41
42 /**
43  * Useful constructor
44  */
45 template <class T>
46 IoTSet<T>::IoTSet(const unordered_set<T>* s) {
47
48         set = s;
49 }
50
51
52 /**
53  * Default destructor
54  */
55 template <class T>
56 IoTSet<T>::~IoTSet() {
57
58 }
59
60
61 /**
62  * Find the object k in the set
63  */
64 template <class T>
65 typename unordered_set<T>::const_iterator IoTSet<T>::find(const T& k) {
66
67         return (new unordered_set<T>(*set))->find(k);
68 }
69
70
71 /**
72  * Return the "begin" iterator
73  */
74 template <class T>
75 typename unordered_set<T>::const_iterator IoTSet<T>::begin() {
76
77         return (new unordered_set<T>(*set))->begin();
78 }
79
80
81 /**
82  * Return the "end" iterator
83  */
84 template <class T>
85 typename unordered_set<T>::const_iterator IoTSet<T>::end() {
86
87         return (new unordered_set<T>(*set))->end();
88 }
89
90
91 /**
92  * Return the size of the set
93  */
94 template <class T>
95 int IoTSet<T>::size() {
96
97         return set->size();
98 }
99
100
101 /**
102  * Return a new copy of the set
103  */
104 template <class T>
105 unordered_set<T>* IoTSet<T>::values() {
106
107         return new unordered_set<T>(*set);
108 }
109 #endif
110