HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_Storage.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: UT_Storage.h (UT Library, C++)
7  *
8  * COMMENTS: An enum for common, numeric data types.
9  */
10 
11 #pragma once
12 
13 #ifndef __UT_Storage__
14 #define __UT_Storage__
15 
16 #include <SYS/SYS_Types.h>
17 #include <SYS/SYS_TypeTraits.h>
18 #include <SYS/SYS_Inline.h>
19 
20 #include "UT_Assert.h"
21 
22 /// An enum representing numeric data storage types.
23 ///
24 /// NOTE: The order must be the conversion precedence order.
25 /// For example, int8(0)+int16(0) will be an int16,
26 /// and int64(0)+fpreal32(0) will be an fpreal32.
27 /// This enables UT_StorageBetter.
28 enum class UT_Storage
29 {
30  INVALID = -1,
31  INT8,
32  UINT8,
33  INT16,
34  INT32,
35  INT64,
36  REAL16,
37  REAL32,
38  REAL64
39 };
40 
41 /// Returns true iff the given storage type represents an integer.
44 {
45  return (int(storage) >= int(UT_Storage::INT8) && int(storage) <= int(UT_Storage::INT64));
46 }
47 
48 /// Returns true iff the given storage type represents a floating-point number.
51 {
52  return (int(storage) >= int(UT_Storage::REAL16) && int(storage) <= int(UT_Storage::REAL64));
53 }
54 
55 /// Returns the number of bytes in the given storage type.
58 {
59  switch (storage)
60  {
62  return 0;
63  case UT_Storage::INT8:
64  case UT_Storage::UINT8:
65  return 1;
66  case UT_Storage::INT16:
67  case UT_Storage::REAL16:
68  return 2;
69  case UT_Storage::INT32:
70  case UT_Storage::REAL32:
71  return 4;
72  case UT_Storage::INT64:
73  case UT_Storage::REAL64:
74  return 8;
75  }
76 
77  // gcc can't figure out that the switch statement above always returns...
78  return 0;
79 }
80 
81 /// These template classes get the UT_Storage from the type, e.g.
82 /// UT_Storage s = UT_StorageType<DATA_T>::theStorage;
83 /// @{
84 template<typename T>
86 {
88  typedef void Type;
89  typedef void AtLeast32Bit;
91  typedef void SecondGuess;
92  static constexpr bool theIsFloat = SYS_IsFloatingPoint_v< Type >;
93  static constexpr bool theIsInt = SYS_IsIntegral_v< Type >;
94 };
95 template<>
97 {
99  typedef int8 Type;
103  static constexpr bool theIsFloat = SYS_IsFloatingPoint_v< Type >;
104  static constexpr bool theIsInt = SYS_IsIntegral_v< Type >;
105 };
106 template<>
108 {
110  typedef uint8 Type;
114  static constexpr bool theIsFloat = SYS_IsFloatingPoint_v< Type >;
115  static constexpr bool theIsInt = SYS_IsIntegral_v< Type >;
116 };
117 template<>
119 {
121  typedef int16 Type;
125  static constexpr bool theIsFloat = SYS_IsFloatingPoint_v< Type >;
126  static constexpr bool theIsInt = SYS_IsIntegral_v< Type >;
127 };
128 template<>
130 {
132  typedef int32 Type;
136  static constexpr bool theIsFloat = SYS_IsFloatingPoint_v< Type >;
137  static constexpr bool theIsInt = SYS_IsIntegral_v< Type >;
138 };
139 template<>
141 {
143  typedef int64 Type;
147  static constexpr bool theIsFloat = SYS_IsFloatingPoint_v< Type >;
148  static constexpr bool theIsInt = SYS_IsIntegral_v< Type >;
149 };
150 template<>
152 {
154  typedef fpreal16 Type;
158  static constexpr bool theIsFloat = SYS_IsFloatingPoint_v< Type >;
159  static constexpr bool theIsInt = SYS_IsIntegral_v< Type >;
160 };
161 template<>
163 {
165  typedef fpreal32 Type;
169  static constexpr bool theIsFloat = SYS_IsFloatingPoint_v< Type >;
170  static constexpr bool theIsInt = SYS_IsIntegral_v< Type >;
171 };
172 template<>
174 {
176  typedef fpreal64 Type;
180  static constexpr bool theIsFloat = SYS_IsFloatingPoint_v< Type >;
181  static constexpr bool theIsInt = SYS_IsIntegral_v< Type >;
182 };
183 
184 template<typename T>
186 
187 /// @}
188 
189 /// These template classes get the type from the UT_Storage, e.g.
190 /// return (UT_StorageType<STORAGE>::theType)source;
191 /// @{
192 template<UT_Storage STORAGE>
194 {
196  typedef void Type;
197  static constexpr bool theIsFloat = SYS_IsFloatingPoint_v< Type >;
198  static constexpr bool theIsInt = SYS_IsIntegral_v< Type >;
199 };
200 template<>
202 {
204  typedef int8 Type;
205  static constexpr bool theIsFloat = SYS_IsFloatingPoint_v< Type >;
206  static constexpr bool theIsInt = SYS_IsIntegral_v< Type >;
207 };
208 template<>
210 {
212  typedef uint8 Type;
213  static constexpr bool theIsFloat = SYS_IsFloatingPoint_v< Type >;
214  static constexpr bool theIsInt = SYS_IsIntegral_v< Type >;
215 };
216 template<>
218 {
220  typedef int16 Type;
221  static constexpr bool theIsFloat = SYS_IsFloatingPoint_v< Type >;
222  static constexpr bool theIsInt = SYS_IsIntegral_v< Type >;
223 };
224 template<>
226 {
228  typedef int32 Type;
229  static constexpr bool theIsFloat = SYS_IsFloatingPoint_v< Type >;
230  static constexpr bool theIsInt = SYS_IsIntegral_v< Type >;
231 };
232 template<>
234 {
236  typedef int64 Type;
237  static constexpr bool theIsFloat = SYS_IsFloatingPoint_v< Type >;
238  static constexpr bool theIsInt = SYS_IsIntegral_v< Type >;
239 };
240 template<>
242 {
244  typedef fpreal16 Type;
245  static constexpr bool theIsFloat = SYS_IsFloatingPoint_v< Type >;
246  static constexpr bool theIsInt = SYS_IsIntegral_v< Type >;
247 };
248 template<>
250 {
252  typedef fpreal32 Type;
253  static constexpr bool theIsFloat = SYS_IsFloatingPoint_v< Type >;
254  static constexpr bool theIsInt = SYS_IsIntegral_v< Type >;
255 };
256 template<>
258 {
260  typedef fpreal64 Type;
261  static constexpr bool theIsFloat = SYS_IsFloatingPoint_v< Type >;
262  static constexpr bool theIsInt = SYS_IsIntegral_v< Type >;
263 };
264 /// @}
265 
266 /// This allows one to determine the type of T0+T1 at compile-time.
267 template<typename T0,typename T1>
269 {
270  // NOTE: The casts to int are only necessary for GCC 4.4's broken support for enum classes
272 };
273 
274 template<typename T0,typename T1>
276 
277 /// This allows one to determine the type of T0+T1 at compile-time.
278 template<typename T0,typename T1>
280 {
282 };
283 
284 template<typename T0,typename T1>
286 
287 template<exint TSIZE,typename DATA_T>
289 {
290  SYS_FORCE_INLINE exint getTupleSize() const { return TSIZE; }
291  SYS_FORCE_INLINE void setTupleSize(exint tuplesize) { UT_ASSERT_P(tuplesize == TSIZE); }
294 };
295 
296 template<typename DATA_T>
297 struct UT_TupleType<-1,DATA_T>
298 {
299  SYS_FORCE_INLINE exint getTupleSize() const { return myTupleSize; }
300  SYS_FORCE_INLINE void setTupleSize(exint tuplesize) { myTupleSize = tuplesize; }
303 private:
304  int myTupleSize;
305 };
306 
307 template<exint TSIZE>
308 struct UT_TupleType<TSIZE, void>
309 {
310  SYS_FORCE_INLINE exint getTupleSize() const { return TSIZE; }
311  SYS_FORCE_INLINE void setTupleSize(exint tuplesize) { UT_ASSERT_P(tuplesize == TSIZE); }
312  SYS_FORCE_INLINE UT_Storage getStorage() const { return myStorage; }
314 private:
315  int myTupleSizePlaceholder;
316  UT_Storage myStorage;
317 };
318 
319 template<>
320 struct UT_TupleType<-1, void>
321 {
322  SYS_FORCE_INLINE exint getTupleSize() const { return myTupleSize; }
323  SYS_FORCE_INLINE void setTupleSize(exint tuplesize) { myTupleSize = tuplesize; }
324  SYS_FORCE_INLINE UT_Storage getStorage() const { return myStorage; }
326 private:
327  int myTupleSize;
328  UT_Storage myStorage;
329 };
330 
331 template<typename TO,typename FROM>
333 TO UTconvertStorage(FROM from)
334 { return TO(from); }
335 
336 #define DECLARE_CONVERT_STORAGE_ROUND(T,F) \
337 template<> \
338 SYS_FORCE_INLINE \
339 T UTconvertStorage<T,F>(F from) \
340 { return T(from + ((from > 0) ? F(0.5) : F(-0.5))); } \
341 /* end of macro */
342 
358 
359 #undef DECLARE_CONVERT_STORAGE_ROUND
360 
361 
362 #endif
SYS_FORCE_INLINE UT_Storage getStorage() const
Definition: UT_Storage.h:301
typename UT_StorageNum< T >::MathFloat UT_StorageMathFloat_t
Definition: UT_Storage.h:185
void SecondGuess
Definition: UT_Storage.h:91
SYS_FORCE_INLINE UT_Storage getStorage() const
Definition: UT_Storage.h:292
int int32
Definition: SYS_Types.h:39
UT_Storage
Definition: UT_Storage.h:28
SYS_FORCE_INLINE void setTupleSize(exint tuplesize)
Definition: UT_Storage.h:323
This allows one to determine the type of T0+T1 at compile-time.
Definition: UT_Storage.h:279
void
Definition: png.h:1083
getFileOption("OpenEXR:storage") storage
Definition: HDK_Image.dox:276
static const UT_Storage theStorage
Definition: UT_Storage.h:87
static constexpr bool theIsInt
Definition: UT_Storage.h:93
SYS_FORCE_INLINE exint getTupleSize() const
Definition: UT_Storage.h:290
SYS_FORCE_INLINE void setStorage(UT_Storage storage)
Definition: UT_Storage.h:325
int64 exint
Definition: SYS_Types.h:125
void AtLeast32Bit
Definition: UT_Storage.h:89
static constexpr bool theIsFloat
Definition: UT_Storage.h:197
SYS_FORCE_INLINE constexpr bool UTisFloatStorage(UT_Storage storage)
Returns true iff the given storage type represents a floating-point number.
Definition: UT_Storage.h:50
typename SYS_SelectType< typename UT_StorageNum< UT_StorageBetter_t< T0, T1 >>::AtLeast32Bit, T0, UT_StorageNum< UT_StorageBetter_t< T0, T1 >>::theStorage==UT_Storage::INVALID >::type type
Definition: UT_Storage.h:281
float fpreal32
Definition: SYS_Types.h:200
static constexpr bool theIsInt
Definition: UT_Storage.h:198
static const UT_Storage theStorage
Definition: UT_Storage.h:195
SYS_FORCE_INLINE TO UTconvertStorage(FROM from)
Definition: UT_Storage.h:333
SYS_FORCE_INLINE exint getTupleSize() const
Definition: UT_Storage.h:310
#define DECLARE_CONVERT_STORAGE_ROUND(T, F)
Definition: UT_Storage.h:336
double fpreal64
Definition: SYS_Types.h:201
unsigned char uint8
Definition: SYS_Types.h:36
SYS_FORCE_INLINE exint getTupleSize() const
Definition: UT_Storage.h:322
SYS_FORCE_INLINE void setTupleSize(exint tuplesize)
Definition: UT_Storage.h:300
fpreal32 MathFloat
Definition: UT_Storage.h:90
typename UT_StorageAtLeast32Bit< T0, T1 >::type UT_StorageAtLeast32Bit_t
Definition: UT_Storage.h:285
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:155
This allows one to determine the type of T0+T1 at compile-time.
Definition: UT_Storage.h:268
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
long long int64
Definition: SYS_Types.h:116
static constexpr bool theIsFloat
Definition: UT_Storage.h:92
typename UT_StorageBetter< T0, T1 >::type UT_StorageBetter_t
Definition: UT_Storage.h:275
signed char int8
Definition: SYS_Types.h:35
SYS_FORCE_INLINE exint getTupleSize() const
Definition: UT_Storage.h:299
SYS_FORCE_INLINE void setStorage(UT_Storage storage)
Definition: UT_Storage.h:313
typename SYS_SelectType< T0, T1,(int(UT_StorageNum< T0 >::theStorage)< int(UT_StorageNum< T1 >::theStorage))>::type type
Definition: UT_Storage.h:271
short int16
Definition: SYS_Types.h:37
SYS_FORCE_INLINE void setTupleSize(exint tuplesize)
Definition: UT_Storage.h:311
SYS_FORCE_INLINE void setTupleSize(exint tuplesize)
Definition: UT_Storage.h:291
SYS_FORCE_INLINE void setStorage(UT_Storage storage)
Definition: UT_Storage.h:302
SYS_FORCE_INLINE UT_Storage getStorage() const
Definition: UT_Storage.h:324
SYS_FORCE_INLINE void setStorage(UT_Storage storage)
Definition: UT_Storage.h:293
SYS_FORCE_INLINE constexpr bool UTisIntStorage(UT_Storage storage)
Returns true iff the given storage type represents an integer.
Definition: UT_Storage.h:43
SYS_FORCE_INLINE constexpr int UTstorageSize(UT_Storage storage)
Returns the number of bytes in the given storage type.
Definition: UT_Storage.h:57
SYS_FORCE_INLINE UT_Storage getStorage() const
Definition: UT_Storage.h:312