35 static_assert(std::is_trivial_v<T>);
47 : native_(std::move(
native)) {}
62 constexpr operator T&()
noexcept {
67 constexpr operator const T&()
const noexcept {
87 constexpr const T*
handle() const noexcept {
93 std::swap(this->
native(), other.native());
102 constexpr const T&
native() const noexcept {
121 template <
typename U>
122 static std::true_type check(
const Wrapper<U>&);
123 static std::false_type check(...);
125 using type =
decltype(check(std::declval<T&>()));
126 static constexpr bool value = type::value;
130constexpr bool isWrapper = IsWrapper<T>::value;
138template <
typename WrapperType>
139struct WrapperConversion {
140 static_assert(isWrapper<WrapperType>);
141 static_assert(std::is_standard_layout_v<WrapperType>);
143 using NativeType =
typename WrapperType::NativeType;
146 static constexpr WrapperType*
asWrapper(NativeType* native)
noexcept {
147 return static_cast<WrapperType*
>(
static_cast<void*
>(native));
150 static constexpr const WrapperType*
asWrapper(
const NativeType* native)
noexcept {
151 return static_cast<const WrapperType*
>(
static_cast<const void*
>(native));
154 static constexpr WrapperType&
asWrapper(NativeType& native)
noexcept {
158 static constexpr const WrapperType&
asWrapper(
const NativeType& native)
noexcept {
162 static constexpr NativeType*
asNative(WrapperType* wrapper)
noexcept {
163 return static_cast<NativeType*
>(
static_cast<void*
>(wrapper));
166 static constexpr const NativeType*
asNative(
const WrapperType* wrapper)
noexcept {
167 return static_cast<const NativeType*
>(
static_cast<const void*
>(wrapper));
170 static constexpr NativeType&
asNative(WrapperType& wrapper)
noexcept {
174 static constexpr const NativeType&
asNative(
const WrapperType& wrapper)
noexcept {
192template <
typename WrapperType,
typename NativeType =
typename WrapperType::NativeType>
194 return detail::WrapperConversion<WrapperType>::asWrapper(native);
199template <
typename WrapperType,
typename NativeType =
typename WrapperType::NativeType>
201 return detail::WrapperConversion<WrapperType>::asWrapper(native);
207template <
typename WrapperType,
typename NativeType =
typename WrapperType::NativeType>
209 return detail::WrapperConversion<WrapperType>::asWrapper(native);
214template <
typename WrapperType,
typename NativeType =
typename WrapperType::NativeType>
216 return detail::WrapperConversion<WrapperType>::asWrapper(native);
222template <
typename WrapperType,
typename NativeType =
typename WrapperType::NativeType>
224 return detail::WrapperConversion<WrapperType>::asNative(wrapper);
229template <
typename WrapperType,
typename NativeType =
typename WrapperType::NativeType>
231 return detail::WrapperConversion<WrapperType>::asNative(wrapper);
237template <
typename WrapperType,
typename NativeType =
typename WrapperType::NativeType>
239 return detail::WrapperConversion<WrapperType>::asNative(wrapper);
244template <
typename WrapperType,
typename NativeType =
typename WrapperType::NativeType>
246 return detail::WrapperConversion<WrapperType>::asNative(wrapper);
Client * asWrapper(UA_Client *client) noexcept
Convert native UA_Client pointer to its wrapper instance.
Template base class to wrap native objects.
constexpr Wrapper & operator=(const T &native) noexcept
Copy assignment with native object.
constexpr void swap(Wrapper &other) noexcept
Swap with wrapper object.
constexpr const T * operator->() const noexcept
Member access to native object.
constexpr T * operator->() noexcept
Member access to native object.
constexpr const T & native() const noexcept
constexpr const T * handle() const noexcept
Return pointer to native object.
constexpr T & native() noexcept
constexpr T * handle() noexcept
Return pointer to native object.
constexpr void swap(T &native) noexcept
Swap with native object.
constexpr Wrapper(T &&native) noexcept
Move constructor with native object.
constexpr Wrapper() noexcept=default
constexpr Wrapper & operator=(T &&native) noexcept
Move assignment with native object.
constexpr WrapperType & asWrapper(NativeType &native) noexcept
Cast native object references to Wrapper object references.
constexpr NativeType * asNative(WrapperType *wrapper) noexcept
Cast Wrapper object pointers to native object pointers.
constexpr const WrapperType & asWrapper(const NativeType &native) noexcept
Cast native object references to Wrapper object references.
constexpr WrapperType * asWrapper(NativeType *native) noexcept
Cast native object pointers to Wrapper object pointers.
constexpr NativeType & asNative(WrapperType &wrapper) noexcept
Cast Wrapper object references to native object references.
constexpr const WrapperType * asWrapper(const NativeType *native) noexcept
Cast native object pointers to Wrapper object pointers.
constexpr const NativeType & asNative(const WrapperType &wrapper) noexcept
Cast Wrapper object references to native object references.
constexpr const NativeType * asNative(const WrapperType *wrapper) noexcept
Cast Wrapper object pointers to native object pointers.