diff options
author | mtklein <mtklein@chromium.org> | 2015-07-01 11:55:42 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-07-01 11:55:42 -0700 |
commit | 928e16565f3e69cd6661e9ad300ac17e3f33c0c8 (patch) | |
tree | 919a82a34f8dba53523ac8a21b168f9895c176b0 /src/core/SkFunction.h | |
parent | ebaf6a69bf604c85185e23aca3fb93308e747ff5 (diff) |
Move headers used by headers in include/ to include/private.
Some of this is transitive, like SkRecords.h used by SkMiniRecorder.h
used by (public) SkPictureRecorder.h.
BUG=skia:
Committed: https://skia.googlesource.com/skia/+/a89f55198bdc58f0b6f6196907ab25a6afc1a661
Review URL: https://codereview.chromium.org/1217293004
Diffstat (limited to 'src/core/SkFunction.h')
-rw-r--r-- | src/core/SkFunction.h | 75 |
1 files changed, 0 insertions, 75 deletions
diff --git a/src/core/SkFunction.h b/src/core/SkFunction.h deleted file mode 100644 index 429c6f5ade..0000000000 --- a/src/core/SkFunction.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2015 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkFunction_DEFINED -#define SkFunction_DEFINED - -// TODO: document, more pervasive move support in constructors, small-Fn optimization - -#include "SkTemplates.h" -#include "SkTypes.h" - -template <typename> class SkFunction; - -template <typename R, typename... Args> -class SkFunction<R(Args...)> { -public: - SkFunction() {} - - template <typename Fn> - SkFunction(const Fn& fn) : fFunction(SkNEW_ARGS(LambdaImpl<Fn>, (fn))) {} - - SkFunction(R (*fn)(Args...)) : fFunction(SkNEW_ARGS(FnPtrImpl, (fn))) {} - - SkFunction(const SkFunction& other) { *this = other; } - SkFunction& operator=(const SkFunction& other) { - if (this != &other) { - fFunction.reset(other.fFunction ? other.fFunction->clone() : nullptr); - } - return *this; - } - - R operator()(Args... args) const { - SkASSERT(fFunction.get()); - return fFunction->call(Forward(args)...); - } - -private: - // ~= std::forward. This moves its argument if possible, falling back to a copy if not. - template <typename T> static T&& Forward(T& v) { return (T&&)v; } - - struct Interface { - virtual ~Interface() {} - virtual R call(Args...) const = 0; - virtual Interface* clone() const = 0; - }; - - template <typename Fn> - class LambdaImpl final : public Interface { - public: - LambdaImpl(const Fn& fn) : fFn(fn) {} - - R call(Args... args) const override { return fFn(Forward(args)...); } - Interface* clone() const { return SkNEW_ARGS(LambdaImpl<Fn>, (fFn)); } - private: - Fn fFn; - }; - - class FnPtrImpl final : public Interface { - public: - FnPtrImpl(R (*fn)(Args...)) : fFn(fn) {} - - R call(Args... args) const override { return fFn(Forward(args)...); } - Interface* clone() const { return SkNEW_ARGS(FnPtrImpl, (fFn)); } - private: - R (*fFn)(Args...); - }; - - SkAutoTDelete<Interface> fFunction; -}; - -#endif//SkFunction_DEFINED |