31 #ifndef GOOGLE_PROTOBUF_MAP_FIELD_INL_H__
32 #define GOOGLE_PROTOBUF_MAP_FIELD_INL_H__
36 #include <google/protobuf/stubs/casts.h>
37 #include <google/protobuf/map.h>
38 #include <google/protobuf/map_field.h>
39 #include <google/protobuf/map_type_handler.h>
42 #error "You cannot SWIG proto headers"
72 inline std::string UnwrapMapKey<std::string>(
const MapKey& map_key) {
73 return map_key.GetStringValue();
100 inline void SetMapKey<std::string>(MapKey* map_key,
const std::string&
value) {
101 map_key->SetStringValue(
value);
105 template <
typename Key,
typename T>
108 const MapIterator* map_iter)
const {
113 template <
typename Key,
typename T>
115 InternalGetIterator(map_iter) =
GetMap().begin();
116 SetMapIteratorValue(map_iter);
119 template <
typename Key,
typename T>
121 InternalGetIterator(map_iter) =
GetMap().end();
124 template <
typename Key,
typename T>
126 const MapIterator& a,
const MapIterator&
b)
const {
127 return InternalGetIterator(&a) == InternalGetIterator(&
b);
130 template <
typename Key,
typename T>
132 MapIterator* map_iter)
const {
133 ++InternalGetIterator(map_iter);
134 SetMapIteratorValue(map_iter);
137 template <
typename Key,
typename T>
139 MapIterator* map_iter)
const {
144 template <
typename Key,
typename T>
146 MapIterator* map_iter)
const {
151 template <
typename Key,
typename T>
153 MapIterator* this_iter,
const MapIterator& that_iter)
const {
154 InternalGetIterator(this_iter) = InternalGetIterator(&that_iter);
155 this_iter->key_.SetType(that_iter.key_.type());
158 this_iter->value_.SetType(
160 SetMapIteratorValue(this_iter);
165 template <
typename Derived,
typename Key,
typename T,
170 return static_cast<int>(
impl_.GetMap().size());
173 template <
typename Derived,
typename Key,
typename T,
179 reinterpret_cast<RepeatedPtrField<EntryType>*
>(
181 repeated_field->Clear();
184 impl_.MutableMap()->clear();
191 template <
typename Derived,
typename Key,
typename T,
195 kValueFieldType>::SetMapIteratorValue(MapIterator* map_iter)
202 map_iter->value_.SetValue(&
iter->second);
205 template <
typename Derived,
typename Key,
typename T,
209 const MapKey& map_key)
const {
211 const Key&
key = UnwrapMapKey<Key>(map_key);
216 template <
typename Derived,
typename Key,
typename T,
220 kValueFieldType>::InsertOrLookupMapValue(
const MapKey& map_key,
225 const Key&
key = UnwrapMapKey<Key>(map_key);
228 val->SetValue(&((*
map)[
key]));
233 val->SetValue(&(
iter->second));
237 template <
typename Derived,
typename Key,
typename T,
243 const Key&
key = UnwrapMapKey<Key>(map_key);
254 template <
typename Derived,
typename Key,
typename T,
259 const Key&
key = UnwrapMapKey<Key>(map_key);
260 return MutableMap()->erase(
key);
263 template <
typename Derived,
typename Key,
typename T,
267 const MapFieldBase& other) {
270 other_field.SyncMapWithRepeatedField();
275 template <
typename Derived,
typename Key,
typename T,
279 MapFieldBase* other) {
281 MapField* other_field = down_cast<MapField*>(other);
282 impl_.Swap(&other_field->impl_);
285 template <
typename Derived,
typename Key,
typename T,
290 InternalSwap(down_cast<MapField*>(other));
293 template <
typename Derived,
typename Key,
typename T,
302 template <
typename Derived,
typename Key,
typename T,
306 kValueFieldType>::SyncRepeatedFieldWithMapNoLock()
const {
309 Arena::CreateMessage<RepeatedPtrField<Message> >(
317 repeated_field->
Clear();
324 const Message* default_entry = Derived::internal_default_instance();
327 EntryType* new_entry =
328 down_cast<EntryType*>(default_entry->
New(this->MapFieldBase::arena_));
330 (*new_entry->mutable_key()) =
it->first;
331 (*new_entry->mutable_value()) =
it->second;
335 template <
typename Derived,
typename Key,
typename T,
339 kValueFieldType>::SyncMapWithRepeatedFieldNoLock()
const {
342 reinterpret_cast<RepeatedPtrField<EntryType>*
>(
354 (*map)[
it->key()] =
static_cast<CastValueType
>(
it->value());
358 template <
typename Derived,
typename Key,
typename T,
362 kValueFieldType>::SpaceUsedExcludingSelfNoLock()
const {
367 size +=
impl_.GetMap().SpaceUsedExcludingSelfLong();
375 #endif // GOOGLE_PROTOBUF_MAP_FIELD_INL_H__