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

Unified Diff: include/private/SkTemplates.h

Issue 1436033003: skstd -> std for unique_ptr (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: more functions Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/private/SkOncePtr.h ('k') | include/private/SkUniquePtr.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/private/SkTemplates.h
diff --git a/include/private/SkTemplates.h b/include/private/SkTemplates.h
index 496cf427337664d82ed499412e67168af14f8f5b..9776a99631372e46edb0c3a1494910507c19a0ad 100644
--- a/include/private/SkTemplates.h
+++ b/include/private/SkTemplates.h
@@ -13,8 +13,8 @@
#include "SkMath.h"
#include "SkTLogic.h"
#include "SkTypes.h"
-#include "SkUniquePtr.h"
#include <limits.h>
+#include <memory>
#include <new>
/** \file SkTemplates.h
@@ -57,13 +57,18 @@ template <typename R, typename T, R (*P)(T*)> struct SkFunctionWrapper {
reference is null when the destructor is called, we do not call the
function.
*/
-template <typename T, void (*P)(T*)> class SkAutoTCallVProc
- : public skstd::unique_ptr<T, SkFunctionWrapper<void, T, P>> {
+template <typename T, void (*P)(T*)> class SkAutoTCallVProc {
public:
- SkAutoTCallVProc(T* obj): skstd::unique_ptr<T, SkFunctionWrapper<void, T, P>>(obj) {}
+ SkAutoTCallVProc(T* obj) : fPtr(obj) {}
- operator T*() const { return this->get(); }
- T* detach() { return this->release(); }
+ T* get() const { return fPtr.get(); }
+ operator T* () const { return fPtr.get(); }
+ T* operator->() const { return fPtr.get(); }
+
+ T* detach() { return fPtr.release(); }
+ void reset(T* ptr = nullptr) { fPtr.reset(ptr); }
+private:
+ std::unique_ptr<T, SkFunctionWrapper<void, T, P>> fPtr;
};
/** \class SkAutoTCallIProc
@@ -74,13 +79,18 @@ If detach() is called, the object reference is set to null. If the object
reference is null when the destructor is called, we do not call the
function.
*/
-template <typename T, int (*P)(T*)> class SkAutoTCallIProc
- : public skstd::unique_ptr<T, SkFunctionWrapper<int, T, P>> {
+template <typename T, int (*P)(T*)> class SkAutoTCallIProc {
public:
- SkAutoTCallIProc(T* obj): skstd::unique_ptr<T, SkFunctionWrapper<int, T, P>>(obj) {}
+ SkAutoTCallIProc(T* obj) : fPtr(obj) {}
- operator T*() const { return this->get(); }
- T* detach() { return this->release(); }
+ T* get() const { return fPtr.get(); }
+ operator T* () const { return fPtr.get(); }
+ T* operator->() const { return fPtr.get(); }
+
+ T* detach() { return fPtr.release(); }
+ void reset(T* ptr = nullptr) { fPtr.reset(ptr); }
+private:
+ std::unique_ptr<T, SkFunctionWrapper<int, T, P>> fPtr;
};
/** \class SkAutoTDelete
@@ -93,18 +103,27 @@ public:
The size of a SkAutoTDelete is small: sizeof(SkAutoTDelete<T>) == sizeof(T*)
*/
-template <typename T> class SkAutoTDelete : public skstd::unique_ptr<T> {
+template <typename T> class SkAutoTDelete {
public:
- SkAutoTDelete(T* obj = NULL) : skstd::unique_ptr<T>(obj) {}
+ SkAutoTDelete(T* obj = NULL) : fPtr(obj) {}
- operator T*() const { return this->get(); }
- void free() { this->reset(nullptr); }
- T* detach() { return this->release(); }
+ void swap(SkAutoTDelete& other) { fPtr.swap(other.fPtr); }
+
+ T* get() const { return fPtr.get(); }
+ operator T* () const { return fPtr.get(); }
+ T* operator->() const { return fPtr.get(); }
+
+ void reset(T* ptr = nullptr) { fPtr.reset(ptr); }
+ void free() { fPtr.reset(nullptr); }
+ T* detach() { return fPtr.release(); }
+ T* release() { return fPtr.release(); }
+private:
+ std::unique_ptr<T> fPtr;
};
-template <typename T> class SkAutoTDeleteArray : public skstd::unique_ptr<T[]> {
+template <typename T> class SkAutoTDeleteArray : public std::unique_ptr<T[]> {
public:
- SkAutoTDeleteArray(T array[]) : skstd::unique_ptr<T[]>(array) {}
+ SkAutoTDeleteArray(T array[]) : std::unique_ptr<T[]>(array) {}
void free() { this->reset(nullptr); }
T* detach() { return this->release(); }
« 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