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 #include <stddef.h>
20 
21 
22 class PRM_Template;
23 class UT_Options;
24 
25 /// This is a callback function that can be used to modify data.
26 /// It is invoked when the user uses a parameter of type PRM_CALLBACK
27 /// (this might be a button, or a menu).
28 /// @param data Pointer to the node it was called on
29 /// @param index The index of the menu entry
30 /// @param time Current evaluation time
31 /// @param tplate Pointer to the PRM_Template of the parameter it was
32 /// triggered for.
33 /// @return It should return 1 if you want the dialog to refresh
34 /// (ie if you changed any values) and 0 otherwise.
36 {
37 public:
38  typedef int (*PRM_Callback32)(void *data, int index, fpreal32 time,
39  const PRM_Template *tplate);
40  typedef int (*PRM_Callback64)(void *data, int index, fpreal64 time,
41  const PRM_Template *tplate);
42  typedef int (*PRM_CallbackOpt)(void *data, int index, fpreal64 time,
43  const PRM_Template *tplate,
44  const UT_Options *options);
45 
47  {
48  myCallback64 = NULL;
49  myCallback32 = NULL;
50  myCallbackOpt = NULL;
51  }
53  {
54  UT_ASSERT(ptr == 0);
55  myCallback64 = NULL;
56  myCallback32 = NULL;
57  myCallbackOpt = NULL;
58  }
59  PRM_Callback(long int ptr)
60  {
61  UT_ASSERT(ptr == 0);
62  myCallback64 = NULL;
63  myCallback32 = NULL;
64  myCallbackOpt = NULL;
65  }
66  PRM_Callback(std::nullptr_t)
67  {
68  myCallback64 = NULL;
69  myCallback32 = NULL;
70  myCallbackOpt = NULL;
71  }
73  {
74  myCallback64 = NULL;
75  myCallback32 = cb;
76  myCallbackOpt = NULL;
77  }
79  {
80  myCallback64 = cb;
81  myCallback32 = NULL;
82  myCallbackOpt = NULL;
83  }
85  {
86  myCallback64 = NULL;
87  myCallback32 = NULL;
88  myCallbackOpt = cb;
89  }
90 
91  int operator()(void *data, int index, fpreal64 time,
92  const PRM_Template *tplate)
93  {
94  if (myCallbackOpt)
95  return myCallbackOpt(data, index, time, tplate, 0);
96  else if (myCallback64)
97  return myCallback64(data, index, time, tplate);
98  else if (myCallback32)
99  return myCallback32(data, index, fpreal32(time), tplate);
100  return 0;
101  }
102  int operator()(void *data, int index, fpreal64 time,
103  const PRM_Template *tplate,
104  const UT_Options *options)
105  {
106  if (myCallbackOpt)
107  return myCallbackOpt(data, index, time, tplate, options);
108  else if (myCallback64)
109  return myCallback64(data, index, time, tplate);
110  else if (myCallback32)
111  return myCallback32(data, index, fpreal32(time), tplate);
112  return 0;
113  }
114  bool operator==(const PRM_Callback &other)
115  {
116  return (myCallbackOpt == other.myCallbackOpt
117  && myCallback64 == other.myCallback64
118  && myCallback32 == other.myCallback32);
119  }
120 
121  bool isNotNull() const
122  {
123  return (myCallbackOpt || myCallback64 || myCallback32);
124  }
125  bool isNull() const
126  {
127  return !isNotNull();
128  }
129 
130 private:
131  PRM_CallbackOpt myCallbackOpt;
132  PRM_Callback64 myCallback64;
133  PRM_Callback32 myCallback32;
134 };
135 
136 #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:38
GLboolean * data
Definition: glcorearb.h:131
GT_API const UT_StringHolder time
bool isNull() const
Definition: PRM_Callback.h:125
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:102
PRM_Callback(PRM_CallbackOpt cb)
Definition: PRM_Callback.h:84
PRM_Callback(PRM_Callback64 cb)
Definition: PRM_Callback.h:78
float fpreal32
Definition: SYS_Types.h:200
int operator()(void *data, int index, fpreal64 time, const PRM_Template *tplate)
Definition: PRM_Callback.h:91
PRM_Callback(long int ptr)
Definition: PRM_Callback.h:59
double fpreal64
Definition: SYS_Types.h:201
int(* PRM_Callback64)(void *data, int index, fpreal64 time, const PRM_Template *tplate)
Definition: PRM_Callback.h:40
bool isNotNull() const
Definition: PRM_Callback.h:121
bool operator==(const PRM_Callback &other)
Definition: PRM_Callback.h:114
PRM_Callback(PRM_Callback32 cb)
Definition: PRM_Callback.h:72
int(* PRM_CallbackOpt)(void *data, int index, fpreal64 time, const PRM_Template *tplate, const UT_Options *options)
Definition: PRM_Callback.h:42
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:2448
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
PRM_Callback(std::nullptr_t)
Definition: PRM_Callback.h:66
Definition: format.h:895