Making C++ classes final
[iot2.git] / iotjava / iotruntime / cpp / setrelation / ISet.hpp
1 #ifndef _ISET_HPP__
2 #define _ISET_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 ISet final {
17         private:
18                 unordered_set<T>* set;
19         public:
20                 ISet();
21                 ISet(unordered_set<T> const* s);
22                 ~ISet();
23         public:
24                 typename unordered_set<T>::const_iterator find(const T& k);             // Find the object
25                 typename unordered_set<T>::const_iterator insert(const T& k);   // Insert the object
26                 bool empty();                                                                                                   // Test is empty?
27                 typename unordered_set<T>::const_iterator begin();                              // Iterator
28                 typename unordered_set<T>::const_iterator end();                                // Iterator
29                 int size();                                                                                                             // Set size
30                 unordered_set<T>* values();                                                                             // Return set contents
31 };
32
33
34 /**
35  * Default constructor
36  */
37 template <class T>
38 ISet<T>::ISet() {
39
40         set = new unordered_set<T>();
41 }
42
43
44 /**
45  * Useful constructor
46  */
47 template <class T>
48 ISet<T>::ISet(const unordered_set<T>* s) {
49
50         set = s;
51 }
52
53
54 /**
55  * Default destructor
56  */
57 template <class T>
58 ISet<T>::~ISet() {
59
60         if (set != NULL)
61                 delete set;
62 }
63
64
65 /**
66  * Find the object k in the set
67  */
68 template <class T>
69 typename unordered_set<T>::const_iterator ISet<T>::find(const T& k) {
70
71         return set->find(k);
72 }
73
74
75 /**
76  * Insert object k into the set
77  */
78 template <class T>
79 typename unordered_set<T>::const_iterator ISet<T>::insert(const T& k) {
80
81         return set->insert(k);
82 }
83
84
85 /**
86  * Return the "begin" iterator
87  */
88 template <class T>
89 typename unordered_set<T>::const_iterator ISet<T>::begin() {
90
91         return set->begin();
92 }
93
94
95 /**
96  * Return the "end" iterator
97  */
98 template <class T>
99 typename unordered_set<T>::const_iterator ISet<T>::end() {
100
101         return set->end();
102 }
103
104
105 /**
106  * Return the size of the set
107  */
108 template <class T>
109 int ISet<T>::size() {
110
111         return set->size();
112 }
113
114
115 /**
116  * Return a new copy of the set
117  */
118 template <class T>
119 unordered_set<T>* ISet<T>::values() {
120
121         return set;
122 }
123 #endif
124