Making C++ classes final
[iot2.git] / iotjava / iotruntime / cpp / setrelation / IRelation.hpp
1 #ifndef _IRELATION_HPP__
2 #define _IRELATION_HPP__
3 #include <iostream>
4 #include <string>
5 #include <unordered_map>
6
7 using namespace std;
8
9 /** This is the IoTRelation 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 K,class V>
16 class IRelation final {
17         private:
18                 unordered_multimap<K,V>* rel;
19         public:
20                 IRelation();
21                 IRelation(unordered_multimap<K,V> const* r);
22                 ~IRelation();
23         public:
24                 typename unordered_multimap<K,V>::const_iterator find(const K& k);                              // Find the object based on key
25                 typename unordered_multimap<K,V>::const_iterator insert(const pair<K,V>& val);  // Insert the object pair
26                 bool empty();                                                                                                                                   // Test is empty?
27                 typename unordered_multimap<K,V>::const_iterator begin();                                               // Iterator
28                 typename unordered_multimap<K,V>::const_iterator end();                                                 // Iterator
29                 std::pair<typename unordered_multimap<K,V>::const_iterator, 
30                         typename unordered_multimap<K,V>::const_iterator> 
31                         equal_range(const K& k);                                                                                                        // Equal range iterator
32                 int size();                                                                                                                                             // Set size
33                 unordered_multimap<K,V> values();                                                                                               // Return set contents
34 };
35
36
37 /**
38  * Default constructor
39  */
40 template <class K,class V>
41 IRelation<K,V>::IRelation() {
42
43         rel = new unordered_multimap<K,V>();
44 }
45
46
47 /**
48  * Useful constructor
49  */
50 template <class K,class V>
51 IRelation<K,V>::IRelation(const unordered_multimap<K,V>* r) {
52
53         rel = r;
54 }
55
56
57 /**
58  * Default destructor
59  */
60 template <class K,class V>
61 IRelation<K,V>::~IRelation() {
62
63         if (rel != NULL)
64                 delete rel;
65 }
66
67
68 /**
69  * Find the object k in the set
70  */
71 template <class K,class V>
72 typename unordered_multimap<K,V>::const_iterator IRelation<K,V>::find(const K& k) {
73
74         return rel->find(k);
75 }
76
77
78 /**
79  * Insert object k into the set
80  */
81 template <class K,class V>
82 typename unordered_multimap<K,V>::const_iterator IRelation<K,V>::insert(const pair<K,V>& val) {
83
84         return rel->insert(val);
85 }
86
87
88 /**
89  * Return the "begin" iterator
90  */
91 template <class K,class V>
92 typename unordered_multimap<K,V>::const_iterator IRelation<K,V>::begin() {
93
94         return rel->begin();
95 }
96
97
98 /**
99  * Return the "end" iterator
100  */
101 template <class K,class V>
102 typename unordered_multimap<K,V>::const_iterator IRelation<K,V>::end() {
103
104         return rel->end();
105 }
106
107
108 /**
109  * Return the "equal_range" iterator
110  */
111 template <class K,class V>
112 std::pair<typename unordered_multimap<K,V>::const_iterator, 
113         typename unordered_multimap<K,V>::const_iterator> 
114         IRelation<K,V>::equal_range(const K& k) {
115
116         return rel->equal_range(k);
117 }
118
119
120 /**
121  * Return the size of the set
122  */
123 template <class K,class V>
124 int IRelation<K,V>::size() {
125
126         return rel->size();
127 }
128
129
130 /**
131  * Return a new copy of the set
132  */
133 template <class K,class V>
134 unordered_multimap<K,V> IRelation<K,V>::values() {
135
136         return rel;
137 }
138 #endif
139
140
141
142