HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PRM_Callback.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: PRM_Callback.h (PRM Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __PRM_CALLBACK_H_INCLUDED__
12 #define __PRM_CALLBACK_H_INCLUDED__
13 
14 #include "PRM_API.h"
15 
16 #include <UT/UT_Assert.h>
17 #include <SYS/SYS_Types.h>
18 
19 
20 class PRM_Template;
21 class UT_Options;
22 
23 /// This is a callback function that can be used to modify data.
24 /// It is invoked when the user uses a parameter of type PRM_CALLBACK
25 /// (this might be a button, or a menu).
26 /// @param data Pointer to the node it was called on
27 /// @param index The index of the menu entry
28 /// @param time Current evaluation time
29 /// @param tplate Pointer to the PRM_Template of the parameter it was
30 /// triggered for.
31 /// @return It should return 1 if you want the dialog to refresh
32 /// (ie if you changed any values) and 0 otherwise.
34 {
35 public:
36  typedef int (*PRM_Callback32)(void *data, int index, fpreal32 time,
37  const PRM_Template *tplate);
38  typedef int (*PRM_Callback64)(void *data, int index, fpreal64 time,
39  const PRM_Template *tplate);
40  typedef int (*PRM_CallbackOpt32)(void *data, int index, fpreal32 time,
41  const PRM_Template *tplate,
42  const UT_Options *options);
43  typedef int (*PRM_CallbackOpt64)(void *data, int index, fpreal64 time,
44  const PRM_Template *tplate,
45  const UT_Options *options);
46 
48  : myTag(TagCallback64)
49  , myCallback64(nullptr)
50  {
51  }
53  : PRM_Callback()
54  {
55  UT_ASSERT(ptr == 0);
56  }
57  PRM_Callback(long int ptr)
58  : PRM_Callback()
59  {
60  UT_ASSERT(ptr == 0);
61  }
62  PRM_Callback(std::nullptr_t)
63  : PRM_Callback()
64  {
65  }
67  : myTag(TagCallback32)
68  , myCallback32(cb)
69  {
70  }
72  : myTag(TagCallback64)
73  , myCallback64(cb)
74  {
75  }
77  : myTag(TagCallbackOpt32)
78  , myCallbackOpt32(cb)
79  {
80  }
82  : myTag(TagCallbackOpt64)
83  , myCallbackOpt64(cb)
84  {
85  }
86 
87  int operator()(void *data, int index, fpreal64 time,
88  const PRM_Template *tplate)
89  {
90  switch (myTag)
91  {
92  case TagCallback64:
93  return myCallback64(data, index, time, tplate);
94  case TagCallback32:
95  return myCallback32(data, index, fpreal32(time), tplate);
96  case TagCallbackOpt64:
97  return myCallbackOpt64(data, index, time, tplate, nullptr);
98  case TagCallbackOpt32:
99  return myCallbackOpt32(data, index, fpreal32(time), tplate,
100  nullptr);
101  }
102  UT_ASSERT(!"Invalid tag");
103  return 0;
104  }
105  int operator()(void *data, int index, fpreal64 time,
106  const PRM_Template *tplate,
107  const UT_Options *options)
108  {
109  switch (myTag)
110  {
111  case TagCallback64:
112  return myCallback64(data, index, time, tplate);
113  case TagCallback32:
114  return myCallback32(data, index, fpreal32(time), tplate);
115  case TagCallbackOpt64:
116  return myCallbackOpt64(data, index, time, tplate, options);
117  case TagCallbackOpt32:
118  return myCallbackOpt32(data, index, fpreal32(time), tplate,
119  options);
120  }
121  UT_ASSERT(!"Invalid tag");
122  return 0;
123  }
124  bool operator==(const PRM_Callback &other)
125  {
126  if (myTag != other.myTag)
127  return false;
128  switch (myTag)
129  {
130  case TagCallback64:
131  return myCallback64 == other.myCallback64;
132  case TagCallback32:
133  return myCallback32 == other.myCallback32;
134  case TagCallbackOpt64:
135  return myCallbackOpt64 == other.myCallbackOpt64;
136  case TagCallbackOpt32:
137  return myCallbackOpt32 == other.myCallbackOpt32;
138  }
139  UT_ASSERT(!"Invalid tag");
140  return false;
141  }
142 
143  bool isNotNull() const
144  {
145  switch (myTag)
146  {
147  case TagCallback64:
148  return myCallback64;
149  case TagCallback32:
150  return myCallback32;
151  case TagCallbackOpt64:
152  return myCallbackOpt64;
153  case TagCallbackOpt32:
154  return myCallbackOpt32;
155  }
156  UT_ASSERT(!"Invalid tag");
157  return false;
158  }
159  bool isNull() const
160  {
161  return !isNotNull();
162  }
163 
164 private:
165  enum
166  {
167  TagCallback64,
168  TagCallback32,
169  TagCallbackOpt64,
170  TagCallbackOpt32
171  } myTag;
172  union
173  {
178  };
179 };
180 
181 #endif // __PRM_CALLBACK_H_INCLUDED__
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
int(* PRM_Callback32)(void *data, int index, fpreal32 time, const PRM_Template *tplate)
Definition: PRM_Callback.h:36
int(* PRM_CallbackOpt64)(void *data, int index, fpreal64 time, const PRM_Template *tplate, const UT_Options *options)
Definition: PRM_Callback.h:43
GLboolean * data
Definition: glcorearb.h:131
GT_API const UT_StringHolder time
bool isNull() const
Definition: PRM_Callback.h:159
PRM_Callback(int ptr)
Definition: PRM_Callback.h:52
int operator()(void *data, int index, fpreal64 time, const PRM_Template *tplate, const UT_Options *options)
Definition: PRM_Callback.h:105
PRM_Callback64 myCallback64
Definition: PRM_Callback.h:174
PRM_Callback(PRM_Callback64 cb)
Definition: PRM_Callback.h:71
float fpreal32
Definition: SYS_Types.h:200
int operator()(void *data, int index, fpreal64 time, const PRM_Template *tplate)
Definition: PRM_Callback.h:87
PRM_Callback(long int ptr)
Definition: PRM_Callback.h:57
PRM_CallbackOpt32 myCallbackOpt32
Definition: PRM_Callback.h:177
double fpreal64
Definition: SYS_Types.h:201
int(* PRM_Callback64)(void *data, int index, fpreal64 time, const PRM_Template *tplate)
Definition: PRM_Callback.h:38
bool isNotNull() const
Definition: PRM_Callback.h:143
PRM_CallbackOpt64 myCallbackOpt64
Definition: PRM_Callback.h:176
bool operator==(const PRM_Callback &other)
Definition: PRM_Callback.h:124
PRM_Callback(PRM_Callback32 cb)
Definition: PRM_Callback.h:66
PRM_Callback(PRM_CallbackOpt32 cb)
Definition: PRM_Callback.h:76
A map of string to various well defined value types.
Definition: UT_Options.h:84
GLuint index
Definition: glcorearb.h:786
auto ptr(T p) -> const void *
Definition: format.h:4331
int(* PRM_CallbackOpt32)(void *data, int index, fpreal32 time, const PRM_Template *tplate, const UT_Options *options)
Definition: PRM_Callback.h:40
PRM_Callback(PRM_CallbackOpt64 cb)
Definition: PRM_Callback.h:81
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
PRM_Callback(std::nullptr_t)
Definition: PRM_Callback.h:62
PRM_Callback32 myCallback32
Definition: PRM_Callback.h:175
Definition: format.h:1821