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