HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 template<exint TSIZE,typename DATA_T>
220 {
221  SYS_FORCE_INLINE exint getTupleSize() const { return TSIZE; }
222  SYS_FORCE_INLINE void setTupleSize(exint tuplesize) { UT_ASSERT_P(tuplesize == TSIZE); }
225 };
226 
227 template<typename DATA_T>
228 struct UT_TupleType<-1,DATA_T>
229 {
230  SYS_FORCE_INLINE exint getTupleSize() const { return myTupleSize; }
231  SYS_FORCE_INLINE void setTupleSize(exint tuplesize) { myTupleSize = tuplesize; }
234 private:
235  int myTupleSize;
236 };
237 
238 template<exint TSIZE>
239 struct UT_TupleType<TSIZE, void>
240 {
241  SYS_FORCE_INLINE exint getTupleSize() const { return TSIZE; }
242  SYS_FORCE_INLINE void setTupleSize(exint tuplesize) { UT_ASSERT_P(tuplesize == TSIZE); }
243  SYS_FORCE_INLINE UT_Storage getStorage() const { return myStorage; }
245 private:
246  int myTupleSizePlaceholder;
247  UT_Storage myStorage;
248 };
249 
250 template<>
251 struct UT_TupleType<-1, void>
252 {
253  SYS_FORCE_INLINE exint getTupleSize() const { return myTupleSize; }
254  SYS_FORCE_INLINE void setTupleSize(exint tuplesize) { myTupleSize = tuplesize; }
255  SYS_FORCE_INLINE UT_Storage getStorage() const { return myStorage; }
257 private:
258  int myTupleSize;
259  UT_Storage myStorage;
260 };
261 
262 template<typename TO,typename FROM>
264 TO UTconvertStorage(FROM from)
265 { return TO(from); }
266 
267 #define DECLARE_CONVERT_STORAGE_ROUND(T,F) \
268 template<> \
269 SYS_FORCE_INLINE \
270 T UTconvertStorage<T,F>(F from) \
271 { return T(from + ((from > 0) ? F(0.5) : F(-0.5))); } \
272 /* end of macro */
273 
286 
287 #undef DECLARE_CONVERT_STORAGE_ROUND
288 
289 
290 #endif
SYS_FORCE_INLINE UT_Storage getStorage() const
Definition: UT_Storage.h:232
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:223
UT_Storage
Definition: UT_Storage.h:26
SYS_FORCE_INLINE void setTupleSize(exint tuplesize)
Definition: UT_Storage.h:254
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:221
SYS_FORCE_INLINE void setStorage(UT_Storage storage)
Definition: UT_Storage.h:256
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:264
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:101
signed char int8
Definition: SYS_Types.h:24
SYS_FORCE_INLINE exint getTupleSize() const
Definition: UT_Storage.h:241
#define DECLARE_CONVERT_STORAGE_ROUND(T, F)
Definition: UT_Storage.h:267
static const bool theIsInt
Definition: UT_Storage.h:76
long long int64
Definition: SYS_Types.h:100
SYS_FORCE_INLINE exint getTupleSize() const
Definition: UT_Storage.h:253
SYS_FORCE_INLINE void setTupleSize(exint tuplesize)
Definition: UT_Storage.h:231
fpreal32 MathFloat
Definition: UT_Storage.h:73
int64 exint
Definition: SYS_Types.h:109
This allows one to determine the type of T0+T1 at compile-time.
Definition: UT_Storage.h:213
double fpreal64
Definition: SYS_Types.h:185
static const bool theIsFloat
Definition: UT_Storage.h:75
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
int int32
Definition: SYS_Types.h:28
SYS_FORCE_INLINE exint getTupleSize() const
Definition: UT_Storage.h:230
SYS_FORCE_INLINE void setStorage(UT_Storage storage)
Definition: UT_Storage.h:244
SYS_FORCE_INLINE void setTupleSize(exint tuplesize)
Definition: UT_Storage.h:242
SYS_FORCE_INLINE void setTupleSize(exint tuplesize)
Definition: UT_Storage.h:222
SYS_FORCE_INLINE void setStorage(UT_Storage storage)
Definition: UT_Storage.h:233
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:255
SYS_FORCE_INLINE void setStorage(UT_Storage storage)
Definition: UT_Storage.h:224
short int16
Definition: SYS_Types.h:26
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:184
SYS_FORCE_INLINE UT_Storage getStorage() const
Definition: UT_Storage.h:243