IDS peak AFL v2.0.1
Loading...
Searching...
No Matches
peak_common_backend_accessor.hpp
Go to the documentation of this file.
1
10
11#pragma once
12
13
15
16#include <algorithm>
17#include <iterator>
18#include <vector>
19
21namespace peak
22{
23namespace common
24{
25
26namespace detail
27{
28
29template <typename T>
30class BackendAccessor
31{
32public:
33 static handle_of_t<T> BackendHandle(const T& instance);
34 static handle_of_t<T>* BackendHandleAddress(T& instance);
35 static T CreateInstance(const c_type_of_t<T>& structure);
36 static T CreateInstance(handle_of_t<T> structure);
37 static T CreateInstance();
38 static peak::common::detail::c_type_of_t<T> CreateCType(const T& instance);
39 static std::vector<T> CreateInstances(std::vector<handle_of_t<T>> handles);
40};
41
42template <typename T>
43handle_of_t<T> BackendAccessor<T>::BackendHandle(const T& instance)
44{
45 return instance.GetHandle();
46}
47
48template <typename T>
49handle_of_t<T>* BackendAccessor<T>::BackendHandleAddress(T& instance)
50{
51 return instance.GetHandleAddress();
52}
53
54template <typename T>
55T BackendAccessor<T>::CreateInstance(const c_type_of_t<T>& structure)
56{
57 return T{ structure };
58}
59
60template <typename T>
61T BackendAccessor<T>::CreateInstance(handle_of_t<T> structure)
62{
63 return T{ structure };
64}
65
66template <typename T>
67T BackendAccessor<T>::CreateInstance()
68{
69 return {};
70}
71
72template <typename T>
73peak::common::detail::c_type_of_t<T> BackendAccessor<T>::CreateCType(const T& instance)
74{
75 return { static_cast<peak::common::detail::c_type_of_t<T>>(instance) };
76}
77
78template <typename T>
79std::vector<T> BackendAccessor<T>::CreateInstances(std::vector<handle_of_t<T>> handles)
80{
81 std::vector<T> instances;
82 instances.reserve(handles.size());
83 std::transform(handles.begin(), handles.end(), std::back_inserter(instances), [](const auto& handle) {
84 return CreateInstance(handle);
85 });
86
87 return instances;
88}
89
90} // namespace detail
91} // namespace common
92} // namespace peak
93
Namespace for internal implementation details and low-level types.
Definition peak_common_math.hpp:24
Root namespace for common types and interfaces shared across multiple libraries.
Definition peak_common_math.hpp:22