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; |
| 37 |
35 private: | 38 private: |
36 typedef int32 KeyType; | |
37 typedef base::hash_map<KeyType, T*> HashTable; | 39 typedef base::hash_map<KeyType, T*> HashTable; |
38 | 40 |
39 public: | 41 public: |
40 IDMap() : iteration_depth_(0), next_id_(1), check_on_null_data_(false) { | 42 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 | 43 // A number of consumers of IDMap create it on one thread but always access |
42 // it from a different, but consitent, thread post-construction. | 44 // it from a different, but consitent, thread post-construction. |
43 DetachFromThread(); | 45 DetachFromThread(); |
44 } | 46 } |
45 | 47 |
46 ~IDMap() { | 48 ~IDMap() { |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 | 250 |
249 HashTable data_; | 251 HashTable data_; |
250 | 252 |
251 // See description above setter. | 253 // See description above setter. |
252 bool check_on_null_data_; | 254 bool check_on_null_data_; |
253 | 255 |
254 DISALLOW_COPY_AND_ASSIGN(IDMap); | 256 DISALLOW_COPY_AND_ASSIGN(IDMap); |
255 }; | 257 }; |
256 | 258 |
257 #endif // BASE_ID_MAP_H_ | 259 #endif // BASE_ID_MAP_H_ |
OLD | NEW |