15 #include "gu_serialize.hpp"
22 #include "gcomm/types.hpp"
26 template<
typename K,
typename V,
typename C>
33 typedef typename MapType::iterator iterator;
34 typedef typename MapType::const_iterator const_iterator;
35 typedef typename MapType::reverse_iterator reverse_iterator;
36 typedef typename MapType::const_reverse_iterator const_reverse_iterator;
37 typedef typename MapType::value_type value_type;
38 typedef typename MapType::const_reference const_reference;
39 typedef typename MapType::key_type key_type;
40 typedef typename MapType::mapped_type mapped_type;
51 iterator begin() {
return map_.begin(); }
53 iterator end() {
return map_.end(); }
55 iterator find(
const K& k) {
return map_.find(k); }
57 iterator find_checked(
const K& k)
59 iterator ret = map_.find(k);
60 if (ret == map_.end())
62 gu_throw_fatal <<
"element " << k <<
" not found";
67 iterator lower_bound(
const K& k) {
return map_.lower_bound(k); }
69 const_iterator begin()
const {
return map_.begin(); }
71 const_iterator end()
const {
return map_.end(); }
73 const_reverse_iterator rbegin()
const {
return map_.rbegin(); }
75 const_reverse_iterator rend()
const {
return map_.rend(); }
77 const_iterator find(
const K& k)
const {
return map_.find(k); }
79 const_iterator find_checked(
const K& k)
const
81 const_iterator ret = map_.find(k);
82 if (ret == map_.end())
84 gu_throw_fatal <<
"element " << k <<
" not found";
89 mapped_type& operator[](
const key_type& k) {
return map_[k]; }
91 void erase(iterator i) { map_.erase(i); }
93 void erase(iterator i, iterator j) { map_.erase(i, j); }
95 void erase(
const K& k) { map_.erase(k); }
97 void clear() { map_.clear(); }
99 size_t size()
const {
return map_.size(); }
101 bool empty()
const {
return map_.empty(); }
103 size_t serialize(gu::byte_t*
const buf,
107 gu_trace(offset = gu::serialize4(
108 static_cast<uint32_t>(size()), buf, buflen, offset));
109 for (const_iterator i = map_.begin(); i != map_.end(); ++i)
111 gu_trace(offset = key(i).serialize(buf, buflen, offset));
112 gu_trace(offset = value(i).serialize(buf, buflen, offset));
117 size_t unserialize(
const gu::byte_t* buf,
125 gu_trace(offset = gu::unserialize4(buf, buflen, offset, len));;
127 for (uint32_t i = 0; i < len; ++i)
131 gu_trace(offset = k.unserialize(buf, buflen, offset));
132 gu_trace(offset = v.unserialize(buf, buflen, offset));
133 if (map_.insert(std::make_pair(k, v)).second ==
false)
135 gu_throw_fatal <<
"Failed to unserialize map";
141 size_t serial_size()
const
143 return sizeof(uint32_t) + size()*(K::serial_size() + V::serial_size());
146 bool operator==(
const MapBase& other)
const
148 return (map_ == other.map_);
151 bool operator!=(
const MapBase& other)
const
153 return !(map_ == other.map_);
156 static const K& key(const_iterator i)
161 static const K& key(iterator i)
166 static const V& value(const_iterator i)
171 static V& value(iterator i)
176 static const K& key(
const value_type& vt)
181 static V& value(value_type& vt)
186 static const V& value(
const value_type& vt)
194 template <
typename K,
typename V>
195 std::ostream& operator<<(std::ostream& os, const std::pair<K, V>& p)
197 return (os <<
"\t" << p.first <<
"," << p.second <<
"\n");
200 template <
typename K,
typename V,
typename C>
201 std::ostream& operator<<(std::ostream& os, const MapBase<K, V, C>& map)
203 std::copy(map.begin(), map.end(),
204 std::ostream_iterator<const std::pair<const K, V> >(os,
""));
209 template <
typename K,
typename V,
typename C = std::map<K, V> >
213 typedef typename MapBase<K, V, C>::iterator iterator;
214 std::pair<iterator, bool> insert(
const std::pair<K, V>& p)
219 template <
class InputIterator>
220 void insert(InputIterator first, InputIterator last)
225 iterator insert_unique(
const typename MapBase<K, V, C>::value_type& p)
228 if (
false == ret.second)
230 gu_throw_fatal <<
"duplicate entry "
243 template <
typename K,
typename V,
typename C = std::multimap<K, V> >
247 typedef typename MapBase<K, V, C>::iterator iterator;
248 typedef typename MapBase<K, V, C>::const_iterator const_iterator;
249 typedef typename MapBase<K, V, C>::value_type value_type;
250 typedef typename MapBase<K, V, C>::const_reference const_reference;
252 iterator insert(
const std::pair<K, V>& p)
257 iterator insert(iterator position,
const value_type& vt)
262 std::pair<const_iterator, const_iterator> equal_range(
const K& k)
const
GComm exception definitions.