34 #ifndef GOOGLE_PROTOBUF_STUBS_MAP_UTIL_H__
35 #define GOOGLE_PROTOBUF_STUBS_MAP_UTIL_H__
72 template <
class Collection>
73 const typename Collection::value_type::second_type&
75 const typename Collection::value_type::first_type& key) {
76 typename Collection::const_iterator it = collection.find(key);
77 GOOGLE_CHECK(it != collection.end()) <<
"Map key not found: " << key;
82 template <
class Collection>
83 typename Collection::value_type::second_type&
85 const typename Collection::value_type::first_type& key) {
86 typename Collection::iterator it = collection.find(key);
87 GOOGLE_CHECK(it != collection.end()) <<
"Map key not found: " << key;
92 template <
class Collection>
93 const typename Collection::value_type::second_type&
95 const typename Collection::value_type::first_type& key) {
96 typename Collection::const_iterator it = collection.find(key);
97 GOOGLE_CHECK(it != collection.end()) <<
"Map key not found";
102 template <
class Collection>
103 typename Collection::value_type::second_type&
105 const typename Collection::value_type::first_type& key) {
106 typename Collection::iterator it = collection.find(key);
107 GOOGLE_CHECK(it != collection.end()) <<
"Map key not found";
121 template <
class Collection>
122 const typename Collection::value_type::second_type&
124 const typename Collection::value_type::first_type& key,
125 const typename Collection::value_type::second_type&
value) {
126 typename Collection::const_iterator it = collection.find(key);
127 if (it == collection.end()) {
135 template <
class Collection>
136 const typename Collection::value_type::second_type*
138 const typename Collection::value_type::first_type& key) {
139 typename Collection::const_iterator it = collection.find(key);
140 if (it == collection.end()) {
147 template <
class Collection>
148 typename Collection::value_type::second_type*
150 const typename Collection::value_type::first_type& key) {
151 typename Collection::iterator it = collection.find(key);
152 if (it == collection.end()) {
164 template <
class Collection>
165 typename Collection::value_type::second_type
167 const typename Collection::value_type::first_type& key) {
168 typename Collection::const_iterator it = collection.find(key);
169 if (it == collection.end()) {
170 return typename Collection::value_type::second_type();
179 template <
class Collection>
180 typename Collection::value_type::second_type
182 const typename Collection::value_type::first_type& key) {
183 typename Collection::iterator it = collection.find(key);
184 if (it == collection.end()) {
185 return typename Collection::value_type::second_type();
192 template <
class Collection>
193 typename Collection::value_type::second_type::element_type*
195 const typename Collection::value_type::first_type& key) {
196 typename Collection::const_iterator it = collection.find(key);
197 if (it == collection.end()) {
202 return it->second.get();
206 template <
class Collection>
207 typename Collection::value_type::second_type::element_type&
209 const typename Collection::value_type::first_type& key) {
210 typename Collection::const_iterator it = collection.find(key);
211 CHECK(it != collection.end()) <<
"key not found: " << key;
219 template <
class Collection,
class Key,
class Value>
223 typename Collection::const_iterator it = collection.find(key);
224 if (it == collection.end()) {
238 template <
class Collection,
class Key>
240 return collection.find(key) != collection.end();
245 template <
class Collection,
class Key,
class Value>
249 typedef typename Collection::const_iterator const_iterator;
250 std::pair<const_iterator, const_iterator> range = collection.equal_range(key);
251 for (const_iterator it = range.first; it != range.second; ++it) {
252 if (it->second == value) {
266 template <
class Collection>
268 const typename Collection::value_type& vt) {
269 std::pair<typename Collection::iterator, bool> ret = collection->insert(vt);
272 ret.first->second = vt.second;
279 template <
class Collection>
281 const typename Collection::value_type::first_type& key,
282 const typename Collection::value_type::second_type&
value) {
284 collection,
typename Collection::value_type(key, value));
289 template <
class Collection,
class InputIterator>
291 InputIterator first, InputIterator last) {
292 for (; first != last; ++first) {
301 template <
class Collection>
303 Collection*
const collection,
304 const typename Collection::value_type::first_type& key,
305 const typename Collection::value_type::second_type&
value) {
306 std::pair<typename Collection::iterator, bool> ret =
307 collection->insert(
typename Collection::value_type(key, value));
309 delete ret.first->second;
310 ret.first->second =
value;
320 template <
class Collection>
322 const typename Collection::value_type& vt) {
323 return collection->insert(vt).second;
327 template <
class Collection>
329 Collection*
const collection,
330 const typename Collection::value_type::first_type& key,
331 const typename Collection::value_type::second_type&
value) {
333 collection,
typename Collection::value_type(key, value));
337 template <
class Collection>
339 const typename Collection::value_type&
value) {
344 template <
class Collection>
346 const typename Collection::value_type&
value) {
352 template <
class Collection>
354 const typename Collection::value_type::first_type& key,
355 const typename Collection::value_type::second_type& data) {
356 typedef typename Collection::value_type value_type;
358 <<
"duplicate key: " << key;
362 template <
class Collection>
364 Collection*
const collection,
365 const typename Collection::value_type::first_type& key,
366 const typename Collection::value_type::second_type& data) {
367 typedef typename Collection::value_type value_type;
377 template <
class Collection>
379 Collection*
const collection,
380 const typename Collection::value_type::first_type& key) {
381 typedef typename Collection::value_type value_type;
382 std::pair<typename Collection::iterator, bool> res =
383 collection->insert(value_type(key,
typename value_type::second_type()));
385 return res.first->second;
395 template <
class Collection>
396 typename Collection::value_type::second_type&
398 const typename Collection::value_type& vt) {
399 return collection->insert(vt).first->second;
403 template <
class Collection>
404 typename Collection::value_type::second_type&
406 const typename Collection::value_type::first_type& key,
407 const typename Collection::value_type::second_type&
value) {
409 collection,
typename Collection::value_type(key, value));
422 template <
typename Sequence,
typename Collection>
424 const Sequence& sequence,
425 const typename Collection::value_type::second_type& increment,
426 Collection*
const count_map) {
427 for (
typename Sequence::const_iterator it = sequence.begin();
428 it != sequence.end(); ++it) {
429 typename Collection::value_type::second_type&
value =
431 typename Collection::value_type::second_type());
442 template <
class Collection>
443 typename Collection::value_type::second_type&
445 const typename Collection::value_type::first_type& key) {
446 typedef typename std::iterator_traits<
447 typename Collection::value_type::second_type>::value_type Element;
448 std::pair<typename Collection::iterator, bool> ret =
449 collection->insert(
typename Collection::value_type(
451 static_cast<typename Collection::value_type::second_type>(
NULL)));
453 ret.first->second =
new Element();
455 return ret.first->second;
460 template <
class Collection,
class Arg>
461 typename Collection::value_type::second_type&
463 const typename Collection::value_type::first_type& key,
465 typedef typename std::iterator_traits<
466 typename Collection::value_type::second_type>::value_type Element;
467 std::pair<typename Collection::iterator, bool> ret =
468 collection->insert(
typename Collection::value_type(
470 static_cast<typename Collection::value_type::second_type>(
NULL)));
472 ret.first->second =
new Element(arg);
474 return ret.first->second;
496 template <
class Collection>
497 typename Collection::value_type::second_type::element_type*
499 Collection*
const collection,
500 const typename Collection::value_type::first_type& key) {
501 typedef typename Collection::value_type::second_type
Value;
502 std::pair<typename Collection::iterator, bool> ret =
503 collection->insert(
typename Collection::value_type(key,
Value()));
505 ret.first->second.reset(
new typename Value::element_type);
507 return ret.first->second.get();
515 template <
class Collection,
class Arg>
516 typename Collection::value_type::second_type::element_type*
518 Collection*
const collection,
519 const typename Collection::value_type::first_type& key,
521 typedef typename Collection::value_type::second_type
Value;
522 std::pair<typename Collection::iterator, bool> ret =
523 collection->insert(
typename Collection::value_type(key,
Value()));
525 ret.first->second.reset(
new typename Value::element_type(arg));
527 return ret.first->second.get();
534 template <
class Collection>
535 typename Collection::value_type::second_type&
537 Collection*
const collection,
538 const typename Collection::value_type::first_type& key) {
539 typedef typename Collection::value_type::second_type SharedPtr;
540 typedef typename Collection::value_type::second_type::element_type Element;
541 std::pair<typename Collection::iterator, bool> ret =
542 collection->insert(
typename Collection::value_type(key, SharedPtr()));
544 ret.first->second.reset(
new Element());
546 return ret.first->second;
554 template <
class Collection,
class Arg>
555 typename Collection::value_type::second_type&
557 Collection*
const collection,
558 const typename Collection::value_type::first_type& key,
560 typedef typename Collection::value_type::second_type SharedPtr;
561 typedef typename Collection::value_type::second_type::element_type Element;
562 std::pair<typename Collection::iterator, bool> ret =
563 collection->insert(
typename Collection::value_type(key, SharedPtr()));
565 ret.first->second.reset(
new Element(arg));
567 return ret.first->second;
581 template <
class Collection>
583 const typename Collection::value_type::first_type& key,
584 const typename Collection::value_type::second_type&
value,
585 typename Collection::value_type::second_type*
previous) {
586 std::pair<typename Collection::iterator, bool> ret =
587 collection->insert(
typename Collection::value_type(key, value));
591 *previous = ret.first->second;
593 ret.first->second =
value;
600 template <
class Collection>
602 const typename Collection::value_type& vt,
603 typename Collection::value_type::second_type*
previous) {
604 std::pair<typename Collection::iterator, bool> ret = collection->insert(vt);
608 *previous = ret.first->second;
610 ret.first->second = vt.second;
623 template <
class Collection>
624 typename Collection::value_type::second_type*
const
626 const typename Collection::value_type& vt) {
627 std::pair<typename Collection::iterator, bool> ret = collection->insert(vt);
631 return &ret.first->second;
636 template <
class Collection>
637 typename Collection::value_type::second_type*
const
639 Collection*
const collection,
640 const typename Collection::value_type::first_type& key,
641 const typename Collection::value_type::second_type& data) {
643 typename Collection::value_type(key, data));
662 template <
class Collection>
664 Collection*
const collection,
665 const typename Collection::value_type::first_type& key) {
666 typename Collection::iterator it = collection->find(key);
667 if (it == collection->end()) {
670 typename Collection::value_type::second_type v = it->second;
671 collection->erase(it);
679 template <
class MapContainer,
class KeyContainer>
681 KeyContainer* key_container) {
683 for (
typename MapContainer::const_iterator it = map_container.begin();
684 it != map_container.end(); ++it) {
685 key_container->insert(it->first);
693 template <
class MapContainer,
class KeyContainer>
695 KeyContainer* key_container) {
697 for (
typename MapContainer::const_iterator it = map_container.begin();
698 it != map_container.end(); ++it) {
699 key_container->push_back(it->first);
710 template <
class MapContainer,
class KeyType>
712 vector<KeyType>* key_container) {
724 if (key_container->empty()) {
725 key_container->reserve(map_container.size());
727 for (
typename MapContainer::const_iterator it = map_container.begin();
728 it != map_container.end(); ++it) {
729 key_container->push_back(it->first);
737 template <
class MapContainer,
class ValueContainer>
739 ValueContainer* value_container) {
741 for (
typename MapContainer::const_iterator it = map_container.begin();
742 it != map_container.end(); ++it) {
743 value_container->push_back(it->second);
754 template <
class MapContainer,
class ValueType>
756 vector<ValueType>* value_container) {
759 if (value_container->empty()) {
760 value_container->reserve(map_container.size());
762 for (
typename MapContainer::const_iterator it = map_container.begin();
763 it != map_container.end(); ++it) {
764 value_container->push_back(it->second);
771 #endif // GOOGLE_PROTOBUF_STUBS_MAP_UTIL_H__
Definition: map_util.h:49
Collection::value_type::second_type *const InsertOrReturnExisting(Collection *const collection, const typename Collection::value_type &vt)
Definition: map_util.h:625
const Collection::value_type::second_type & FindWithDefault(const Collection &collection, const typename Collection::value_type::first_type &key, const typename Collection::value_type::second_type &value)
Definition: map_util.h:123
const Collection::value_type::second_type * FindOrNull(const Collection &collection, const typename Collection::value_type::first_type &key)
Definition: map_util.h:137
bool ContainsKey(const Collection &collection, const Key &key)
Definition: map_util.h:239
bool UpdateReturnCopy(Collection *const collection, const typename Collection::value_type::first_type &key, const typename Collection::value_type::second_type &value, typename Collection::value_type::second_type *previous)
Definition: map_util.h:582
void AddTokenCounts(const Sequence &sequence, const typename Collection::value_type::second_type &increment, Collection *const count_map)
Definition: map_util.h:423
Collection::value_type::second_type & LookupOrInsertNewSharedPtr(Collection *const collection, const typename Collection::value_type::first_type &key)
Definition: map_util.h:536
void AppendKeysFromMap(const MapContainer &map_container, KeyContainer *key_container)
Definition: map_util.h:694
bool ContainsKeyValuePair(const Collection &collection, const Key &key, const Value &value)
Definition: map_util.h:246
void InsertOrUpdateMany(Collection *const collection, InputIterator first, InputIterator last)
Definition: map_util.h:290
Collection::value_type::second_type::element_type * FindLinkedPtrOrNull(const Collection &collection, const typename Collection::value_type::first_type &key)
Definition: map_util.h:194
Collection::value_type::second_type & LookupOrInsertNew(Collection *const collection, const typename Collection::value_type::first_type &key)
Definition: map_util.h:444
arena_t NULL
Definition: jemalloc_internal.h:624
bool InsertAndDeleteExisting(Collection *const collection, const typename Collection::value_type::first_type &key, const typename Collection::value_type::second_type &value)
Definition: map_util.h:302
Collection::value_type::second_type::element_type * LookupOrInsertNewLinkedPtr(Collection *const collection, const typename Collection::value_type::first_type &key)
Definition: map_util.h:498
Collection::value_type::second_type EraseKeyReturnValuePtr(Collection *const collection, const typename Collection::value_type::first_type &key)
Definition: map_util.h:663
Collection::value_type::second_type::element_type & FindLinkedPtrOrDie(const Collection &collection, const typename Collection::value_type::first_type &key)
Definition: map_util.h:208
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
Definition: document.h:1706
#define GOOGLE_CHECK(EXPRESSION)
Definition: common.h:713
uint32_t previous(octet_iterator &it, octet_iterator pass_start)
Deprecated in versions that include "prior".
Definition: checked.h:179
Collection::value_type::second_type & LookupOrInsert(Collection *const collection, const typename Collection::value_type &vt)
Definition: map_util.h:397
void AppendValuesFromMap(const MapContainer &map_container, ValueContainer *value_container)
Definition: map_util.h:738
bool InsertIfNotPresent(Collection *const collection, const typename Collection::value_type &vt)
Definition: map_util.h:321
bool FindCopy(const Collection &collection, const Key &key, Value *const value)
Definition: map_util.h:220
Definition: document.h:390
internal::NamedArg< char > arg(StringRef name, const T &arg)
Definition: format.h:3248
bool InsertOrUpdate(Collection *const collection, const typename Collection::value_type &vt)
Definition: map_util.h:267
Collection::value_type::second_type & InsertKeyOrDie(Collection *const collection, const typename Collection::value_type::first_type &key)
Definition: map_util.h:378
const Collection::value_type::second_type & FindOrDie(const Collection &collection, const typename Collection::value_type::first_type &key)
Definition: map_util.h:74
Definition: BnetFileGenerator.h:47
const Collection::value_type::second_type & FindOrDieNoPrint(const Collection &collection, const typename Collection::value_type::first_type &key)
Definition: map_util.h:94
const FieldDescriptor value
Definition: descriptor.h:1522
#define const
Definition: zconf.h:217
void InsertKeysFromMap(const MapContainer &map_container, KeyContainer *key_container)
Definition: map_util.h:680
T type
Definition: map_util.h:49
void InsertOrDieNoPrint(Collection *const collection, const typename Collection::value_type &value)
Definition: map_util.h:345
void InsertOrDie(Collection *const collection, const typename Collection::value_type &value)
Definition: map_util.h:338
Collection::value_type::second_type FindPtrOrNull(const Collection &collection, const typename Collection::value_type::first_type &key)
Definition: map_util.h:166