OLD | NEW |
1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
2 // Copyright 2014 Google Inc. All rights reserved. | 2 // Copyright 2014 Google Inc. All rights reserved. |
3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
4 // | 4 // |
5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
7 // met: | 7 // met: |
8 // | 8 // |
9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 // we do not need a version of this function taking a non const collection. | 201 // we do not need a version of this function taking a non const collection. |
202 return it->second.get(); | 202 return it->second.get(); |
203 } | 203 } |
204 | 204 |
205 // Same as above, but dies if the key is not found. | 205 // Same as above, but dies if the key is not found. |
206 template <class Collection> | 206 template <class Collection> |
207 typename Collection::value_type::second_type::element_type& | 207 typename Collection::value_type::second_type::element_type& |
208 FindLinkedPtrOrDie(const Collection& collection, | 208 FindLinkedPtrOrDie(const Collection& collection, |
209 const typename Collection::value_type::first_type& key) { | 209 const typename Collection::value_type::first_type& key) { |
210 typename Collection::const_iterator it = collection.find(key); | 210 typename Collection::const_iterator it = collection.find(key); |
211 GOOGLE_CHECK(it != collection.end()) << "key not found: " << key; | 211 CHECK(it != collection.end()) << "key not found: " << key; |
212 // Since linked_ptr::operator*() is a const member returning a non const, | 212 // Since linked_ptr::operator*() is a const member returning a non const, |
213 // we do not need a version of this function taking a non const collection. | 213 // we do not need a version of this function taking a non const collection. |
214 return *it->second; | 214 return *it->second; |
215 } | 215 } |
216 | 216 |
217 // Finds the value associated with the given key and copies it to *value (if not | 217 // Finds the value associated with the given key and copies it to *value (if not |
218 // NULL). Returns false if the key was not found, true otherwise. | 218 // NULL). Returns false if the key was not found, true otherwise. |
219 template <class Collection, class Key, class Value> | 219 template <class Collection, class Key, class Value> |
220 bool FindCopy(const Collection& collection, | 220 bool FindCopy(const Collection& collection, |
221 const Key& key, | 221 const Key& key, |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 const typename Collection::value_type::first_type& key, | 330 const typename Collection::value_type::first_type& key, |
331 const typename Collection::value_type::second_type& value) { | 331 const typename Collection::value_type::second_type& value) { |
332 return InsertIfNotPresent( | 332 return InsertIfNotPresent( |
333 collection, typename Collection::value_type(key, value)); | 333 collection, typename Collection::value_type(key, value)); |
334 } | 334 } |
335 | 335 |
336 // Same as above except dies if the key already exists in the collection. | 336 // Same as above except dies if the key already exists in the collection. |
337 template <class Collection> | 337 template <class Collection> |
338 void InsertOrDie(Collection* const collection, | 338 void InsertOrDie(Collection* const collection, |
339 const typename Collection::value_type& value) { | 339 const typename Collection::value_type& value) { |
340 GOOGLE_CHECK(InsertIfNotPresent(collection, value)) | 340 CHECK(InsertIfNotPresent(collection, value)) << "duplicate value: " << value; |
341 << "duplicate value: " << value; | |
342 } | 341 } |
343 | 342 |
344 // Same as above except doesn't log the value on error. | 343 // Same as above except doesn't log the value on error. |
345 template <class Collection> | 344 template <class Collection> |
346 void InsertOrDieNoPrint(Collection* const collection, | 345 void InsertOrDieNoPrint(Collection* const collection, |
347 const typename Collection::value_type& value) { | 346 const typename Collection::value_type& value) { |
348 GOOGLE_CHECK(InsertIfNotPresent(collection, value)) << "duplicate value."; | 347 CHECK(InsertIfNotPresent(collection, value)) << "duplicate value."; |
349 } | 348 } |
350 | 349 |
351 // Inserts the key-value pair into the collection. Dies if key was already | 350 // Inserts the key-value pair into the collection. Dies if key was already |
352 // present. | 351 // present. |
353 template <class Collection> | 352 template <class Collection> |
354 void InsertOrDie(Collection* const collection, | 353 void InsertOrDie(Collection* const collection, |
355 const typename Collection::value_type::first_type& key, | 354 const typename Collection::value_type::first_type& key, |
356 const typename Collection::value_type::second_type& data) { | 355 const typename Collection::value_type::second_type& data) { |
357 GOOGLE_CHECK(InsertIfNotPresent(collection, key, data)) | 356 GOOGLE_CHECK(InsertIfNotPresent(collection, key, data)) |
358 << "duplicate key: " << key; | 357 << "duplicate key: " << key; |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 for (typename MapContainer::const_iterator it = map_container.begin(); | 760 for (typename MapContainer::const_iterator it = map_container.begin(); |
762 it != map_container.end(); ++it) { | 761 it != map_container.end(); ++it) { |
763 value_container->push_back(it->second); | 762 value_container->push_back(it->second); |
764 } | 763 } |
765 } | 764 } |
766 | 765 |
767 } // namespace protobuf | 766 } // namespace protobuf |
768 } // namespace google | 767 } // namespace google |
769 | 768 |
770 #endif // GOOGLE_PROTOBUF_STUBS_MAP_UTIL_H__ | 769 #endif // GOOGLE_PROTOBUF_STUBS_MAP_UTIL_H__ |
OLD | NEW |