1 // Copyright 2013 The Flutter Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef FLUTTER_FML_MEMORY_REF_PTR_INTERNAL_H_ 6 #define FLUTTER_FML_MEMORY_REF_PTR_INTERNAL_H_ 7 8 #include <utility> 9 10 #include "flutter/fml/macros.h" 11 12 namespace fml { 13 14 template <typename T> 15 class RefPtr; 16 17 template <typename T> 18 RefPtr<T> AdoptRef(T* ptr); 19 20 namespace internal { 21 22 // This is a wrapper class that can be friended for a particular |T|, if you 23 // want to make |T|'s constructor private, but still use |MakeRefCounted()| 24 // (below). (You can't friend partial specializations.) See |MakeRefCounted()| 25 // and |FML_FRIEND_MAKE_REF_COUNTED()|. 26 template <typename T> 27 class MakeRefCountedHelper final { 28 public: 29 template <typename... Args> MakeRefCounted(Args &&...args)30 static RefPtr<T> MakeRefCounted(Args&&... args) { 31 return AdoptRef<T>(new T(std::forward<Args>(args)...)); 32 } 33 }; 34 35 } // namespace internal 36 } // namespace fml 37 38 #endif // FLUTTER_FML_MEMORY_REF_PTR_INTERNAL_H_ 39