Adding config file for sharing.
[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 final {
17         private:
18                 const unordered_multimap<K,V>* rel;
19         public:
20                 IoTRelation();
21                 //IoTRelation(unordered_multimap<K,V> const& s);
22                 IoTRelation(const unordered_multimap<K,V>* s);
23                 ~IoTRelation();
24         public:
25                 typename unordered_multimap<K,V>::const_iterator find(const K& k);      // Find the object based on key
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 IoTRelation<K,V>::IoTRelation() {
42
43 }
44
45
46 /**
47  * Useful constructor
48  */
49 template <class K,class V>
50 //IoTRelation<K,V>::IoTRelation(const unordered_multimap<K,V>& r) {
51 IoTRelation<K,V>::IoTRelation(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 IoTRelation<K,V>::~IoTRelation() {
62
63 }
64
65
66 /**
67  * Find the object k in the set
68  */
69 template <class K,class V>
70 typename unordered_multimap<K,V>::const_iterator IoTRelation<K,V>::find(const K& k) {
71
72         return (new unordered_multimap<K,V>(*rel))->find(k);
73 }
74
75
76 /**
77  * Return the "begin" iterator
78  */
79 template <class K,class V>
80 typename unordered_multimap<K,V>::const_iterator IoTRelation<K,V>::begin() {
81
82         return (new unordered_multimap<K,V>(*rel))->begin();
83 }
84
85
86 /**
87  * Return the "end" iterator
88  */
89 template <class K,class V>
90 typename unordered_multimap<K,V>::const_iterator IoTRelation<K,V>::end() {
91
92         return (new unordered_multimap<K,V>(*rel))->end();
93 }
94
95
96 /**
97  * Return the "equal_range" iterator
98  */
99 template <class K,class V>
100 std::pair<typename unordered_multimap<K,V>::const_iterator, 
101         typename unordered_multimap<K,V>::const_iterator> 
102         IoTRelation<K,V>::equal_range(const K& k) {
103
104         return (new unordered_multimap<K,V>(*rel))->equal_range(k);
105 }
106
107
108 /**
109  * Return the size of the set
110  */
111 template <class K,class V>
112 int IoTRelation<K,V>::size() {
113
114         return rel->size();
115 }
116
117
118 /**
119  * Return a new copy of the set
120  */
121 template <class K,class V>
122 unordered_multimap<K,V>* IoTRelation<K,V>::values() {
123
124         return new unordered_multimap<K,V>(*rel);
125 }
126 #endif
127
128
129
130