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>
85 struct UT_StorageNum {
87  typedef void Type;
88  typedef void AtLeast32Bit;
90  typedef void SecondGuess;
91  static const bool theIsFloat = false;
92  static const bool theIsInt = false;
93 };
94 template<>
97  typedef int8 Type;
101  static const bool theIsFloat = false;
102  static const bool theIsInt = true;
103 };
104 template<>
107  typedef uint8 Type;
111  static const bool theIsFloat = false;
112  static const bool theIsInt = true;
113 };
114 template<>
117  typedef int16 Type;
121  static const bool theIsFloat = false;
122  static const bool theIsInt = true;
123 };
124 template<>
127  typedef int32 Type;
131  static const bool theIsFloat = false;
132  static const bool theIsInt = true;
133 };
134 template<>
137  typedef int64 Type;
141  static const bool theIsFloat = false;
142  static const bool theIsInt = true;
143 };
144 template<>
147  typedef fpreal16 Type;
151  static const bool theIsFloat = true;
152  static const bool theIsInt = false;
153 };
154 template<>
157  typedef fpreal32 Type;
161  static const bool theIsFloat = true;
162  static const bool theIsInt = false;
163 };
164 template<>
167  typedef fpreal64 Type;
171  static const bool theIsFloat = true;
172  static const bool theIsInt = false;
173 };
174 /// @}
175 
176 /// These template classes get the type from the UT_Storage, e.g.
177 /// return (UT_StorageType<STORAGE>::theType)source;
178 /// @{
179 template<UT_Storage STORAGE>
182  typedef void Type;
183  static const bool theIsFloat = false;
184  static const bool theIsInt = false;
185 };
186 template<>
189  typedef int8 Type;
190  static const bool theIsFloat = false;
191  static const bool theIsInt = true;
192 };
193 template<>
196  typedef uint8 Type;
197  static const bool theIsFloat = false;
198  static const bool theIsInt = true;
199 };
200 template<>
203  typedef int16 Type;
204  static const bool theIsFloat = false;
205  static const bool theIsInt = true;
206 };
207 template<>
210  typedef int32 Type;
211  static const bool theIsFloat = false;
212  static const bool theIsInt = true;
213 };
214 template<>
217  typedef int64 Type;
218  static const bool theIsFloat = false;
219  static const bool theIsInt = true;
220 };
221 template<>
224  typedef fpreal16 Type;
225  static const bool theIsFloat = true;
226  static const bool theIsInt = false;
227 };
228 template<>
231  typedef fpreal32 Type;
232  static const bool theIsFloat = true;
233  static const bool theIsInt = false;
234 };
235 template<>
238  typedef fpreal64 Type;
239  static const bool theIsFloat = true;
240  static const bool theIsInt = false;
241 };
242 /// @}
243 
244 /// This allows one to determine the type of T0+T1 at compile-time.
245 template<typename T0,typename T1>
247  // NOTE: The casts to int are only necessary for GCC 4.4's broken support for enum classes
249 };
250 
251 /// This allows one to determine the type of T0+T1 at compile-time.
252 template<typename T0,typename T1>
255 };
256 
257 template<exint TSIZE,typename DATA_T>
259 {
260  SYS_FORCE_INLINE exint getTupleSize() const { return TSIZE; }
261  SYS_FORCE_INLINE void setTupleSize(exint tuplesize) { UT_ASSERT_P(tuplesize == TSIZE); }
264 };
265 
266 template<typename DATA_T>
267 struct UT_TupleType<-1,DATA_T>
268 {
269  SYS_FORCE_INLINE exint getTupleSize() const { return myTupleSize; }
270  SYS_FORCE_INLINE void setTupleSize(exint tuplesize) { myTupleSize = tuplesize; }
273 private:
274  int myTupleSize;
275 };
276 
277 template<exint TSIZE>
278 struct UT_TupleType<TSIZE, void>
279 {
280  SYS_FORCE_INLINE exint getTupleSize() const { return TSIZE; }
281  SYS_FORCE_INLINE void setTupleSize(exint tuplesize) { UT_ASSERT_P(tuplesize == TSIZE); }
282  SYS_FORCE_INLINE UT_Storage getStorage() const { return myStorage; }
284 private:
285  int myTupleSizePlaceholder;
286  UT_Storage myStorage;
287 };
288 
289 template<>
290 struct UT_TupleType<-1, void>
291 {
292  SYS_FORCE_INLINE exint getTupleSize() const { return myTupleSize; }
293  SYS_FORCE_INLINE void setTupleSize(exint tuplesize) { myTupleSize = tuplesize; }
294  SYS_FORCE_INLINE UT_Storage getStorage() const { return myStorage; }
296 private:
297  int myTupleSize;
298  UT_Storage myStorage;
299 };
300 
301 template<typename TO,typename FROM>
303 TO UTconvertStorage(FROM from)
304 { return TO(from); }
305 
306 #define DECLARE_CONVERT_STORAGE_ROUND(T,F) \
307 template<> \
308 SYS_FORCE_INLINE \
309 T UTconvertStorage<T,F>(F from) \
310 { return T(from + ((from > 0) ? F(0.5) : F(-0.5))); } \
311 /* end of macro */
312 
328 
329 #undef DECLARE_CONVERT_STORAGE_ROUND
330 
331 
332 #endif
SYS_FORCE_INLINE UT_Storage getStorage() const
Definition: UT_Storage.h:271
void SecondGuess
Definition: UT_Storage.h:90
static const bool theIsFloat
Definition: UT_Storage.h:183
SYS_FORCE_INLINE UT_Storage getStorage() const
Definition: UT_Storage.h:262
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:293
This allows one to determine the type of T0+T1 at compile-time.
Definition: UT_Storage.h:253
static const UT_Storage theStorage
Definition: UT_Storage.h:86
static const bool theIsInt
Definition: UT_Storage.h:184
SYS_FORCE_INLINE exint getTupleSize() const
Definition: UT_Storage.h:260
SYS_FORCE_INLINE void setStorage(UT_Storage storage)
Definition: UT_Storage.h:295
int64 exint
Definition: SYS_Types.h:125
void AtLeast32Bit
Definition: UT_Storage.h:88
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
float fpreal32
Definition: SYS_Types.h:200
static const UT_Storage theStorage
Definition: UT_Storage.h:181
SYS_FORCE_INLINE TO UTconvertStorage(FROM from)
Definition: UT_Storage.h:303
SYS_FORCE_INLINE exint getTupleSize() const
Definition: UT_Storage.h:280
#define DECLARE_CONVERT_STORAGE_ROUND(T, F)
Definition: UT_Storage.h:306
double fpreal64
Definition: SYS_Types.h:201
unsigned char uint8
Definition: SYS_Types.h:36
static const bool theIsInt
Definition: UT_Storage.h:92
SYS_FORCE_INLINE exint getTupleSize() const
Definition: UT_Storage.h:292
SYS_FORCE_INLINE void setTupleSize(exint tuplesize)
Definition: UT_Storage.h:270
fpreal32 MathFloat
Definition: UT_Storage.h:89
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:134
This allows one to determine the type of T0+T1 at compile-time.
Definition: UT_Storage.h:246
static const bool theIsFloat
Definition: UT_Storage.h:91
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
void
Definition: png.h:1083
long long int64
Definition: SYS_Types.h:116
signed char int8
Definition: SYS_Types.h:35
SYS_FORCE_INLINE exint getTupleSize() const
Definition: UT_Storage.h:269
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1253
SYS_FORCE_INLINE void setStorage(UT_Storage storage)
Definition: UT_Storage.h:283
typename SYS_SelectType< typename UT_StorageNum< typename UT_StorageBetter< T0, T1 >::Type >::AtLeast32Bit, T0, UT_StorageNum< typename UT_StorageBetter< T0, T1 >::Type >::theStorage==UT_Storage::INVALID >::type Type
Definition: UT_Storage.h:254
short int16
Definition: SYS_Types.h:37
SYS_FORCE_INLINE void setTupleSize(exint tuplesize)
Definition: UT_Storage.h:281
SYS_FORCE_INLINE void setTupleSize(exint tuplesize)
Definition: UT_Storage.h:261
SYS_FORCE_INLINE void setStorage(UT_Storage storage)
Definition: UT_Storage.h:272
getOption("OpenEXR.storage") storage
Definition: HDK_Image.dox:276
SYS_FORCE_INLINE UT_Storage getStorage() const
Definition: UT_Storage.h:294
SYS_FORCE_INLINE void setStorage(UT_Storage storage)
Definition: UT_Storage.h:263
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
type
Definition: core.h:528
SYS_FORCE_INLINE UT_Storage getStorage() const
Definition: UT_Storage.h:282