CTK  0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
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 
25 namespace ctk {
26 namespace CmdLineModuleBackendFunctionPointer {
27 
28 struct NullType {};
29 
30 template<bool flag, typename T, typename U>
31 struct Select
32 {
33  typedef T Result;
34 };
35 
36 template<typename T, typename U>
37 struct Select<false, T, U>
38 {
39  typedef U Result;
40 };
41 
42 template<typename T>
44 {
45 private:
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 
77 public:
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 
89 template<bool C, typename T = void>
90 struct EnableIf
91 {
92  typedef T Type;
93 };
94 
95 template<typename T>
96 struct EnableIf<false, T> {};
97 
98 template<typename, typename>
99 struct IsSame
100 {
101  static bool const value = false;
102 };
103 
104 template<typename A>
105 struct IsSame<A, A>
106 {
107  static bool const value = true;
108 };
109 
110 template<typename B, typename D>
111 struct IsBaseOf
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, typename UnConst< PointeeType >::Result, typename Select< isReference, typename UnConst< ReferenceType >::Result, typename UnConst< T >::Result >::Result >::Result RawType