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 // NOTE: This header is intentionally kept free of any includes,
15 // as it may itself get included in many places.
16 
17 // Define SYS_RemoveCV here instead to avoid including
18 // SYS_TypeTraits.h or type_traits in too many places.
19 
20 /// Remove topmost const/volatile qualifiers.
21 /// @{
22 
23 template< typename T >
24 struct SYS_RemoveCV { using type = T; };
25 
26 template< typename T >
27 struct SYS_RemoveCV< const T > { using type = T; };
28 
29 template< typename T >
30 struct SYS_RemoveCV< volatile T > { using type = T; };
31 
32 template< typename T >
33 struct SYS_RemoveCV< const volatile T > { using type = T; };
34 
35 template< typename T >
37 
38 /// @}
39 
40 // Primary templates for additional types that are considered,
41 // integral, floating-point, POD:
42 
43 template <typename T> struct AddIntegralNoCV { static constexpr bool value = false; };
44 template <typename T> struct AddFloatingPointNoCV { static constexpr bool value = false; };
45 template <typename T> struct AddPodNoCV { static constexpr bool value = false; };
46 
47 // Specialization of SafeTrivialRelocationNoCV adds a type to the list
48 // of types that are known to be safe for trivial relocation.
49 // For each such type SYS_IsTriviallyRelocatable (see SYS_TypeTraits.h)
50 // would return true. However, SYS_IsTriviallyRelocatable may be true
51 // for additional types that have no SafeTrivialRelocationNoCV specialization,
52 // for example, enum types.
53 // Primary template:
54 template< typename T > struct SafeTrivialRelocationNoCV { static constexpr bool value = false; };
55 
56 // Specialization of UnsafeTrivialRelocationNoCV adds a type to the list
57 // of types that are known to be unsafe for trivial relocation.
58 // Primary template:
59 template< typename T > struct UnsafeTrivialRelocationNoCV { static constexpr bool value = false; };
60 
61 // Primary template:
62 // LegacyTrivialRelocationNoCV indicates that trivial relocation must
63 // be used for T not because it's safe but only because T is legacy code:
64 // T may have missing or broken move constructors or destructors,
65 // in which case we're forced to keep treating T as TR until T is fixed.
66 template< typename T > struct LegacyTrivialRelocationNoCV { static constexpr bool value = false; };
67 
68 // Primary template:
69 // RegisterRelocationNoCV indicates that trivial relocation is
70 // currently being used for a type T.
71 // This trait does not say whether this is safe or not,
72 // it merely documents a previously existing use of trivial relocation.
73 template< typename T > struct RegisterTrivialRelocationNoCV { static constexpr bool value = false; };
74 
75 // Primary templates for fixed-array-like type traits
76 
77 template< typename T > struct SYS_IsFixedArrayNoCVRef { static constexpr bool value = false; };
78 template< typename T > struct SYS_FixedArrayElementNoCVRef;
79 template< typename T > struct SYS_FixedArraySizeNoCVRef;
80 
81 // SYS_HasCV: Return whether a type T has any const or volatile qualifiers
82 
83 // Primary
84 template< typename T > struct SYS_HasCV { static constexpr bool value = false; };
85 
86 template< typename T > constexpr auto SYS_HasCV_v = SYS_HasCV< T >::value;
87 
88 template< typename T > struct SYS_HasCV< const T > { static constexpr bool value = true; };
89 template< typename T > struct SYS_HasCV< volatile T > { static constexpr bool value = true; };
90 template< typename T > struct SYS_HasCV< const volatile T > { static constexpr bool value = true; };
91 
92 /// @file
93 /// Provides facilities to decorate types that can then be tested using type
94 /// traits.
95 
96 /// Declare a type as integral
97 #define SYS_DECLARE_IS_INTEGRAL(T) \
98  template<> struct AddIntegralNoCV< T > { \
99  static_assert( ( ! SYS_HasCV_v< T > ), \
100  "SYS_DECLARE_IS_INTEGRAL must be used on types without const/volatile qualifiers" ); \
101  [[maybe_unused]] static constexpr bool value = true; \
102  };\
103  /**/
104 
105 /// Declare a type as floating point
106 #define SYS_DECLARE_IS_FLOATING_POINT(T) \
107  template<> struct AddFloatingPointNoCV< T > { \
108  static_assert( ( ! SYS_HasCV_v< T > ), \
109  "SYS_DECLARE_IS_FLOATING_POINT must be used on types without const/volatile qualifiers" ); \
110  [[maybe_unused]] static constexpr bool value = true; \
111  };\
112  /**/
113 
114 /// Declare a type as POD
115 #define SYS_DECLARE_IS_POD(T) \
116  template<> struct AddPodNoCV< T > { \
117  static_assert( ( ! SYS_HasCV_v< T > ), \
118  "SYS_DECLARE_IS_POD must be used on types without const/volatile qualifiers" ); \
119  [[maybe_unused]] static constexpr bool value = true; \
120  };\
121  /**/
122 
123 #define SYS_DECLARE_IS_TR_IMPL(...) \
124  struct SafeTrivialRelocationNoCV< __VA_ARGS__ > { \
125  static_assert( ( ! SYS_HasCV_v< __VA_ARGS__> ), \
126  "SYS_DECLARE_IS_TR must be used on types without const/volatile qualifiers" ); \
127  [[maybe_unused]] static constexpr bool value = true; \
128  };\
129  /**/
130 
131 #define SYS_DECLARE_IS_NOT_TR_IMPL(...) \
132  struct UnsafeTrivialRelocationNoCV< __VA_ARGS__ > { \
133  static_assert( ( ! SYS_HasCV_v< __VA_ARGS__ > ), \
134  "SYS_DECLARE_IS_NOT_TR must be used on types without const/volatile qualifiers" ); \
135  [[maybe_unused]] static constexpr bool value = true; \
136  };\
137  /**/
138 
139 #define SYS_DECLARE_LEGACY_TR_IMPL(...) \
140  struct LegacyTrivialRelocationNoCV< __VA_ARGS__ > { \
141  static_assert( ( ! SYS_HasCV_v< __VA_ARGS__ > ), \
142  "SYS_DECLARE_LEGACY_TR must be used on types without const/volatile qualifiers" ); \
143  [[maybe_unused]] static constexpr bool value = true; \
144  };\
145  /**/
146 
147 #define SYS_REGISTER_TR_IMPL(...) \
148  struct RegisterTrivialRelocationNoCV< __VA_ARGS__ > { \
149  static_assert( ( ! SYS_HasCV_v< __VA_ARGS__ > ), \
150  "SYS_REGISTER_TR must be used on types without const/volatile qualifiers" ); \
151  [[maybe_unused]] static constexpr bool value = true; \
152  };\
153  /**/
154 
155 /// Guarantee that it's safe to use trivial relocation with type T
156 #define SYS_DECLARE_IS_TR(T) template<> SYS_DECLARE_IS_TR_IMPL(T)
157 
158 /// Version for class template
159 #define SYS_DECLARE_IS_TR_TEMPLATE(...) SYS_DECLARE_IS_TR_IMPL( __VA_ARGS__ )
160 
161 /// Declare that that trivial relocation with type T is not guaranteed to be safe
162 #define SYS_DECLARE_IS_NOT_TR(T) template<> SYS_DECLARE_IS_NOT_TR_IMPL(T)
163 
164 /// Version for class template
165 #define SYS_DECLARE_IS_NOT_TR_TEMPLATE(...) SYS_DECLARE_IS_NOT_TR_IMPL( __VA_ARGS__ )
166 
167 /// Declare that trivial relocation must be used with T,
168 /// but only because T is legacy code
169 /// Ideally, the type T would be modified to allow safe relocation,
170 /// by providing a move constructor.
171 #define SYS_DECLARE_LEGACY_TR(T) template<> SYS_DECLARE_LEGACY_TR_IMPL(T)
172 
173 /// Version for class template
174 #define SYS_DECLARE_LEGACY_TR_TEMPLATE(...) SYS_DECLARE_LEGACY_TR_IMPL( __VA_ARGS__ )
175 
176 /// Register that trivial relocation is currently being used with T
177 /// This does not declare that this is safe at all;
178 /// it just documents each type that is currently being trivially relocated.
179 /// the information is merely used to help compile a list of all types that
180 /// are currently being trivially relocated by UT_Array
181 /// (all types were being trivially relocated before H20).
182 /// An actual decision on whether TR should be remain enabled for the type T
183 /// can be made later.
184 #define SYS_REGISTER_TR(T) template<> SYS_REGISTER_TR_IMPL(T)
185 
186 /// Version for class template
187 #define SYS_REGISTER_TR_TEMPLATE(...) SYS_REGISTER_TR_IMPL( __VA_ARGS__ )
188 
189 // Built-in bool, char and arithmetic types should be trivially relocatable:
190 
191 SYS_DECLARE_IS_TR(bool);
192 SYS_DECLARE_IS_TR(char);
193 
194 SYS_DECLARE_IS_TR(unsigned char);
195 SYS_DECLARE_IS_TR(unsigned short int);
196 SYS_DECLARE_IS_TR(unsigned int);
197 SYS_DECLARE_IS_TR(unsigned long int);
198 SYS_DECLARE_IS_TR(unsigned long long int);
199 
200 SYS_DECLARE_IS_TR(signed char);
201 SYS_DECLARE_IS_TR(signed short int);
202 SYS_DECLARE_IS_TR(signed int);
203 SYS_DECLARE_IS_TR(signed long int);
204 SYS_DECLARE_IS_TR(signed long long int);
205 
206 SYS_DECLARE_IS_TR(float);
207 SYS_DECLARE_IS_TR(double);
208 
209 // Partial specialization for pointer types
210 
211 template< typename T >
213 {
214  static constexpr bool value = true;
215 };
216 
217 #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.