1/*
2 * Copyright 2020 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SkottieAdapter_DEFINED
9#define SkottieAdapter_DEFINED
10
11#include "modules/skottie/src/animator/Animator.h"
12
13namespace skottie {
14namespace internal {
15
16template <typename AdapterT, typename T>
17class DiscardableAdapterBase : public AnimatablePropertyContainer {
18public:
19 template <typename... Args>
20 static sk_sp<AdapterT> Make(Args&&... args) {
21 sk_sp<AdapterT> adapter(new AdapterT(std::forward<Args>(args)...));
22 adapter->shrink_to_fit();
23 return adapter;
24 }
25
26 const sk_sp<T>& node() const { return fNode; }
27
28protected:
29 DiscardableAdapterBase()
30 : fNode(T::Make()) {}
31
32 explicit DiscardableAdapterBase(sk_sp<T> node)
33 : fNode(std::move(node)) {}
34
35private:
36 const sk_sp<T> fNode;
37};
38
39} // namespace internal
40} // namespace skottie
41
42#endif // SkottieAdapter_DEFINED
43