Adding stub and skeleton for Lifxtest and LifxLightBulb; Creating build flow for...
[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 }
62
63
64 /**
65  * Find the object k in the set
66  */
67 template <class K,class V>
68 typename unordered_multimap<K,V>::const_iterator IoTRelation<K,V>::find(const K& k) {
69
70         return rel.find(k);
71 }
72
73
74 /**
75  * Return the "begin" iterator
76  */
77 template <class K,class V>
78 typename unordered_multimap<K,V>::const_iterator IoTRelation<K,V>::begin() {
79
80         return rel.begin();
81 }
82
83
84 /**
85  * Return the "end" iterator
86  */
87 template <class K,class V>
88 typename unordered_multimap<K,V>::const_iterator IoTRelation<K,V>::end() {
89
90         return rel.end();
91 }
92
93
94 /**
95  * Return the "equal_range" iterator
96  */
97 template <class K,class V>
98 std::pair<typename unordered_multimap<K,V>::const_iterator, 
99         typename unordered_multimap<K,V>::const_iterator> 
100         IoTRelation<K,V>::equal_range(const K& k) {
101
102         return rel.equal_range(k);
103 }
104
105
106 /**
107  * Return the size of the set
108  */
109 template <class K,class V>
110 int IoTRelation<K,V>::size() {
111
112         return rel.size();
113 }
114
115
116 /**
117  * Return a new copy of the set
118  */
119 template <class K,class V>
120 unordered_multimap<K,V> IoTRelation<K,V>::values() {
121
122         return new unordered_multimap<K,V>(rel);
123 }
124 #endif
125
126
127
128