| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 COMPONENTS_SYNC_BASE_IMMUTABLE_H_ |
| 6 #define COMPONENTS_SYNC_BASE_IMMUTABLE_H_ |
| 7 |
| 8 #include <utility> |
| 9 |
| 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" |
| 12 |
| 5 // Immutable<T> provides an easy, cheap, and thread-safe way to pass | 13 // Immutable<T> provides an easy, cheap, and thread-safe way to pass |
| 6 // large immutable data around. | 14 // large immutable data around. |
| 7 // | 15 // |
| 8 // For example, consider the following code: | 16 // For example, consider the following code: |
| 9 // | 17 // |
| 10 // typedef std::vector<LargeObject> LargeObjectList; | 18 // typedef std::vector<LargeObject> LargeObjectList; |
| 11 // | 19 // |
| 12 // void ProcessStuff(const LargeObjectList& stuff) { | 20 // void ProcessStuff(const LargeObjectList& stuff) { |
| 13 // for (LargeObjectList::const_iterator it = stuff.begin(); | 21 // for (LargeObjectList::const_iterator it = stuff.begin(); |
| 14 // it != stuff.end(); ++it) { | 22 // it != stuff.end(); ++it) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 // for discussion) Immutable<T> should be able to find it. | 62 // for discussion) Immutable<T> should be able to find it. |
| 55 // | 63 // |
| 56 // Alternatively, you could explicitly control which swap function is | 64 // Alternatively, you could explicitly control which swap function is |
| 57 // used by providing your own traits class or using one of the | 65 // used by providing your own traits class or using one of the |
| 58 // pre-defined ones below. See comments on traits below for details. | 66 // pre-defined ones below. See comments on traits below for details. |
| 59 // | 67 // |
| 60 // NOTE: Some complexity is necessary in order to use Immutable<T> | 68 // NOTE: Some complexity is necessary in order to use Immutable<T> |
| 61 // with forward-declared types. See comments on traits below for | 69 // with forward-declared types. See comments on traits below for |
| 62 // details. | 70 // details. |
| 63 | 71 |
| 64 #ifndef COMPONENTS_SYNC_BASE_IMMUTABLE_H_ | |
| 65 #define COMPONENTS_SYNC_BASE_IMMUTABLE_H_ | |
| 66 | |
| 67 #include <utility> | |
| 68 | |
| 69 #include "base/macros.h" | |
| 70 #include "base/memory/ref_counted.h" | |
| 71 | |
| 72 namespace syncer { | 72 namespace syncer { |
| 73 | 73 |
| 74 namespace internal { | 74 namespace internal { |
| 75 // This class is part of the Immutable implementation. DO NOT USE | 75 // This class is part of the Immutable implementation. DO NOT USE |
| 76 // THIS CLASS DIRECTLY YOURSELF. | 76 // THIS CLASS DIRECTLY YOURSELF. |
| 77 | 77 |
| 78 template <typename T, typename Traits> | 78 template <typename T, typename Traits> |
| 79 class ImmutableCore | 79 class ImmutableCore |
| 80 : public base::RefCountedThreadSafe<ImmutableCore<T, Traits>> { | 80 : public base::RefCountedThreadSafe<ImmutableCore<T, Traits>> { |
| 81 public: | 81 public: |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 | 238 |
| 239 // Helper function to avoid having to write out template arguments. | 239 // Helper function to avoid having to write out template arguments. |
| 240 template <typename T> | 240 template <typename T> |
| 241 Immutable<T> MakeImmutable(T* t) { | 241 Immutable<T> MakeImmutable(T* t) { |
| 242 return Immutable<T>(t); | 242 return Immutable<T>(t); |
| 243 } | 243 } |
| 244 | 244 |
| 245 } // namespace syncer | 245 } // namespace syncer |
| 246 | 246 |
| 247 #endif // COMPONENTS_SYNC_BASE_IMMUTABLE_H_ | 247 #endif // COMPONENTS_SYNC_BASE_IMMUTABLE_H_ |
| OLD | NEW |