Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Side by Side Diff: include/private/SkTemplates.h

Issue 1782973002: Revert of Use std::unique_ptr. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/private/SkOncePtr.h ('k') | include/private/SkUniquePtr.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #ifndef SkTemplates_DEFINED 10 #ifndef SkTemplates_DEFINED
11 #define SkTemplates_DEFINED 11 #define SkTemplates_DEFINED
12 12
13 #include "SkMath.h" 13 #include "SkMath.h"
14 #include "SkTLogic.h" 14 #include "SkTLogic.h"
15 #include "SkTypes.h" 15 #include "SkTypes.h"
16 #include "SkUniquePtr.h"
16 #include <limits.h> 17 #include <limits.h>
17 #include <memory>
18 #include <new> 18 #include <new>
19 19
20 /** \file SkTemplates.h 20 /** \file SkTemplates.h
21 21
22 This file contains light-weight template classes for type-safe and exception -safe 22 This file contains light-weight template classes for type-safe and exception -safe
23 resource management. 23 resource management.
24 */ 24 */
25 25
26 /** 26 /**
27 * Marks a local variable as known to be unused (to avoid warnings). 27 * Marks a local variable as known to be unused (to avoid warnings).
(...skipping 23 matching lines...) Expand all
51 51
52 /** \class SkAutoTCallVProc 52 /** \class SkAutoTCallVProc
53 53
54 Call a function when this goes out of scope. The template uses two 54 Call a function when this goes out of scope. The template uses two
55 parameters, the object, and a function that is to be called in the destructo r. 55 parameters, the object, and a function that is to be called in the destructo r.
56 If detach() is called, the object reference is set to null. If the object 56 If detach() is called, the object reference is set to null. If the object
57 reference is null when the destructor is called, we do not call the 57 reference is null when the destructor is called, we do not call the
58 function. 58 function.
59 */ 59 */
60 template <typename T, void (*P)(T*)> class SkAutoTCallVProc 60 template <typename T, void (*P)(T*)> class SkAutoTCallVProc
61 : public std::unique_ptr<T, SkFunctionWrapper<void, T, P>> { 61 : public skstd::unique_ptr<T, SkFunctionWrapper<void, T, P>> {
62 public: 62 public:
63 SkAutoTCallVProc(T* obj): std::unique_ptr<T, SkFunctionWrapper<void, T, P>>( obj) {} 63 SkAutoTCallVProc(T* obj): skstd::unique_ptr<T, SkFunctionWrapper<void, T, P> >(obj) {}
64 64
65 operator T*() const { return this->get(); } 65 operator T*() const { return this->get(); }
66 T* detach() { return this->release(); } 66 T* detach() { return this->release(); }
67 }; 67 };
68 68
69 /** \class SkAutoTCallIProc 69 /** \class SkAutoTCallIProc
70 70
71 Call a function when this goes out of scope. The template uses two 71 Call a function when this goes out of scope. The template uses two
72 parameters, the object, and a function that is to be called in the destructor. 72 parameters, the object, and a function that is to be called in the destructor.
73 If detach() is called, the object reference is set to null. If the object 73 If detach() is called, the object reference is set to null. If the object
74 reference is null when the destructor is called, we do not call the 74 reference is null when the destructor is called, we do not call the
75 function. 75 function.
76 */ 76 */
77 template <typename T, int (*P)(T*)> class SkAutoTCallIProc 77 template <typename T, int (*P)(T*)> class SkAutoTCallIProc
78 : public std::unique_ptr<T, SkFunctionWrapper<int, T, P>> { 78 : public skstd::unique_ptr<T, SkFunctionWrapper<int, T, P>> {
79 public: 79 public:
80 SkAutoTCallIProc(T* obj): std::unique_ptr<T, SkFunctionWrapper<int, T, P>>(o bj) {} 80 SkAutoTCallIProc(T* obj): skstd::unique_ptr<T, SkFunctionWrapper<int, T, P>> (obj) {}
81 81
82 operator T*() const { return this->get(); } 82 operator T*() const { return this->get(); }
83 T* detach() { return this->release(); } 83 T* detach() { return this->release(); }
84 }; 84 };
85 85
86 /** \class SkAutoTDelete 86 /** \class SkAutoTDelete
87 An SkAutoTDelete<T> is like a T*, except that the destructor of SkAutoTDelete< T> 87 An SkAutoTDelete<T> is like a T*, except that the destructor of SkAutoTDelete< T>
88 automatically deletes the pointer it holds (if any). That is, SkAutoTDelete<T > 88 automatically deletes the pointer it holds (if any). That is, SkAutoTDelete<T >
89 owns the T object that it points to. Like a T*, an SkAutoTDelete<T> may hold 89 owns the T object that it points to. Like a T*, an SkAutoTDelete<T> may hold
90 either NULL or a pointer to a T object. Also like T*, SkAutoTDelete<T> is 90 either NULL or a pointer to a T object. Also like T*, SkAutoTDelete<T> is
91 thread-compatible, and once you dereference it, you get the threadsafety 91 thread-compatible, and once you dereference it, you get the threadsafety
92 guarantees of T. 92 guarantees of T.
93 93
94 The size of a SkAutoTDelete is small: sizeof(SkAutoTDelete<T>) == sizeof(T*) 94 The size of a SkAutoTDelete is small: sizeof(SkAutoTDelete<T>) == sizeof(T*)
95 */ 95 */
96 template <typename T> class SkAutoTDelete : public std::unique_ptr<T> { 96 template <typename T> class SkAutoTDelete : public skstd::unique_ptr<T> {
97 public: 97 public:
98 SkAutoTDelete(T* obj = NULL) : std::unique_ptr<T>(obj) {} 98 SkAutoTDelete(T* obj = NULL) : skstd::unique_ptr<T>(obj) {}
99 99
100 operator T*() const { return this->get(); } 100 operator T*() const { return this->get(); }
101 void free() { this->reset(nullptr); } 101 void free() { this->reset(nullptr); }
102 T* detach() { return this->release(); } 102 T* detach() { return this->release(); }
103 }; 103 };
104 104
105 template <typename T> class SkAutoTDeleteArray : public std::unique_ptr<T[]> { 105 template <typename T> class SkAutoTDeleteArray : public skstd::unique_ptr<T[]> {
106 public: 106 public:
107 SkAutoTDeleteArray(T array[]) : std::unique_ptr<T[]>(array) {} 107 SkAutoTDeleteArray(T array[]) : skstd::unique_ptr<T[]>(array) {}
108 108
109 void free() { this->reset(nullptr); } 109 void free() { this->reset(nullptr); }
110 T* detach() { return this->release(); } 110 T* detach() { return this->release(); }
111 }; 111 };
112 112
113 /** Allocate an array of T elements, and free the array in the destructor 113 /** Allocate an array of T elements, and free the array in the destructor
114 */ 114 */
115 template <typename T> class SkAutoTArray : SkNoncopyable { 115 template <typename T> class SkAutoTArray : SkNoncopyable {
116 public: 116 public:
117 SkAutoTArray() { 117 SkAutoTArray() {
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 * Returns void* because this object does not initialize the 473 * Returns void* because this object does not initialize the
474 * memory. Use placement new for types that require a cons. 474 * memory. Use placement new for types that require a cons.
475 */ 475 */
476 void* get() { return fStorage.get(); } 476 void* get() { return fStorage.get(); }
477 const void* get() const { return fStorage.get(); } 477 const void* get() const { return fStorage.get(); }
478 private: 478 private:
479 SkAlignedSStorage<sizeof(T)*N> fStorage; 479 SkAlignedSStorage<sizeof(T)*N> fStorage;
480 }; 480 };
481 481
482 #endif 482 #endif
OLDNEW
« no previous file with comments | « include/private/SkOncePtr.h ('k') | include/private/SkUniquePtr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698