31 #ifndef GOOGLE_PROTOBUF_MAP_FIELD_INL_H__
32 #define GOOGLE_PROTOBUF_MAP_FIELD_INL_H__
42 #error "You cannot SWIG proto headers"
105 template <
typename Key,
typename T>
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>
127 return InternalGetIterator(&
a) == InternalGetIterator(&
b);
130 template <
typename Key,
typename T>
133 ++InternalGetIterator(map_iter);
134 SetMapIteratorValue(map_iter);
137 template <
typename Key,
typename T>
144 template <
typename Key,
typename T>
151 template <
typename Key,
typename T>
154 InternalGetIterator(this_iter) = InternalGetIterator(&that_iter);
160 SetMapIteratorValue(this_iter);
165 template <
typename Derived,
typename Key,
typename T,
168 int MapField<Derived, Key,
T, kKeyFieldType, kValueFieldType,
171 return static_cast<int>(impl_.GetMap().size());
174 template <
typename Derived,
typename Key,
typename T,
177 void MapField<Derived, Key,
T, kKeyFieldType, kValueFieldType,
183 repeated_field->
Clear();
186 impl_.MutableMap()->clear();
193 template <
typename Derived,
typename Key,
typename T,
196 void MapField<Derived, Key,
T, kKeyFieldType, kValueFieldType,
202 if (iter ==
map.end())
return;
207 template <
typename Derived,
typename Key,
typename T,
210 bool MapField<Derived, Key,
T, kKeyFieldType, kValueFieldType,
211 default_enum_value>::ContainsMapKey(
const MapKey& map_key)
const {
213 const Key&
key = UnwrapMapKey<Key>(map_key);
215 return iter !=
map.end();
218 template <
typename Derived,
typename Key,
typename T,
221 bool MapField<Derived, Key,
T, kKeyFieldType, kValueFieldType,
222 default_enum_value>::InsertOrLookupMapValue(
const MapKey& map_key,
227 const Key&
key = UnwrapMapKey<Key>(map_key);
229 if (
map->end() == iter) {
235 val->SetValue(&(iter->second));
239 template <
typename Derived,
typename Key,
typename T,
242 bool MapField<Derived, Key,
T, kKeyFieldType, kValueFieldType,
243 default_enum_value>::DeleteMapValue(
const MapKey& map_key) {
244 const Key&
key = UnwrapMapKey<Key>(map_key);
245 return MutableMap()->erase(
key);
248 template <
typename Derived,
typename Key,
typename T,
251 void MapField<Derived, Key,
T, kKeyFieldType, kValueFieldType,
255 other_field.SyncMapWithRepeatedField();
260 template <
typename Derived,
typename Key,
typename T,
263 void MapField<Derived, Key,
T, kKeyFieldType, kValueFieldType,
265 MapField* other_field = down_cast<MapField*>(other);
267 impl_.Swap(&other_field->
impl_);
269 auto other_state = other_field->state_.load(std::memory_order_relaxed);
271 other_field->state_.store(this_state, std::memory_order_relaxed);
275 template <
typename Derived,
typename Key,
typename T,
278 void MapField<Derived, Key,
T, kKeyFieldType, kValueFieldType,
279 default_enum_value>::SyncRepeatedFieldWithMapNoLock()
const {
285 Arena::CreateMessage<RepeatedPtrField<Message> >(
294 repeated_field->
Clear();
301 const Message* default_entry = Derived::internal_default_instance();
305 down_cast<EntryType*>(default_entry->
New(this->MapFieldBase::arena_));
307 (*new_entry->mutable_key()) =
it->first;
308 (*new_entry->mutable_value()) =
it->second;
312 template <
typename Derived,
typename Key,
typename T,
315 void MapField<Derived, Key,
T, kKeyFieldType, kValueFieldType,
316 default_enum_value>::SyncMapWithRepeatedFieldNoLock()
const {
335 template <
typename Derived,
typename Key,
typename T,
338 size_t MapField<Derived, Key,
T, kKeyFieldType, kValueFieldType,
339 default_enum_value>::SpaceUsedExcludingSelfNoLock()
const {
345 size +=
sizeof(*map);
348 size += KeyTypeHandler::SpaceUsedInMapLong(
it->first);
349 size += ValueTypeHandler::SpaceUsedInMapLong(
it->second);
357 #endif // GOOGLE_PROTOBUF_MAP_FIELD_INL_H__