OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_ID_MAP_H_ | 5 #ifndef BASE_ID_MAP_H_ |
6 #define BASE_ID_MAP_H_ | 6 #define BASE_ID_MAP_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 14 matching lines...) Expand all Loading... | |
25 // item in the list). | 25 // item in the list). |
26 // | 26 // |
27 // Items can be inserted into the container with arbitrary ID, but the caller | 27 // Items can be inserted into the container with arbitrary ID, but the caller |
28 // must ensure they are unique. Inserting IDs and relying on automatically | 28 // must ensure they are unique. Inserting IDs and relying on automatically |
29 // generated ones is not allowed because they can collide. | 29 // generated ones is not allowed because they can collide. |
30 // | 30 // |
31 // This class does not have a virtual destructor, do not inherit from it when | 31 // This class does not have a virtual destructor, do not inherit from it when |
32 // ownership semantics are set to own because pointers will leak. | 32 // ownership semantics are set to own because pointers will leak. |
33 template<typename T, IDMapOwnershipSemantics OS = IDMapExternalPointer> | 33 template<typename T, IDMapOwnershipSemantics OS = IDMapExternalPointer> |
34 class IDMap : public base::NonThreadSafe { | 34 class IDMap : public base::NonThreadSafe { |
35 public: | |
36 typedef int32 KeyType; | |
jochen (gone - plz use gerrit)
2014/05/05 10:55:49
nit. empty line after this line
mnaganov (inactive)
2014/05/06 10:54:15
Done.
| |
35 private: | 37 private: |
36 typedef int32 KeyType; | |
37 typedef base::hash_map<KeyType, T*> HashTable; | 38 typedef base::hash_map<KeyType, T*> HashTable; |
38 | 39 |
39 public: | 40 public: |
40 IDMap() : iteration_depth_(0), next_id_(1), check_on_null_data_(false) { | 41 IDMap() : iteration_depth_(0), next_id_(1), check_on_null_data_(false) { |
41 // A number of consumers of IDMap create it on one thread but always access | 42 // A number of consumers of IDMap create it on one thread but always access |
42 // it from a different, but consitent, thread post-construction. | 43 // it from a different, but consitent, thread post-construction. |
43 DetachFromThread(); | 44 DetachFromThread(); |
44 } | 45 } |
45 | 46 |
46 ~IDMap() { | 47 ~IDMap() { |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
248 | 249 |
249 HashTable data_; | 250 HashTable data_; |
250 | 251 |
251 // See description above setter. | 252 // See description above setter. |
252 bool check_on_null_data_; | 253 bool check_on_null_data_; |
253 | 254 |
254 DISALLOW_COPY_AND_ASSIGN(IDMap); | 255 DISALLOW_COPY_AND_ASSIGN(IDMap); |
255 }; | 256 }; |
256 | 257 |
257 #endif // BASE_ID_MAP_H_ | 258 #endif // BASE_ID_MAP_H_ |
OLD | NEW |