olp-cpp-sdk  1.22.0
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 
29 namespace olp {
30 namespace thread {
31 namespace internal {
32 
34 template <typename Type>
36  using type =
37  typename std::remove_cv<typename std::remove_reference<Type>::type>::type;
38 };
39 
41 template <typename Type>
42 using RemoveRefAndConst = typename RemoveRefAndConstImpl<Type>::type;
43 
47 template <typename Type>
49  using type =
50  typename std::conditional<std::is_same<Type, std::vector<void>>::value,
51  void, Type>::type;
52 };
53 
55 template <typename Type>
57  using type = std::function<void(Type)>;
58 };
59 
61 template <>
63  using type = std::function<void()>;
64 };
65 
66 template <typename Type>
68 using TypeToFunctionInput = typename TypeToFunctionInputImpl<Type>::type;
69 
70 template <typename Class, typename ExecutionContext, typename Arg>
72 Arg SecondArgType(void (Class::*)(ExecutionContext, Arg) const);
73 
74 template <typename Class, typename ExecutionContext, typename Arg>
76 Arg SecondArgType(void (Class::*)(ExecutionContext, Arg));
77 
78 template <typename Class, typename Some, typename ExecutionContext,
79  typename Arg>
81 Arg ThirdArgType(void (Class::*)(Some, ExecutionContext, Arg) const);
82 
83 template <typename Class, typename Some, typename ExecutionContext,
84  typename Arg>
86 Arg ThirdArgType(void (Class::*)(Some, ExecutionContext, Arg));
87 
89 void FuncArgType(std::function<void()>);
90 
92 template <typename Arg>
93 Arg FuncArgType(std::function<void(Arg)>);
94 
95 template <typename Callable>
98  using FirstArgType =
99  RemoveRefAndConst<decltype(SecondArgType(&Callable::operator()))>;
100  using type = RemoveRefAndConst<decltype(FuncArgType(FirstArgType()))>;
101 };
102 
103 template <typename Callable>
105 using AsyncResultType = typename AsyncResultTypeImpl<Callable>::type;
106 
107 template <typename Callable>
110  using ThirdArgTypeParam =
111  RemoveRefAndConst<decltype(ThirdArgType(&Callable::operator()))>;
112  using type = RemoveRefAndConst<decltype(FuncArgType(ThirdArgTypeParam()))>;
113 };
114 
115 template <typename Callable>
117 using DeducedType = typename DeducedTypeImpl<Callable>::type;
118 
122  virtual void* Get() const = 0;
123  virtual ~UntypedSmartPointer() = default;
124 };
125 
127 template <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 
140 template <typename SmartPointer>
141 inline 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