3#if PL_DISABLED(PL_PLATFORM_WINDOWS_UWP)
4# error "uwp util header should only be included in UWP builds!"
7#include <Foundation/Basics/Platform/Win/HResultUtils.h>
8#include <Foundation/Types/Types.h>
10#include <Foundation/Basics/Platform/Win/IncludeWindows.h>
14#include <windows.foundation.collections.h>
15#include <windows.foundation.h>
16#include <windows.foundation.numerics.h>
17#include <wrl/client.h>
19#include <wrl/implements.h>
20#include <wrl/wrappers/corewrappers.h>
24using namespace Microsoft::WRL::Wrappers;
25using namespace Microsoft::WRL;
32 template <
typename ElementQueryType,
typename ElementType,
typename Callback>
33 HRESULT plWinRtIterateIVectorView(
34 const ComPtr<ABI::Windows::Foundation::Collections::IVectorView<ElementType>>& pVectorView,
const Callback& callback)
37 HRESULT result = pVectorView->get_Size(&numElements);
41 for (UINT i = 0; i < numElements; ++i)
43 ElementQueryType pElement;
44 result = pVectorView->GetAt(i, &pElement);
48 if (!callback(i, pElement))
58 template <
typename ValueInterfaceType,
typename KeyType,
typename ValueType,
typename Callback>
59 void plWinRtIterateIMapView(
const ComPtr<ABI::Windows::Foundation::Collections::IMapView<KeyType, ValueType>>& pMapView,
const Callback& callback)
61 using namespace ABI::Windows::Foundation::Collections;
62 using namespace ABI::Windows::Foundation::Internal;
64 using MapInterface = IIterable<IKeyValuePair<KeyType, GetLogicalType<ValueType>::type>*>;
66 ComPtr<MapInterface> pIterable;
67 pMapView->QueryInterface<MapInterface>(&pIterable);
69 PL_ASSERT_DEBUG(pIterable !=
nullptr,
"Invalid map iteration interface");
71 ComPtr<IIterator<IKeyValuePair<KeyType, ValueType>*>> iterator;
72 pIterable->First(&iterator);
74 boolean hasCurrent = FALSE;
75 iterator->get_HasCurrent(&hasCurrent);
77 while (hasCurrent == TRUE)
79 IKeyValuePair<KeyType, ValueType>* pair;
80 iterator->get_Current(&pair);
85 ValueInterfaceType value;
86 pair->get_Value(&value);
88 if (!callback(key, value))
91 iterator->MoveNext(&hasCurrent);
104 template <
typename AsyncCompletedType,
typename AsyncResultType,
typename Callback,
typename ObjectType>
105 HRESULT plWinRtPutCompleted(ObjectType&
object, Callback callback)
107 object->put_Completed(Microsoft::WRL::Callback<ABI::Windows::Foundation::IAsyncOperationCompletedHandler<AsyncCompletedType>>(
108 [callback](ABI::Windows::Foundation::IAsyncOperation<AsyncCompletedType>* pCompletion, AsyncStatus status)
110 if (status != ABI::Windows::Foundation::AsyncStatus::Completed)
113 AsyncResultType pResult;
114 pCompletion->GetResults(&pResult);
125 template <
typename T>
126 void RetrieveStatics(
const WCHAR* szRuntimeClassName, ComPtr<T>& out_Ptr)
128 if (FAILED(ABI::Windows::Foundation::GetActivationFactory(HStringReference(szRuntimeClassName).Get(), &out_Ptr)))
130 PL_REPORT_FAILURE(
"Failed to retrieve activation factory (statics) for '{0}'",
plStringUtf8(szRuntimeClassName).GetData());
139 template <
typename T>
140 void CreateInstance(
const WCHAR* szRuntimeClassName, ComPtr<T>& out_Ptr)
142 ::RoActivateInstance(HStringReference(szRuntimeClassName).Get(), &out_Ptr);
145 plMat4 PL_FOUNDATION_DLL ConvertMat4(
const ABI::Windows::Foundation::Numerics::Matrix4x4& in);
147 plVec3 PL_FOUNDATION_DLL ConvertVec3(
const ABI::Windows::Foundation::Numerics::Vector3& in);
148 void PL_FOUNDATION_DLL ConvertVec3(
const plVec3& in, ABI::Windows::Foundation::Numerics::Vector3& out);
150 plQuat PL_FOUNDATION_DLL ConvertQuat(
const ABI::Windows::Foundation::Numerics::Quaternion& in);
151 void PL_FOUNDATION_DLL ConvertQuat(
const plQuat& in, ABI::Windows::Foundation::Numerics::Quaternion& out);
153 plUuid PL_FOUNDATION_DLL ConvertGuid(
const GUID& in);
154 void PL_FOUNDATION_DLL ConvertGuid(
const plUuid& in, GUID& out);
A small string class that converts any other encoding to Utf8.
Definition StringConversion.h:47
This data type is the abstraction for 128-bit Uuid (also known as GUID) instances.
Definition Uuid.h:11