1 // Copyright 2018 The Chromium Authors 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 BASE_WIN_REFERENCE_H_ 6 #define BASE_WIN_REFERENCE_H_ 7 8 #include <windows.foundation.collections.h> 9 #include <wrl/implements.h> 10 11 #include <type_traits> 12 #include <utility> 13 14 namespace base { 15 namespace win { 16 17 // Implementation of the UWP's IReference interface. 18 template <typename T> 19 class Reference 20 : public Microsoft::WRL::RuntimeClass< 21 Microsoft::WRL::RuntimeClassFlags< 22 Microsoft::WRL::WinRt | Microsoft::WRL::InhibitRoOriginateError>, 23 ABI::Windows::Foundation::IReference<T>> { 24 public: 25 using AbiT = typename ABI::Windows::Foundation::Internal::GetAbiType< 26 typename ABI::Windows::Foundation::IReference<T>::T_complex>::type; 27 Reference(const AbiT & value)28 explicit Reference(const AbiT& value) : value_(value) {} Reference(AbiT && value)29 explicit Reference(AbiT&& value) : value_(std::move(value)) {} 30 31 Reference(const Reference&) = delete; 32 Reference& operator=(const Reference&) = delete; 33 34 // ABI::Windows::Foundation::IReference: get_Value(AbiT * value)35 IFACEMETHODIMP get_Value(AbiT* value) override { 36 *value = value_; 37 return S_OK; 38 } 39 40 private: 41 ~Reference() override = default; 42 AbiT value_; 43 }; 44 45 } // namespace win 46 } // namespace base 47 48 #endif // BASE_WIN_REFERENCE_H_ 49