Preparing Lifxtest as a test benchmark; making adjustments in IoTSet for C++, etc.
[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                 unordered_set<T> set;
19         public:
20                 IoTSet();
21                 IoTSet(unordered_set<T> const& 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         //free(&set);
59 }
60
61
62 /**
63  * Find the object k in the set
64  */
65 template <class T>
66 typename unordered_set<T>::const_iterator IoTSet<T>::find(const T& k) {
67
68         return set.find(k);
69 }
70
71
72 /**
73  * Return the "begin" iterator
74  */
75 template <class T>
76 typename unordered_set<T>::const_iterator IoTSet<T>::begin() {
77
78         return set.begin();
79 }
80
81
82 /**
83  * Return the "end" iterator
84  */
85 template <class T>
86 typename unordered_set<T>::const_iterator IoTSet<T>::end() {
87
88         return set.end();
89 }
90
91
92 /**
93  * Return the size of the set
94  */
95 template <class T>
96 int IoTSet<T>::size() {
97
98         return set.size();
99 }
100
101
102 /**
103  * Return a new copy of the set
104  */
105 template <class T>
106 unordered_set<T>* IoTSet<T>::values() {
107
108         return new unordered_set<T>(set);
109 }
110 #endif
111