Chromium Code Reviews| Index: src/base/smart-pointers.h |
| diff --git a/src/smart-pointers.h b/src/base/smart-pointers.h |
| similarity index 67% |
| rename from src/smart-pointers.h |
| rename to src/base/smart-pointers.h |
| index c4bbd0b45e57155f240f2e30d1152d172e0c68d4..31e45520cfd0b4a1062413a2fb491e23fdf2bb8d 100644 |
| --- a/src/smart-pointers.h |
| +++ b/src/base/smart-pointers.h |
| @@ -2,14 +2,15 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#ifndef V8_SMART_POINTERS_H_ |
| -#define V8_SMART_POINTERS_H_ |
| +#ifndef V8_BASE_SMART_POINTERS_H_ |
| +#define V8_BASE_SMART_POINTERS_H_ |
| namespace v8 { |
| +namespace base { |
| namespace internal { |
| -template<typename Deallocator, typename T> |
| +template <typename Deallocator, typename T> |
| class SmartPointerBase { |
| public: |
| // Default constructor. Constructs an empty scoped pointer. |
| @@ -20,8 +21,7 @@ class SmartPointerBase { |
| // Copy constructor removes the pointer from the original to avoid double |
| // freeing. |
| - SmartPointerBase(const SmartPointerBase<Deallocator, T>& rhs) |
| - : p_(rhs.p_) { |
| + SmartPointerBase(const SmartPointerBase<Deallocator, T>& rhs) : p_(rhs.p_) { |
| const_cast<SmartPointerBase<Deallocator, T>&>(rhs).p_ = NULL; |
| } |
| @@ -32,14 +32,10 @@ class SmartPointerBase { |
| T* get() const { return p_; } |
| // You can use [n] to index as if it was a plain pointer. |
| - T& operator[](size_t i) { |
| - return p_[i]; |
| - } |
| + T& operator[](size_t i) { return p_[i]; } |
| // You can use [n] to index as if it was a plain pointer. |
| - const T& operator[](size_t i) const { |
| - return p_[i]; |
| - } |
| + const T& operator[](size_t i) const { return p_[i]; } |
| // We don't have implicit conversion to a T* since that hinders migration: |
| // You would not be able to change a method from returning a T* to |
| @@ -79,52 +75,58 @@ class SmartPointerBase { |
| // When the destructor of the scoped pointer is executed the plain pointer |
| // is deleted using DeleteArray. This implies that you must allocate with |
| // NewArray. |
| - ~SmartPointerBase() { if (p_) Deallocator::Delete(p_); } |
| + ~SmartPointerBase() { |
| + if (p_) Deallocator::Delete(p_); |
| + } |
| private: |
| T* p_; |
| }; |
| + |
| +} // namepsace internal |
| +} // namespace base |
| + |
| +namespace internal { |
|
rmcilroy
2015/07/08 14:30:58
I kept this in namespace v8::internal to avoid ugl
jochen (gone - plz use gerrit)
2015/07/10 08:35:38
hum, i'd rather have it in base. scoped_ptr isn't
|
| + |
| // A 'scoped array pointer' that calls DeleteArray on its pointer when the |
| // destructor is called. |
| -template<typename T> |
| +template <typename T> |
| struct ArrayDeallocator { |
| - static void Delete(T* array) { |
| - DeleteArray(array); |
| - } |
| + static void Delete(T* array) { DeleteArray(array); } |
| }; |
| -template<typename T> |
| -class SmartArrayPointer: public SmartPointerBase<ArrayDeallocator<T>, T> { |
| +template <typename T> |
| +class SmartArrayPointer |
| + : public base::internal::SmartPointerBase<ArrayDeallocator<T>, T> { |
| public: |
| - SmartArrayPointer() { } |
| + SmartArrayPointer() {} |
| explicit SmartArrayPointer(T* ptr) |
| - : SmartPointerBase<ArrayDeallocator<T>, T>(ptr) { } |
| + : base::internal::SmartPointerBase<ArrayDeallocator<T>, T>(ptr) {} |
| SmartArrayPointer(const SmartArrayPointer<T>& rhs) |
| - : SmartPointerBase<ArrayDeallocator<T>, T>(rhs) { } |
| + : base::internal::SmartPointerBase<ArrayDeallocator<T>, T>(rhs) {} |
| }; |
| -template<typename T> |
| +template <typename T> |
| struct ObjectDeallocator { |
| - static void Delete(T* object) { |
| - delete object; |
| - } |
| + static void Delete(T* object) { delete object; } |
| }; |
| - |
| -template<typename T> |
| -class SmartPointer: public SmartPointerBase<ObjectDeallocator<T>, T> { |
| +template <typename T> |
| +class SmartPointer |
| + : public base::internal::SmartPointerBase<ObjectDeallocator<T>, T> { |
| public: |
| - SmartPointer() { } |
| + SmartPointer() {} |
| explicit SmartPointer(T* ptr) |
| - : SmartPointerBase<ObjectDeallocator<T>, T>(ptr) { } |
| + : base::internal::SmartPointerBase<ObjectDeallocator<T>, T>(ptr) {} |
| SmartPointer(const SmartPointer<T>& rhs) |
| - : SmartPointerBase<ObjectDeallocator<T>, T>(rhs) { } |
| + : base::internal::SmartPointerBase<ObjectDeallocator<T>, T>(rhs) {} |
| }; |
| -} } // namespace v8::internal |
| +} // namespace internal |
| +} // namespace v8 |
| #endif // V8_SMART_POINTERS_H_ |