Moving Java drivers; Creating iotruntime socket connections for C++; First version...
[iot2.git] / iotjava / iotruntime / cpp / setrelation / IoTRelation.hpp
1 #ifndef _IOTRELATION_HPP__
2 #define _IOTRELATION_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 IoTRelation {
17         private:
18                 unordered_multimap<K,V> rel;
19         public:
20                 IoTRelation();
21                 IoTRelation(unordered_multimap<K,V> const& s);
22                 ~IoTRelation();
23         public:
24                 typename unordered_multimap<K,V>::const_iterator find(const K& k);      // Find the object based on key
25                 bool empty();                                                                                                           // Test is empty?
26                 typename unordered_multimap<K,V>::const_iterator begin();                       // Iterator
27                 typename unordered_multimap<K,V>::const_iterator end();                         // Iterator
28                 std::pair<typename unordered_multimap<K,V>::const_iterator, 
29                         typename unordered_multimap<K,V>::const_iterator> 
30                         equal_range(const K& k);                                                                                // Equal range iterator
31                 int size();                                                                                                                     // Set size
32                 unordered_multimap<K,V> values();                                                                       // Return set contents
33 };
34
35
36 /**
37  * Default constructor
38  */
39 template <class K,class V>
40 IoTRelation<K,V>::IoTRelation() {
41
42 }
43
44
45 /**
46  * Useful constructor
47  */
48 template <class K,class V>
49 IoTRelation<K,V>::IoTRelation(const unordered_multimap<K,V>& r) {
50
51         rel = r;
52 }
53
54
55 /**
56  * Default destructor
57  */
58 template <class K,class V>
59 IoTRelation<K,V>::~IoTRelation() {
60
61         //free(&set);
62 }
63
64
65 /**
66  * Find the object k in the set
67  */
68 template <class K,class V>
69 typename unordered_multimap<K,V>::const_iterator IoTRelation<K,V>::find(const K& k) {
70
71         return rel.find(k);
72 }
73
74
75 /**
76  * Return the "begin" iterator
77  */
78 template <class K,class V>
79 typename unordered_multimap<K,V>::const_iterator IoTRelation<K,V>::begin() {
80
81         return rel.begin();
82 }
83
84
85 /**
86  * Return the "end" iterator
87  */
88 template <class K,class V>
89 typename unordered_multimap<K,V>::const_iterator IoTRelation<K,V>::end() {
90
91         return rel.end();
92 }
93
94
95 /**
96  * Return the "equal_range" iterator
97  */
98 template <class K,class V>
99 std::pair<typename unordered_multimap<K,V>::const_iterator, 
100         typename unordered_multimap<K,V>::const_iterator> 
101         IoTRelation<K,V>::equal_range(const K& k) {
102
103         return rel.equal_range(k);
104 }
105
106
107 /**
108  * Return the size of the set
109  */
110 template <class K,class V>
111 int IoTRelation<K,V>::size() {
112
113         return rel.size();
114 }
115
116
117 /**
118  * Return a new copy of the set
119  */
120 template <class K,class V>
121 unordered_multimap<K,V> IoTRelation<K,V>::values() {
122
123         return new unordered_multimap<K,V>(rel);
124 }
125 #endif
126
127
128
129