IDS peak AFL v2.0.2
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 template <typename... Args>
36 static T CreateInstance(Args&&... args);
37 static peak::common::detail::c_type_of_t<T> CreateCType(const T& instance);
38 static std::vector<T> CreateInstances(std::vector<handle_of_t<T>> handles);
39};
40
41template <typename T>
42handle_of_t<T> BackendAccessor<T>::BackendHandle(const T& instance)
43{
44 return instance.GetHandle();
45}
46
47template <typename T>
48handle_of_t<T>* BackendAccessor<T>::BackendHandleAddress(T& instance)
49{
50 return instance.GetHandleAddress();
51}
52
53template <typename T>
54template <typename... Args>
55T BackendAccessor<T>::CreateInstance(Args&&... args)
56{
57 return T{ std::forward<Args>(args)... };
58}
59
60template <typename T>
61peak::common::detail::c_type_of_t<T> BackendAccessor<T>::CreateCType(const T& instance)
62{
63 return { static_cast<peak::common::detail::c_type_of_t<T>>(instance) };
64}
65
66template <typename T>
67std::vector<T> BackendAccessor<T>::CreateInstances(std::vector<handle_of_t<T>> handles)
68{
69 std::vector<T> instances;
70 instances.reserve(handles.size());
71 std::transform(handles.begin(), handles.end(), std::back_inserter(instances), [](const auto& handle) {
72 return CreateInstance(handle);
73 });
74
75 return instances;
76}
77
78} // namespace detail
79} // namespace common
80} // namespace peak
81
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