1// Copyright 2019 The SwiftShader Authors. All Rights Reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef rr_Traits_inl
16#define rr_Traits_inl
17
18namespace rr
19{
20 // Non-specialized implementation of CToReactorPtr::cast() defaults to
21 // returning a ConstantPointer for v.
22 template<typename T, typename ENABLE>
23 Pointer<Byte> CToReactorPtr<T, ENABLE>::cast(const T* v)
24 {
25 return ConstantPointer(v);
26 }
27
28 // CToReactorPtr specialization for T types that have a CToReactorT<>
29 // specialization.
30 template<typename T>
31 Pointer<CToReactorT<T>>
32 CToReactorPtr<T, typename std::enable_if< IsDefined< CToReactorT<T> >::value>::type >::cast(const T* v)
33 {
34 return type(v);
35 }
36
37 // CToReactorPtr specialization for void*.
38 Pointer<Byte> CToReactorPtr<void, void>::cast(const void* v)
39 {
40 return ConstantPointer(v);
41 }
42
43 // CToReactorPtrT specialization for function pointer types.
44 template<typename T>
45 Pointer<Byte>
46 CToReactorPtr<T, typename std::enable_if< std::is_function<T>::value >::type>::cast(T* v)
47 {
48 return ConstantPointer(v);
49 }
50
51 // CToReactor specialization for pointer types.
52 template<typename T>
53 CToReactorPtrT<typename std::remove_pointer<T>::type>
54 CToReactor<T, typename std::enable_if<std::is_pointer<T>::value>::type>::cast(T v)
55 {
56 return CToReactorPtr<elem>::cast(v);
57 }
58
59 // CToReactor specialization for enum types.
60 template<typename T>
61 CToReactorT<typename std::underlying_type<T>::type>
62 CToReactor<T, typename std::enable_if<std::is_enum<T>::value>::type>::cast(T v)
63 {
64 return CToReactor<underlying>::cast(v);
65 }
66
67} // namespace rr
68
69#endif // rr_Traits_inl
70