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) {
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) {
357 <<
"duplicate key: " <<
key;
361 template <
class Collection>
363 Collection*
const collection,
364 const typename Collection::value_type::first_type&
key,
365 const typename Collection::value_type::second_type&
data) {
375 template <
class Collection>
377 Collection*
const collection,
378 const typename Collection::value_type::first_type&
key) {
379 typedef typename Collection::value_type value_type;
380 std::pair<typename Collection::iterator, bool>
res =
381 collection->insert(value_type(key,
typename value_type::second_type()));
383 return res.first->second;
393 template <
class Collection>
394 typename Collection::value_type::second_type&
396 const typename Collection::value_type& vt) {
397 return collection->insert(vt).first->second;
401 template <
class Collection>
402 typename Collection::value_type::second_type&
404 const typename Collection::value_type::first_type&
key,
405 const typename Collection::value_type::second_type&
value) {
407 collection,
typename Collection::value_type(key, value));
420 template <
typename Sequence,
typename Collection>
423 const typename Collection::value_type::second_type& increment,
424 Collection*
const count_map) {
425 for (
typename Sequence::const_iterator it = sequence.begin();
426 it != sequence.end(); ++it) {
427 typename Collection::value_type::second_type&
value =
429 typename Collection::value_type::second_type());
440 template <
class Collection>
441 typename Collection::value_type::second_type&
443 const typename Collection::value_type::first_type&
key) {
444 typedef typename std::iterator_traits<
445 typename Collection::value_type::second_type>::value_type Element;
446 std::pair<typename Collection::iterator, bool>
ret =
447 collection->insert(
typename Collection::value_type(
449 static_cast<typename Collection::value_type::second_type>(
NULL)));
451 ret.first->second =
new Element();
453 return ret.first->second;
458 template <
class Collection,
class Arg>
459 typename Collection::value_type::second_type&
461 const typename Collection::value_type::first_type&
key,
463 typedef typename std::iterator_traits<
464 typename Collection::value_type::second_type>::value_type Element;
465 std::pair<typename Collection::iterator, bool>
ret =
466 collection->insert(
typename Collection::value_type(
468 static_cast<typename Collection::value_type::second_type>(
NULL)));
470 ret.first->second =
new Element(arg);
472 return ret.first->second;
494 template <
class Collection>
495 typename Collection::value_type::second_type::element_type*
497 Collection*
const collection,
498 const typename Collection::value_type::first_type&
key) {
499 typedef typename Collection::value_type::second_type
Value;
500 std::pair<typename Collection::iterator, bool>
ret =
501 collection->insert(
typename Collection::value_type(key, Value()));
503 ret.first->second.reset(
new typename Value::element_type);
505 return ret.first->second.get();
513 template <
class Collection,
class Arg>
514 typename Collection::value_type::second_type::element_type*
516 Collection*
const collection,
517 const typename Collection::value_type::first_type&
key,
519 typedef typename Collection::value_type::second_type
Value;
520 std::pair<typename Collection::iterator, bool>
ret =
521 collection->insert(
typename Collection::value_type(key, Value()));
523 ret.first->second.reset(
new typename Value::element_type(arg));
525 return ret.first->second.get();
532 template <
class Collection>
533 typename Collection::value_type::second_type&
535 Collection*
const collection,
536 const typename Collection::value_type::first_type&
key) {
537 typedef typename Collection::value_type::second_type SharedPtr;
538 typedef typename Collection::value_type::second_type::element_type Element;
539 std::pair<typename Collection::iterator, bool>
ret =
540 collection->insert(
typename Collection::value_type(key, SharedPtr()));
542 ret.first->second.reset(
new Element());
544 return ret.first->second;
552 template <
class Collection,
class Arg>
553 typename Collection::value_type::second_type&
555 Collection*
const collection,
556 const typename Collection::value_type::first_type&
key,
558 typedef typename Collection::value_type::second_type SharedPtr;
559 typedef typename Collection::value_type::second_type::element_type Element;
560 std::pair<typename Collection::iterator, bool>
ret =
561 collection->insert(
typename Collection::value_type(key, SharedPtr()));
563 ret.first->second.reset(
new Element(arg));
565 return ret.first->second;
579 template <
class Collection>
581 const typename Collection::value_type::first_type&
key,
582 const typename Collection::value_type::second_type&
value,
583 typename Collection::value_type::second_type*
previous) {
584 std::pair<typename Collection::iterator, bool>
ret =
585 collection->insert(
typename Collection::value_type(key, value));
589 *previous = ret.first->second;
591 ret.first->second =
value;
598 template <
class Collection>
600 const typename Collection::value_type& vt,
601 typename Collection::value_type::second_type*
previous) {
602 std::pair<typename Collection::iterator, bool>
ret = collection->insert(vt);
606 *previous = ret.first->second;
608 ret.first->second = vt.second;
621 template <
class Collection>
622 typename Collection::value_type::second_type*
const 624 const typename Collection::value_type& vt) {
625 std::pair<typename Collection::iterator, bool>
ret = collection->insert(vt);
629 return &ret.first->second;
634 template <
class Collection>
635 typename Collection::value_type::second_type*
const 637 Collection*
const collection,
638 const typename Collection::value_type::first_type&
key,
639 const typename Collection::value_type::second_type&
data) {
641 typename Collection::value_type(key, data));
660 template <
class Collection>
662 Collection*
const collection,
663 const typename Collection::value_type::first_type&
key) {
664 typename Collection::iterator it = collection->find(key);
665 if (it == collection->end()) {
668 typename Collection::value_type::second_type
v = it->second;
669 collection->erase(it);
677 template <
class MapContainer,
class KeyContainer>
679 KeyContainer* key_container) {
681 for (
typename MapContainer::const_iterator it = map_container.begin();
682 it != map_container.end(); ++it) {
683 key_container->insert(it->first);
691 template <
class MapContainer,
class KeyContainer>
693 KeyContainer* key_container) {
695 for (
typename MapContainer::const_iterator it = map_container.begin();
696 it != map_container.end(); ++it) {
697 key_container->push_back(it->first);
708 template <
class MapContainer,
class KeyType>
710 vector<KeyType>* key_container) {
722 if (key_container->empty()) {
723 key_container->reserve(map_container.size());
725 for (
typename MapContainer::const_iterator it = map_container.begin();
726 it != map_container.end(); ++it) {
727 key_container->push_back(it->first);
735 template <
class MapContainer,
class ValueContainer>
737 ValueContainer* value_container) {
739 for (
typename MapContainer::const_iterator it = map_container.begin();
740 it != map_container.end(); ++it) {
741 value_container->push_back(it->second);
752 template <
class MapContainer,
class ValueType>
754 vector<ValueType>* value_container) {
757 if (value_container->empty()) {
758 value_container->reserve(map_container.size());
760 for (
typename MapContainer::const_iterator it = map_container.begin();
761 it != map_container.end(); ++it) {
762 value_container->push_back(it->second);
769 #endif // GOOGLE_PROTOBUF_STUBS_MAP_UTIL_H__ Collection::value_type::second_type *const InsertOrReturnExisting(Collection *const collection, const typename Collection::value_type &vt)
Definition: map_util.h:623
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
Node * previous(const Node &, const Node *stayWithin=nullptr)
Definition: NodeTraversal.h:120
GLint first
Definition: gl2.h:421
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:580
Definition: SourceBuffer.idl:33
void AddTokenCounts(const Sequence &sequence, const typename Collection::value_type::second_type &increment, Collection *const count_map)
Definition: map_util.h:421
Collection::value_type::second_type & LookupOrInsertNewSharedPtr(Collection *const collection, const typename Collection::value_type::first_type &key)
Definition: map_util.h:534
Definition: map_util.h:49
void AppendKeysFromMap(const MapContainer &map_container, KeyContainer *key_container)
Definition: map_util.h:692
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:442
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:496
Collection::value_type::second_type EraseKeyReturnValuePtr(Collection *const collection, const typename Collection::value_type::first_type &key)
Definition: map_util.h:661
Collection::value_type::second_type::element_type & FindLinkedPtrOrDie(const Collection &collection, const typename Collection::value_type::first_type &key)
Definition: map_util.h:208
WEBCORE_EXPORT Node * last(const ContainerNode &)
Definition: NodeTraversal.cpp:106
const FieldDescriptor const OneofDescriptor value
Definition: descriptor.h:1717
int ret
Definition: test_unit_dft.c:69
TestSubObjConstructor T
Definition: TestTypedefs.idl:84
EGLAttrib * value
Definition: eglext.h:120
Collection::value_type::second_type & LookupOrInsert(Collection *const collection, const typename Collection::value_type &vt)
Definition: map_util.h:395
Definition: __init__.py:1
void AppendValuesFromMap(const MapContainer &map_container, ValueContainer *value_container)
Definition: map_util.h:736
bool InsertIfNotPresent(Collection *const collection, const typename Collection::value_type &vt)
Definition: map_util.h:321
const GLfloat * v
Definition: gl2.h:514
bool FindCopy(const Collection &collection, const Key &key, Value *const value)
Definition: map_util.h:220
EGLStreamKHR EGLint EGLint EGLint const void * data
Definition: eglext.h:984
Definition: struct.pb.h:161
Definition: document.h:393
#define CHECK(x)
Definition: dynbench.cpp:46
bool InsertOrUpdate(Collection *const collection, const typename Collection::value_type &vt)
Definition: map_util.h:267
#define GOOGLE_CHECK(EXPRESSION)
Definition: logging.h:151
Collection::value_type::second_type & InsertKeyOrDie(Collection *const collection, const typename Collection::value_type::first_type &key)
Definition: map_util.h:376
const
Definition: upload.py:398
#define NULL
Definition: common_types.h:41
Key
Definition: keyboard.h:10
const Collection::value_type::second_type & FindOrDie(const Collection &collection, const typename Collection::value_type::first_type &key)
Definition: map_util.h:74
Definition: gflags_completions.h:115
const Collection::value_type::second_type & FindOrDieNoPrint(const Collection &collection, const typename Collection::value_type::first_type &key)
Definition: map_util.h:94
void InsertKeysFromMap(const MapContainer &map_container, KeyContainer *key_container)
Definition: map_util.h:678
res
Definition: harness.py:111
T type
Definition: map_util.h:49
void InsertOrDieNoPrint(Collection *const collection, const typename Collection::value_type &value)
Definition: map_util.h:345
CFArrayRef CFTypeRef key
Definition: AVFoundationCFSoftLinking.h:129
void InsertOrDie(Collection *const collection, const typename Collection::value_type &value)
Definition: map_util.h:338
GLenum GLint * range
Definition: gl2.h:450
Collection::value_type::second_type FindPtrOrNull(const Collection &collection, const typename Collection::value_type::first_type &key)
Definition: map_util.h:166