HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SYS_TypeDecorate.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: SYS_TypeDecorate.h (SYS Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __SYS_TYPEDECORATE_H_INCLUDED__
12 #define __SYS_TYPEDECORATE_H_INCLUDED__
13 
14 #include "SYS_Compiler.h"
15 
16 // NOTE: This header is intentionally kept free of any includes,
17 // as it may itself get included in many places.
18 
19 // Define SYS_RemoveCV here instead to avoid including
20 // SYS_TypeTraits.h or type_traits in too many places.
21 
22 /// Remove topmost const/volatile qualifiers.
23 /// @{
24 
25 template< typename T >
26 struct SYS_RemoveCV { using type = T; };
27 
28 template< typename T >
29 struct SYS_RemoveCV< const T > { using type = T; };
30 
31 template< typename T >
32 struct SYS_RemoveCV< volatile T > { using type = T; };
33 
34 template< typename T >
35 struct SYS_RemoveCV< const volatile T > { using type = T; };
36 
37 template< typename T >
39 
40 /// @}
41 
42 // Primary templates for additional types that are considered,
43 // integral, floating-point, POD:
44 
45 template <typename T> struct AddIntegralNoCV { static constexpr bool value = false; };
46 template <typename T> struct AddFloatingPointNoCV { static constexpr bool value = false; };
47 template <typename T> struct AddPodNoCV { static constexpr bool value = false; };
48 
49 // Primary template:
50 // SafeTrivialRelocationNoCV indicates that trivial relocation is safe for T
51 template< typename T > struct SafeTrivialRelocationNoCV { static constexpr bool value = false; };
52 
53 // Primary template:
54 // UnsafeTrivialRelocationNoCV indicates that trivial relocation is unsafe for T
55 template< typename T > struct UnsafeTrivialRelocationNoCV { static constexpr bool value = false; };
56 
57 // Primary templates for fixed-array-like type traits
58 
59 template< typename T > struct SYS_IsFixedArrayNoCVRef { static constexpr bool value = false; };
60 template< typename T > struct SYS_FixedArrayElementNoCVRef;
61 template< typename T > struct SYS_FixedArraySizeNoCVRef;
62 
63 // SYS_HasCV: Return whether a type T has any const or volatile qualifiers
64 
65 // Primary
66 template< typename T > struct SYS_HasCV { static constexpr bool value = false; };
67 
68 template< typename T > constexpr auto SYS_HasCV_v = SYS_HasCV< T >::value;
69 
70 template< typename T > struct SYS_HasCV< const T > { static constexpr bool value = true; };
71 template< typename T > struct SYS_HasCV< volatile T > { static constexpr bool value = true; };
72 template< typename T > struct SYS_HasCV< const volatile T > { static constexpr bool value = true; };
73 
74 /// @file
75 /// Provides facilities to decorate types that can then be tested using type
76 /// traits.
77 
78 /// Declare a type as integral
79 #define SYS_DECLARE_IS_INTEGRAL(T) \
80  template<> struct AddIntegralNoCV< T > { \
81  static_assert( ( ! SYS_HasCV_v< T > ), \
82  "SYS_DECLARE_IS_INTEGRAL must be used on types without const/volatile qualifiers" ); \
83  SYS_MAYBE_UNUSED static constexpr bool value = true; \
84  };\
85  /**/
86 
87 /// Declare a type as floating point
88 #define SYS_DECLARE_IS_FLOATING_POINT(T) \
89  template<> struct AddFloatingPointNoCV< T > { \
90  static_assert( ( ! SYS_HasCV_v< T > ), \
91  "SYS_DECLARE_IS_FLOATING_POINT must be used on types without const/volatile qualifiers" ); \
92  SYS_MAYBE_UNUSED static constexpr bool value = true; \
93  };\
94  /**/
95 
96 /// Declare a type as POD
97 #define SYS_DECLARE_IS_POD(T) \
98  template<> struct AddPodNoCV< T > { \
99  static_assert( ( ! SYS_HasCV_v< T > ), \
100  "SYS_DECLARE_IS_POD must be used on types without const/volatile qualifiers" ); \
101  SYS_MAYBE_UNUSED static constexpr bool value = true; \
102  };\
103  /**/
104 
105 #define SYS_DECLARE_IS_TR_IMPL(...) \
106  struct SafeTrivialRelocationNoCV< __VA_ARGS__ > { \
107  static_assert( ( ! SYS_HasCV_v< __VA_ARGS__> ), \
108  "SYS_DECLARE_IS_TR must be used on types without const/volatile qualifiers" ); \
109  SYS_MAYBE_UNUSED static constexpr bool value = true; \
110  };\
111  /**/
112 
113 #define SYS_DECLARE_IS_NOT_TR_IMPL(...) \
114  struct UnsafeTrivialRelocationNoCV< __VA_ARGS__ > { \
115  static_assert( ( ! SYS_HasCV_v< __VA_ARGS__ > ), \
116  "SYS_DECLARE_IS_NOT_TR must be used on types without const/volatile qualifiers" ); \
117  SYS_MAYBE_UNUSED static constexpr bool value = true; \
118  };\
119  /**/
120 
121 /// Guarantee that it's safe to use trivial relocation with type T
122 #define SYS_DECLARE_IS_TR(T) template<> SYS_DECLARE_IS_TR_IMPL(T)
123 
124 /// Version for class template
125 #define SYS_DECLARE_IS_TR_TEMPLATE(...) SYS_DECLARE_IS_TR_IMPL( __VA_ARGS__ )
126 
127 /// Declare that that trivial relocation with type T is not guaranteed to be safe
128 #define SYS_DECLARE_IS_NOT_TR(T) template<> SYS_DECLARE_IS_NOT_TR_IMPL(T)
129 
130 /// Version for class template
131 #define SYS_DECLARE_IS_NOT_TR_TEMPLATE(...) SYS_DECLARE_IS_NOT_TR_IMPL( __VA_ARGS__ )
132 
133 // Built-in bool, char and arithmetic types should be trivially relocatable:
134 
135 SYS_DECLARE_IS_TR(bool);
136 SYS_DECLARE_IS_TR(char);
137 
138 SYS_DECLARE_IS_TR(unsigned char);
139 SYS_DECLARE_IS_TR(unsigned short int);
140 SYS_DECLARE_IS_TR(unsigned int);
141 SYS_DECLARE_IS_TR(unsigned long int);
142 SYS_DECLARE_IS_TR(unsigned long long int);
143 
144 SYS_DECLARE_IS_TR(signed char);
145 SYS_DECLARE_IS_TR(signed short int);
146 SYS_DECLARE_IS_TR(signed int);
147 SYS_DECLARE_IS_TR(signed long int);
148 SYS_DECLARE_IS_TR(signed long long int);
149 
150 SYS_DECLARE_IS_TR(float);
151 SYS_DECLARE_IS_TR(double);
152 
153 // Partial specialization for pointer types
154 
155 template< typename T >
157 {
158  static constexpr bool value = true;
159 };
160 
161 #endif // __SYS_TYPEDECORATE_H_INCLUDED__
typename SYS_RemoveCV< T >::type SYS_RemoveCV_t
constexpr auto SYS_HasCV_v
Definition: core.h:1131
#define const
Definition: zconf.h:214
#define SYS_DECLARE_IS_TR(T)
Guarantee that it's safe to use trivial relocation with type T.