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 // This file contains utility functions and classes that help the | 5 // This file contains utility functions and classes that help the |
6 // implementation, and management of the Callback objects. | 6 // implementation, and management of the Callback objects. |
7 | 7 |
8 #ifndef BASE_CALLBACK_INTERNAL_H_ | 8 #ifndef BASE_CALLBACK_INTERNAL_H_ |
9 #define BASE_CALLBACK_INTERNAL_H_ | 9 #define BASE_CALLBACK_INTERNAL_H_ |
10 | 10 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 public: | 60 public: |
61 CallbackBase(const CallbackBase& c); | 61 CallbackBase(const CallbackBase& c); |
62 CallbackBase& operator=(const CallbackBase& c); | 62 CallbackBase& operator=(const CallbackBase& c); |
63 | 63 |
64 // Returns true if Callback is null (doesn't refer to anything). | 64 // Returns true if Callback is null (doesn't refer to anything). |
65 bool is_null() const { return bind_state_.get() == NULL; } | 65 bool is_null() const { return bind_state_.get() == NULL; } |
66 | 66 |
67 // Returns the Callback into an uninitialized state. | 67 // Returns the Callback into an uninitialized state. |
68 void Reset(); | 68 void Reset(); |
69 | 69 |
70 // Returns true if this callback equals |other|. |other| may be null. | |
71 bool Equals(const CallbackBase& other) const; | |
dcheng
2015/12/08 20:16:46
I'm curious: do you know why we didn't just do thi
danakj
2015/12/08 22:12:59
Does this allow comparison of
Callback<void(int)>
tzik
2015/12/09 07:03:15
Ah, yes. Let me revert this part, that is an unint
| |
72 | |
70 protected: | 73 protected: |
71 // In C++, it is safe to cast function pointers to function pointers of | 74 // In C++, it is safe to cast function pointers to function pointers of |
72 // another type. It is not okay to use void*. We create a InvokeFuncStorage | 75 // another type. It is not okay to use void*. We create a InvokeFuncStorage |
73 // that that can store our function pointer, and then cast it back to | 76 // that that can store our function pointer, and then cast it back to |
74 // the original type on usage. | 77 // the original type on usage. |
75 typedef void(*InvokeFuncStorage)(void); | 78 typedef void(*InvokeFuncStorage)(void); |
76 | 79 |
77 // Returns true if this callback equals |other|. |other| may be null. | |
78 bool Equals(const CallbackBase& other) const; | |
79 | |
80 // Allow initializing of |bind_state_| via the constructor to avoid default | 80 // Allow initializing of |bind_state_| via the constructor to avoid default |
81 // initialization of the scoped_refptr. We do not also initialize | 81 // initialization of the scoped_refptr. We do not also initialize |
82 // |polymorphic_invoke_| here because doing a normal assignment in the | 82 // |polymorphic_invoke_| here because doing a normal assignment in the |
83 // derived Callback templates makes for much nicer compiler errors. | 83 // derived Callback templates makes for much nicer compiler errors. |
84 explicit CallbackBase(BindStateBase* bind_state); | 84 explicit CallbackBase(BindStateBase* bind_state); |
85 | 85 |
86 // Force the destructor to be instantiated inside this translation unit so | 86 // Force the destructor to be instantiated inside this translation unit so |
87 // that our subclasses will not get inlined versions. Avoids more template | 87 // that our subclasses will not get inlined versions. Avoids more template |
88 // bloat. | 88 // bloat. |
89 ~CallbackBase(); | 89 ~CallbackBase(); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
213 template <typename T> | 213 template <typename T> |
214 typename std::enable_if<IsMoveOnlyType<T>::value, T>::type CallbackForward( | 214 typename std::enable_if<IsMoveOnlyType<T>::value, T>::type CallbackForward( |
215 T& t) { | 215 T& t) { |
216 return std::move(t); | 216 return std::move(t); |
217 } | 217 } |
218 | 218 |
219 } // namespace internal | 219 } // namespace internal |
220 } // namespace base | 220 } // namespace base |
221 | 221 |
222 #endif // BASE_CALLBACK_INTERNAL_H_ | 222 #endif // BASE_CALLBACK_INTERNAL_H_ |
OLD | NEW |