| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef BASE_SUPPORTS_USER_DATA_H_ |
| 6 #define BASE_SUPPORTS_USER_DATA_H_ |
| 7 |
| 8 #include <map> |
| 9 |
| 10 #include "base/base_export.h" |
| 11 #include "base/memory/linked_ptr.h" |
| 12 |
| 13 namespace base { |
| 14 |
| 15 // This is a helper for classes that want to allow users to stash random data by |
| 16 // key. At destruction all the objects will be destructed. |
| 17 class BASE_EXPORT SupportsUserData { |
| 18 public: |
| 19 SupportsUserData(); |
| 20 virtual ~SupportsUserData(); |
| 21 |
| 22 // Derive from this class and add your own data members to associate extra |
| 23 // information with this object. Use GetUserData(key) and SetUserData() |
| 24 class BASE_EXPORT Data { |
| 25 public: |
| 26 virtual ~Data() {} |
| 27 }; |
| 28 |
| 29 // The user data allows the clients to associate data with this object. |
| 30 // Multiple user data values can be stored under different keys. |
| 31 // This object will TAKE OWNERSHIP of the given data pointer, and will |
| 32 // delete the object if it is changed or the object is destroyed. |
| 33 Data* GetUserData(const void* key) const; |
| 34 void SetUserData(const void* key, Data* data); |
| 35 |
| 36 private: |
| 37 typedef std::map<const void*, linked_ptr<Data> > DataMap; |
| 38 |
| 39 // Externally-defined data accessible by key |
| 40 DataMap user_data_; |
| 41 |
| 42 DISALLOW_COPY_AND_ASSIGN(SupportsUserData); |
| 43 }; |
| 44 |
| 45 } // namespace base |
| 46 |
| 47 #endif // BASE_SUPPORTS_USER_DATA_H_ |
| OLD | NEW |