36 |
|
|
37 |
|
#include <map> |
38 |
|
#include <vector> |
39 |
+ |
|
40 |
+ |
#include "utils/Utility.hpp" |
41 |
+ |
|
42 |
|
namespace oopse { |
43 |
|
|
44 |
|
/** |
55 |
|
typedef std::map<KeyType, ValueType> MapType; |
56 |
|
typedef std::map<KeyType, ValueType>::iterator MapTypeIterator; |
57 |
|
|
58 |
< |
TypeContainer() index_(0) {} |
58 |
> |
TypeContainer() : index_(0) {} |
59 |
|
|
60 |
|
~TypeContainer() { |
61 |
|
MapTypeIterator i; |
67 |
|
|
68 |
|
bool add(KeyType& keys, ElemPtr elem) { |
69 |
|
assert(keys.size() == SIZE); |
70 |
< |
return data_.insert(MapType::value_type(keys, make_pair(index_++,elem))).second; |
70 |
> |
assert(elem); |
71 |
> |
return data_.insert(MapType::value_type(keys, std::make_pair(index_++,elem))).second; |
72 |
|
} |
73 |
|
|
74 |
|
/** Exact Match */ |
79 |
|
|
80 |
|
i = data_.find(keys); |
81 |
|
if (i != data_.end()) { |
82 |
< |
return (i->second).second |
82 |
> |
return (i->second).second; |
83 |
|
} |
84 |
|
|
85 |
|
KeyType reversedKeys = keys; |
86 |
|
std::reverse(reversedKeys.begin(), reversedKeys.end()); |
87 |
|
|
88 |
< |
i = data_.find(keys); |
88 |
> |
i = data_.find(reversedKeys); |
89 |
|
if (i != data_.end()) { |
90 |
< |
return (i->second).second |
90 |
> |
return (i->second).second; |
91 |
|
} else { |
92 |
|
return NULL; |
93 |
|
} |
105 |
|
MapTypeIterator i; |
106 |
|
std::vector<ValueType> foundTypes; |
107 |
|
|
108 |
< |
while (replaceWithWildCard(iterCont, keys, replacedKey, wildCard)) { |
108 |
> |
while (replaceWithWildCard(iterCont, keys, replacedKey, wildCard)) { |
109 |
|
i = data_.find(replacedKey); |
110 |
|
if (i != data_.end()) { |
111 |
|
foundTypes.push_back(i->second); |
117 |
|
std::reverse(reversedKeys.begin(), reversedKeys.end()); |
118 |
|
|
119 |
|
//if the reversedKeys is the same as keys, just skip it |
120 |
< |
if (reversedKeys == keys) { |
120 |
> |
if (reversedKeys != keys) { |
121 |
|
|
122 |
|
|
123 |
|
//empty the iterator container |
124 |
|
iterCont.clear(); |
125 |
|
|
126 |
< |
while (replaceWithWildCard(iterCont, keys, replacedKey, wildCard)) { |
126 |
> |
while (replaceWithWildCard(iterCont, reversedKeys, replacedKey, wildCard)) { |
127 |
|
i = data_.find(replacedKey); |
128 |
|
if (i != data_.end()) { |
129 |
|
foundTypes.push_back(i->second); |
143 |
|
std::vector<ValueType>::iterator j; |
144 |
|
j = std::min_element(foundTypes.begin(), foundTypes.end()); |
145 |
|
|
146 |
< |
return j == foundTypes.end() ? NULL : (j->second).second; |
146 |
> |
return j == foundTypes.end() ? NULL : j->second; |
147 |
|
} |
148 |
|
|
149 |
|
unsigned int size() { |
152 |
|
|
153 |
|
ElemPtr beginType(MapTypeIterator& i) { |
154 |
|
i = data_.begin(); |
155 |
< |
i != data_.end() ? i->(i->second).second : NULL; |
152 |
< |
|
155 |
> |
return i != data_.end() ? (i->second).second : NULL; |
156 |
|
} |
157 |
|
|
158 |
|
ElemPtr nextType(MapTypeIterator& i) { |
159 |
|
++i; |
160 |
< |
i != data_.end() ? i->(i->second).second : NULL; |
160 |
> |
return i != data_.end() ? (i->second).second : NULL; |
161 |
|
} |
162 |
|
|
163 |
|
private: |