CTK 0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
Loading...
Searching...
No Matches
ctkCmdLineModuleBackendFPTypeTraits.h
Go to the documentation of this file.
1/*=============================================================================
2
3 Library: CTK
4
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics
7
8 Licensed under the Apache License, Version 2.0 (the "License");
9 you may not use this file except in compliance with the License.
10 You may obtain a copy of the License at
11
12 http://www.apache.org/licenses/LICENSE-2.0
13
14 Unless required by applicable law or agreed to in writing, software
15 distributed under the License is distributed on an "AS IS" BASIS,
16 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 See the License for the specific language governing permissions and
18 limitations under the License.
19
20=============================================================================*/
21
22#ifndef CTKCMDLINEMODULEBACKENDFPTYPETRAITS_H
23#define CTKCMDLINEMODULEBACKENDFPTYPETRAITS_H
24
25namespace ctk {
26namespace CmdLineModuleBackendFunctionPointer {
27
28struct NullType {};
29
30template<bool flag, typename T, typename U>
31struct Select
32{
33 typedef T Result;
34};
35
36template<typename T, typename U>
37struct Select<false, T, U>
38{
39 typedef U Result;
40};
41
42template<typename T>
44{
45private:
46
47 template<class U> struct PointerTraits
48 {
49 enum { result = false };
50 typedef NullType PointeeType;
51 };
52 template<class U> struct PointerTraits<U*>
53 {
54 enum { result = true };
55 typedef U PointeeType;
56 };
57 template<class U> struct ReferenceTraits
58 {
59 enum { result = false };
60 typedef NullType ReferenceType;
61 };
62 template<class U> struct ReferenceTraits<U&>
63 {
64 enum { result = true };
65 typedef U ReferenceType;
66 };
67
68 template<class U> struct UnConst
69 {
70 typedef U Result;
71 };
72 template<class U> struct UnConst<const U>
73 {
74 typedef U Result;
75 };
76
77public:
78
81
82 enum { isPointer = PointerTraits<T>::result };
83 enum { isReference = ReferenceTraits<T>::result };
84
86 typename Select<isReference, typename UnConst<ReferenceType>::Result, typename UnConst<T>::Result>::Result >::Result RawType;
87};
88
89template<bool C, typename T = void>
91{
92 typedef T Type;
93};
94
95template<typename T>
96struct EnableIf<false, T> {};
97
98template<typename, typename>
99struct IsSame
100{
101 static bool const value = false;
102};
103
104template<typename A>
105struct IsSame<A, A>
106{
107 static bool const value = true;
108};
109
110template<typename B, typename D>
112{
113 static D* MakeD();
114 static char (& Test(B*))[1];
115 static char (& Test(...))[2];
116 static bool const value = sizeof Test(MakeD()) == 1 &&
118};
119
120
121}
122}
123
124
125#endif // CTKCMDLINEMODULEBACKENDFPTYPETRAITS_H
Select< isPointer, typenameUnConst< PointeeType >::Result, typenameSelect< isReference, typenameUnConst< ReferenceType >::Result, typenameUnConst< T >::Result >::Result >::Result RawType