reference.h 1.3 KB

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