HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GA_Defaults.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: GA_Defaults.h ( GA Library, C++)
7  *
8  * COMMENTS: Defaults for attribute data
9  */
10 
11 #ifndef __GA_Defaults__
12 #define __GA_Defaults__
13 
14 #include "GA_API.h"
15 #include "GA_Types.h"
16 #include <UT/UT_Defaults.h>
17 #include <SYS/SYS_Types.h>
18 #include <SYS/SYS_Inline.h>
19 #include <SYS/SYS_StaticAssert.h>
20 
21 class UT_JSONWriter;
22 class UT_JSONParser;
23 class UT_Options;
24 class UT_StringRef;
25 
26 #define GA_DEFAULT_BUFSIZE 4
27 
28 ///@brief Class which stores the default values for a GA_Attribute
29 ///
30 /// This class stores a list of integer/real values which can be used to
31 /// initialize attribute data.
33 {
34 public:
35  typedef UT_Defaults Base;
36 
37  /// Default constructor -- the default will be 0.
38  GA_Defaults() : Base() {}
39 
40  /// Construct by extracting data out of a UT_Options
41  explicit GA_Defaults(const UT_Options *options);
42 
43  /// Construct a set of defaults from variadic arguments. For example
44  /// @code
45  /// GA_Defaults a(GA_STORE_INT32, 3, 0, 1, 2);
46  /// GA_Defaults a(GA_STORE_INT64, 2, int64(0), int64(1));
47  /// GA_Defaults b(GA_STORE_REAL64, 1, fpreal64(0));
48  /// @endcode
49  ///
50  /// This style of construction is a little bit dangerous, so please ensure
51  /// - All data arguments are the right type
52  /// - You have the proper count of variadic arguments
53  /// - You use only one of the supported types: INT32, INT64 or REAL64
54  /// All other types will either cause compiler errors or crashing
55  /// Otherwise, core dumping may occur.
57 
58  /// @{
59  /// Type classes to construct an identity matrix / quaternion as a default.
60  class quaternion {};
61  class matrix3 {};
62  class matrix4 {};
66  /// @}
67 
68  /// @{
69  /// Construct by repeating the value
70  explicit GA_Defaults(int64 value) // Repeated value
71  : Base(value)
72  {
73  }
74  explicit GA_Defaults(int32 value) // Repeated value
75  : Base(value)
76  {
77  }
78  /// Construct by repeating the value
79  explicit GA_Defaults(fpreal64 value) // Repeated value
80  : Base(value)
81  {
82  }
83  explicit GA_Defaults(fpreal32 value) // Repeated value
84  : Base(value)
85  {
86  }
87  /// @}
88 
89  /// @{
90  /// Construct by passing a vector of scalar values
91  /// Note that the defaults will @b copy the data out of the values passed
92  /// in (so the array doesn't have to be persistent).
93  GA_Defaults(const int32 *values, int count) : Base(values, count) {}
94  GA_Defaults(const int64 *values, int count) : Base(values, count) {}
95  GA_Defaults(const fpreal32 *values, int count) : Base(values, count) {}
96  GA_Defaults(const fpreal64 *values, int count) : Base(values, count) {}
97  /// @}
98 
99  /// Copy constructor
100  GA_Defaults(const GA_Defaults &src) : Base((const Base &)src) {}
102 
104  {
105  *((Base*)this) = (const Base&)src;
106  return *this;
107  }
108 
109  /// Copy values from another set of defaults
111  {
112  *this = src;
113  }
114 
115  /// Set the GA_OPTION_DEFAULTS option in the options
116  /// If @c always is false and there are no defaults (i.e. getSize() == 0),
117  /// then the options will not be written.
118  void saveToOptions(UT_Options &options, bool always=true) const;
119 
120  /// @{
121  /// Get a value out of the defaults.
122  /// - Automatically casts defaults into appropriate return type
123  /// - Clamps index to tuple size
124  /// - If there is no default data, then, the result will be 0
125  /// NOTE: There is getI and getF defined in baseclass.
126  void get(int index, int32 &v) const
127  { v = getI(index); }
128  void get(int index, int64 &v) const
129  { v = getI(index); }
130  void get(int index, fpreal32 &v) const
131  { v = getF(index); }
132  void get(int index, fpreal64 &v) const
133  { v = getF(index); }
134  /// @}
135 
136  /// Set defaults to the list of integer values.
137  void set(const int32 *values, int count);
138  /// Set defaults to the list of integer values.
139  void set(const int64 *values, int count);
140  /// Set defaults to the list of real values.
141  void set(const fpreal32 *values, int count);
142  /// Set defaults to the list of real values.
143  void set(const fpreal64 *values, int count);
144 
145  /// Set this to a reasonable guess based on the specified name,
146  /// e.g. Cd -> 1.0; id -> -1; orient -> (0,0,0,1)
147  void guessFromName(const UT_StringRef &name, int tuple_size);
148 
149  /// Get the size of the defaults.
150  /// You can have an attribute tuple size that's
151  /// larger than its GA_Defaults size; the GA_Defaults
152  /// will repeat its last element.
154  int size() const
155  {
156  return getTupleSize();
157  }
158 
159  /// Save data to a JSON stream.
160  /// @section JSON-GA_Defaults JSON Schema: GA_Defaults
161  /// @code
162  /// {
163  /// "name" : "GA_Defaults",
164  /// "description" : "An array of numbers used for attribute defaults",
165  /// "type" : "orderedmap",
166  /// "properties": {
167  /// "size": {
168  /// "type" : "integer",
169  /// "description" : "Number of values",
170  /// },
171  /// "storage": {
172  /// "type" : "string",
173  /// "enum" : ["fpreal64", "int64"],
174  /// "description" : "The type data",
175  /// },
176  /// "values": {
177  /// "type" : "array",
178  /// "items" : "number",
179  /// "description" : "The default values",
180  /// },
181  /// },
182  /// }
183  /// @endcode
184  /// @see @ref JSON_FileFormat
185  bool jsonSave(UT_JSONWriter &w) const;
186 
187  /// Load data from a JSON stream
188  bool jsonLoad(UT_JSONParser &p);
189 };
190 
191 #endif
192 
int int32
Definition: SYS_Types.h:39
GA_Defaults(const int64 *values, int count)
Definition: GA_Defaults.h:94
GA_Defaults()
Default constructor – the default will be 0.
Definition: GA_Defaults.h:38
Class which stores the default values for a GA_Attribute.
Definition: GA_Defaults.h:32
getFileOption("OpenEXR:storage") storage
Definition: HDK_Image.dox:276
const GLdouble * v
Definition: glcorearb.h:837
GA_Defaults & operator=(const GA_Defaults &src)
Definition: GA_Defaults.h:103
GLsizei const GLfloat * value
Definition: glcorearb.h:824
int64 getI(exint i=0) const
Definition: UT_Defaults.h:268
GA_Defaults(fpreal64 value)
Construct by repeating the value.
Definition: GA_Defaults.h:79
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:87
#define GA_API
Definition: GA_API.h:14
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:39
float fpreal32
Definition: SYS_Types.h:200
GA_Defaults(const GA_Defaults &src)
Copy constructor.
Definition: GA_Defaults.h:100
double fpreal64
Definition: SYS_Types.h:201
SYS_FORCE_INLINE void copy(const GA_Defaults &src)
Copy values from another set of defaults.
Definition: GA_Defaults.h:110
constexpr auto set(type rhs) -> int
Definition: core.h:610
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
SYS_FORCE_INLINE int size() const
Definition: GA_Defaults.h:154
GA_Defaults(int32 value)
Definition: GA_Defaults.h:74
long long int64
Definition: SYS_Types.h:116
GA_Defaults(const fpreal64 *values, int count)
Definition: GA_Defaults.h:96
GLuint const GLchar * name
Definition: glcorearb.h:786
UT_Defaults Base
Definition: GA_Defaults.h:35
A map of string to various well defined value types.
Definition: UT_Options.h:87
fpreal64 getF(exint i=0) const
Definition: UT_Defaults.h:244
GLenum GLsizei GLsizei GLint * values
Definition: glcorearb.h:1602
GLuint index
Definition: glcorearb.h:786
GA_Defaults(fpreal32 value)
Definition: GA_Defaults.h:83
GA_Defaults(const fpreal32 *values, int count)
Definition: GA_Defaults.h:95
GA_Defaults(int64 value)
Definition: GA_Defaults.h:70
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
GA_Defaults(const int32 *values, int count)
Definition: GA_Defaults.h:93
SYS_FORCE_INLINE exint getTupleSize() const
Definition: UT_Defaults.h:239
GA_Storage
Definition: GA_Types.h:52
GLint GLsizei count
Definition: glcorearb.h:405
GLenum src
Definition: glcorearb.h:1793