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

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

Issue 1330503006: Add skstd::unique_ptr and use it. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Formatting. Created 5 years, 3 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/gpu/gl/GrGLExtensions.h ('k') | include/private/SkTLogic.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 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkFunction_DEFINED 8 #ifndef SkFunction_DEFINED
9 #define SkFunction_DEFINED 9 #define SkFunction_DEFINED
10 10
11 // TODO: document, more pervasive move support in constructors, small-Fn optimiz ation 11 // TODO: document, more pervasive move support in constructors, small-Fn optimiz ation
12 12
13 #include "SkTemplates.h" 13 #include "SkUtility.h"
14 #include "SkUniquePtr.h"
14 #include "SkTypes.h" 15 #include "SkTypes.h"
15 16
16 template <typename> class SkFunction; 17 template <typename> class SkFunction;
17 18
18 template <typename R, typename... Args> 19 template <typename R, typename... Args>
19 class SkFunction<R(Args...)> { 20 class SkFunction<R(Args...)> {
20 public: 21 public:
21 SkFunction() {} 22 SkFunction() {}
22 23
23 template <typename Fn> 24 template <typename Fn>
24 SkFunction(const Fn& fn) 25 SkFunction(const Fn& fn)
25 : fFunction(new LambdaImpl<Fn>(fn)) {} 26 : fFunction(new LambdaImpl<Fn>(fn)) {}
26 27
27 SkFunction(R (*fn)(Args...)) : fFunction(new FnPtrImpl(fn)) {} 28 SkFunction(R (*fn)(Args...)) : fFunction(new FnPtrImpl(fn)) {}
28 29
29 SkFunction(const SkFunction& other) { *this = other; } 30 SkFunction(const SkFunction& other) { *this = other; }
30 SkFunction& operator=(const SkFunction& other) { 31 SkFunction& operator=(const SkFunction& other) {
31 if (this != &other) { 32 if (this != &other) {
32 fFunction.reset(other.fFunction ? other.fFunction->clone() : nullptr ); 33 fFunction.reset(other.fFunction.get() ? other.fFunction->clone() : n ullptr);
33 } 34 }
34 return *this; 35 return *this;
35 } 36 }
36 37
37 R operator()(Args... args) const { 38 R operator()(Args... args) const {
38 SkASSERT(fFunction.get()); 39 SkASSERT(fFunction.get());
39 return fFunction->call(skstd::forward<Args>(args)...); 40 return fFunction->call(skstd::forward<Args>(args)...);
40 } 41 }
41 42
42 private: 43 private:
(...skipping 19 matching lines...) Expand all
62 public: 63 public:
63 FnPtrImpl(R (*fn)(Args...)) : fFn(fn) {} 64 FnPtrImpl(R (*fn)(Args...)) : fFn(fn) {}
64 65
65 R call(Args... args) const override { return fFn(skstd::forward<Args>(ar gs)...); } 66 R call(Args... args) const override { return fFn(skstd::forward<Args>(ar gs)...); }
66 Interface* clone() const override { return new FnPtrImpl(fFn); } 67 Interface* clone() const override { return new FnPtrImpl(fFn); }
67 68
68 private: 69 private:
69 R (*fFn)(Args...); 70 R (*fFn)(Args...);
70 }; 71 };
71 72
72 SkAutoTDelete<Interface> fFunction; 73 skstd::unique_ptr<Interface> fFunction;
73 }; 74 };
74 75
75 #endif//SkFunction_DEFINED 76 #endif//SkFunction_DEFINED
OLDNEW
« no previous file with comments | « include/gpu/gl/GrGLExtensions.h ('k') | include/private/SkTLogic.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698