olp-cpp-sdk 1.24.0
Loading...
Searching...
No Matches
TypeHelpers.h
1/*
2 * Copyright (C) 2022 HERE Europe B.V.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * SPDX-License-Identifier: Apache-2.0
17 * License-Filename: LICENSE
18 */
19
20#pragma once
21
22#include <functional>
23#include <type_traits>
24#include <vector>
25
26#include <olp/core/client/ApiError.h>
27#include <olp/core/porting/make_unique.h>
28
29namespace olp {
30namespace thread {
31namespace internal {
32
34template <typename Type>
36 using type =
37 typename std::remove_cv<typename std::remove_reference<Type>::type>::type;
38};
39
41template <typename Type>
42using RemoveRefAndConst = typename RemoveRefAndConstImpl<Type>::type;
43
47template <typename Type>
49 using type =
50 typename std::conditional<std::is_same<Type, std::vector<void>>::value,
51 void, Type>::type;
52};
53
55template <typename Type>
57 using type = std::function<void(Type)>;
58};
59
61template <>
63 using type = std::function<void()>;
64};
65
66template <typename Type>
68using TypeToFunctionInput = typename TypeToFunctionInputImpl<Type>::type;
69
70template <typename Class, typename ExecutionContext, typename Arg>
72Arg SecondArgType(void (Class::*)(ExecutionContext, Arg) const);
73
74template <typename Class, typename ExecutionContext, typename Arg>
76Arg SecondArgType(void (Class::*)(ExecutionContext, Arg));
77
78template <typename Class, typename Some, typename ExecutionContext,
79 typename Arg>
81Arg ThirdArgType(void (Class::*)(Some, ExecutionContext, Arg) const);
82
83template <typename Class, typename Some, typename ExecutionContext,
84 typename Arg>
86Arg ThirdArgType(void (Class::*)(Some, ExecutionContext, Arg));
87
89void FuncArgType(std::function<void()>);
90
92template <typename Arg>
93Arg FuncArgType(std::function<void(Arg)>);
94
95template <typename Callable>
98 using FirstArgType =
99 RemoveRefAndConst<decltype(SecondArgType(&Callable::operator()))>;
100 using type = RemoveRefAndConst<decltype(FuncArgType(FirstArgType()))>;
101};
102
103template <typename Callable>
105using AsyncResultType = typename AsyncResultTypeImpl<Callable>::type;
106
107template <typename Callable>
110 using ThirdArgTypeParam =
111 RemoveRefAndConst<decltype(ThirdArgType(&Callable::operator()))>;
112 using type = RemoveRefAndConst<decltype(FuncArgType(ThirdArgTypeParam()))>;
113};
114
115template <typename Callable>
117using DeducedType = typename DeducedTypeImpl<Callable>::type;
118
122 virtual void* Get() const = 0;
123 virtual ~UntypedSmartPointer() = default;
124};
125
127template <typename SmartPointer>
130 explicit TypedSmartPointer(SmartPointer&& pointer)
131 : pointer_(std::move(pointer)) {}
132
134 void* Get() const override { return static_cast<void*>(pointer_.get()); }
135
136 SmartPointer pointer_;
137};
138
140template <typename SmartPointer>
141inline std::unique_ptr<UntypedSmartPointer> MakeUntypedUnique(
142 SmartPointer&& ptr) {
143 return std::make_unique<TypedSmartPointer<SmartPointer>>(std::move(ptr));
144}
145
146} // namespace internal
147} // namespace thread
148} // namespace olp
Handles the cancellation and final mechanisms.
Definition ExecutionContext.h:31
Rules all the other namespaces.
Definition AppleSignInProperties.h:24
Declares the type of a callable with two parameters.
Definition TypeHelpers.h:97
Declares the type of a callable with three parameters.
Definition TypeHelpers.h:109
Definition TypeHelpers.h:48
A helper class removes type qualifiers and provides a type.
Definition TypeHelpers.h:35
A class for wrapping a type with std::function.
Definition TypeHelpers.h:56
An implementation of UntypedSmartPointer interface.
Definition TypeHelpers.h:128
TypedSmartPointer(SmartPointer &&pointer)
A move contructor.
Definition TypeHelpers.h:130
void * Get() const override
Method converts data to a void pointer.
Definition TypeHelpers.h:134
Definition TypeHelpers.h:121