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 /// An enum representing numeric data storage types.
21 ///
22 /// NOTE: The order must be the conversion precedence order.
23 /// For example, int8(0)+int16(0) will be an int16,
24 /// and int64(0)+fpreal32(0) will be an fpreal32.
25 /// This enables UT_StorageBetter.
26 enum class UT_Storage
27 {
28  INVALID = -1,
29  INT8,
30  INT16,
31  INT32,
32  INT64,
33  REAL16,
34  REAL32,
35  REAL64
36 };
37 
38 /// Returns true iff the given storage type represents an integer.
41 {
42  return (int(storage) >= int(UT_Storage::INT8) && int(storage) <= int(UT_Storage::INT64));
43 }
44 
45 /// Returns true iff the given storage type represents a floating-point number.
48 {
49  return (int(storage) >= int(UT_Storage::REAL16) && int(storage) <= int(UT_Storage::REAL64));
50 }
51 
52 /// Returns the number of bytes in the given storage type.
55 {
56  // This should really be a switch statement, but constexpr doesn't
57  // allow that in C++11, so enjoy this chain of ternary operators! :)
58  return (storage == UT_Storage::REAL32 || storage == UT_Storage::INT32) ? 4
59  : ((storage == UT_Storage::REAL64 || storage == UT_Storage::INT64) ? 8
60  : ((storage == UT_Storage::REAL16 || storage == UT_Storage::INT16) ? 2
61  : ((storage == UT_Storage::INT8) ? 1
62  : 0)));
63 }
64 
65 /// These template classes get the UT_Storage from the type, e.g.
66 /// UT_Storage s = UT_StorageType<DATA_T>::theStorage;
67 /// @{
68 template<typename T>
69 struct UT_StorageNum {
71  typedef void Type;
72  typedef void AtLeast32Bit;
74  typedef void SecondGuess;
75  static const bool theIsFloat = false;
76  static const bool theIsInt = false;
77 };
78 template<>
81  typedef int8 Type;
84  typedef int32 SecondGuess;
85  static const bool theIsFloat = false;
86  static const bool theIsInt = true;
87 };
88 template<>
91  typedef int16 Type;
94  typedef int32 SecondGuess;
95  static const bool theIsFloat = false;
96  static const bool theIsInt = true;
97 };
98 template<>
101  typedef int32 Type;
105  static const bool theIsFloat = false;
106  static const bool theIsInt = true;
107 };
108 template<>
111  typedef int64 Type;
115  static const bool theIsFloat = false;
116  static const bool theIsInt = true;
117 };
118 template<>
121  typedef fpreal16 Type;
125  static const bool theIsFloat = true;
126  static const bool theIsInt = false;
127 };
128 template<>
131  typedef fpreal32 Type;
135  static const bool theIsFloat = true;
136  static const bool theIsInt = false;
137 };
138 template<>
141  typedef fpreal64 Type;
145  static const bool theIsFloat = true;
146  static const bool theIsInt = false;
147 };
148 /// @}
149 
150 /// These template classes get the type from the UT_Storage, e.g.
151 /// return (UT_StorageType<STORAGE>::theType)source;
152 /// @{
153 template<UT_Storage STORAGE>
156  typedef void Type;
157  static const bool theIsFloat = false;
158  static const bool theIsInt = false;
159 };
160 template<>
163  typedef int8 Type;
164  static const bool theIsFloat = false;
165  static const bool theIsInt = true;
166 };
167 template<>
170  typedef int16 Type;
171  static const bool theIsFloat = false;
172  static const bool theIsInt = true;
173 };
174 template<>
177  typedef int32 Type;
178  static const bool theIsFloat = false;
179  static const bool theIsInt = true;
180 };
181 template<>
184  typedef int64 Type;
185  static const bool theIsFloat = false;
186  static const bool theIsInt = true;
187 };
188 template<>
191  typedef fpreal16 Type;
192  static const bool theIsFloat = true;
193  static const bool theIsInt = false;
194 };
195 template<>
198  typedef fpreal32 Type;
199  static const bool theIsFloat = true;
200  static const bool theIsInt = false;
201 };
202 template<>
205  typedef fpreal64 Type;
206  static const bool theIsFloat = true;
207  static const bool theIsInt = false;
208 };
209 /// @}
210 
211 /// This allows one to determine the type of T0+T1 at compile-time.
212 template<typename T0,typename T1>
214  // NOTE: The casts to int are only necessary for GCC 4.4's broken support for enum classes
216 };
217 
218 /// This allows one to determine the type of T0+T1 at compile-time.
219 template<typename T0,typename T1>
222 };
223 
224 template<exint TSIZE,typename DATA_T>
226 {
227  SYS_FORCE_INLINE exint getTupleSize() const { return TSIZE; }
228  SYS_FORCE_INLINE void setTupleSize(exint tuplesize) { UT_ASSERT_P(tuplesize == TSIZE); }
231 };
232 
233 template<typename DATA_T>
234 struct UT_TupleType<-1,DATA_T>
235 {
236  SYS_FORCE_INLINE exint getTupleSize() const { return myTupleSize; }
237  SYS_FORCE_INLINE void setTupleSize(exint tuplesize) { myTupleSize = tuplesize; }
240 private:
241  int myTupleSize;
242 };
243 
244 template<exint TSIZE>
245 struct UT_TupleType<TSIZE, void>
246 {
247  SYS_FORCE_INLINE exint getTupleSize() const { return TSIZE; }
248  SYS_FORCE_INLINE void setTupleSize(exint tuplesize) { UT_ASSERT_P(tuplesize == TSIZE); }
249  SYS_FORCE_INLINE UT_Storage getStorage() const { return myStorage; }
251 private:
252  int myTupleSizePlaceholder;
253  UT_Storage myStorage;
254 };
255 
256 template<>
257 struct UT_TupleType<-1, void>
258 {
259  SYS_FORCE_INLINE exint getTupleSize() const { return myTupleSize; }
260  SYS_FORCE_INLINE void setTupleSize(exint tuplesize) { myTupleSize = tuplesize; }
261  SYS_FORCE_INLINE UT_Storage getStorage() const { return myStorage; }
263 private:
264  int myTupleSize;
265  UT_Storage myStorage;
266 };
267 
268 template<typename TO,typename FROM>
270 TO UTconvertStorage(FROM from)
271 { return TO(from); }
272 
273 #define DECLARE_CONVERT_STORAGE_ROUND(T,F) \
274 template<> \
275 SYS_FORCE_INLINE \
276 T UTconvertStorage<T,F>(F from) \
277 { return T(from + ((from > 0) ? F(0.5) : F(-0.5))); } \
278 /* end of macro */
279 
292 
293 #undef DECLARE_CONVERT_STORAGE_ROUND
294 
295 
296 #endif
SYS_FORCE_INLINE UT_Storage getStorage() const
Definition: UT_Storage.h:238
void SecondGuess
Definition: UT_Storage.h:74
static const bool theIsFloat
Definition: UT_Storage.h:157
SYS_FORCE_INLINE UT_Storage getStorage() const
Definition: UT_Storage.h:229
UT_Storage
Definition: UT_Storage.h:26
SYS_FORCE_INLINE void setTupleSize(exint tuplesize)
Definition: UT_Storage.h:260
This allows one to determine the type of T0+T1 at compile-time.
Definition: UT_Storage.h:220
static const UT_Storage theStorage
Definition: UT_Storage.h:70
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
static const bool theIsInt
Definition: UT_Storage.h:158
SYS_FORCE_INLINE exint getTupleSize() const
Definition: UT_Storage.h:227
SYS_FORCE_INLINE void setStorage(UT_Storage storage)
Definition: UT_Storage.h:262
void AtLeast32Bit
Definition: UT_Storage.h:72
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:47
static const UT_Storage theStorage
Definition: UT_Storage.h:155
SYS_FORCE_INLINE TO UTconvertStorage(FROM from)
Definition: UT_Storage.h:270
signed char int8
Definition: SYS_Types.h:31
SYS_FORCE_INLINE exint getTupleSize() const
Definition: UT_Storage.h:247
#define DECLARE_CONVERT_STORAGE_ROUND(T, F)
Definition: UT_Storage.h:273
static const bool theIsInt
Definition: UT_Storage.h:76
long long int64
Definition: SYS_Types.h:107
SYS_FORCE_INLINE exint getTupleSize() const
Definition: UT_Storage.h:259
SYS_FORCE_INLINE void setTupleSize(exint tuplesize)
Definition: UT_Storage.h:237
fpreal32 MathFloat
Definition: UT_Storage.h:73
int64 exint
Definition: SYS_Types.h:116
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:125
This allows one to determine the type of T0+T1 at compile-time.
Definition: UT_Storage.h:213
double fpreal64
Definition: SYS_Types.h:192
static const bool theIsFloat
Definition: UT_Storage.h:75
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
int int32
Definition: SYS_Types.h:35
SYS_FORCE_INLINE exint getTupleSize() const
Definition: UT_Storage.h:236
SYS_FORCE_INLINE void setStorage(UT_Storage storage)
Definition: UT_Storage.h:250
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:221
SYS_FORCE_INLINE void setTupleSize(exint tuplesize)
Definition: UT_Storage.h:248
SYS_FORCE_INLINE void setTupleSize(exint tuplesize)
Definition: UT_Storage.h:228
SYS_FORCE_INLINE void setStorage(UT_Storage storage)
Definition: UT_Storage.h:239
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
getOption("OpenEXR.storage") storage
Definition: HDK_Image.dox:276
SYS_FORCE_INLINE UT_Storage getStorage() const
Definition: UT_Storage.h:261
SYS_FORCE_INLINE void setStorage(UT_Storage storage)
Definition: UT_Storage.h:230
short int16
Definition: SYS_Types.h:33
SYS_FORCE_INLINE constexpr bool UTisIntStorage(UT_Storage storage)
Returns true iff the given storage type represents an integer.
Definition: UT_Storage.h:40
SYS_FORCE_INLINE constexpr int UTstorageSize(UT_Storage storage)
Returns the number of bytes in the given storage type.
Definition: UT_Storage.h:54
float fpreal32
Definition: SYS_Types.h:191
SYS_FORCE_INLINE UT_Storage getStorage() const
Definition: UT_Storage.h:249