HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 ptr)
67  {
68  UT_ASSERT(ptr == nullptr);
69  myCallback64 = NULL;
70  myCallback32 = NULL;
71  myCallbackOpt = NULL;
72  }
74  {
75  myCallback64 = NULL;
76  myCallback32 = cb;
77  myCallbackOpt = NULL;
78  }
80  {
81  myCallback64 = cb;
82  myCallback32 = NULL;
83  myCallbackOpt = NULL;
84  }
86  {
87  myCallback64 = NULL;
88  myCallback32 = NULL;
89  myCallbackOpt = cb;
90  }
91 
92  int operator()(void *data, int index, fpreal64 time,
93  const PRM_Template *tplate)
94  {
95  if (myCallbackOpt)
96  return myCallbackOpt(data, index, time, tplate, 0);
97  else if (myCallback64)
98  return myCallback64(data, index, time, tplate);
99  else if (myCallback32)
100  return myCallback32(data, index, fpreal32(time), tplate);
101  return 0;
102  }
103  int operator()(void *data, int index, fpreal64 time,
104  const PRM_Template *tplate,
105  const UT_Options *options)
106  {
107  if (myCallbackOpt)
108  return myCallbackOpt(data, index, time, tplate, options);
109  else if (myCallback64)
110  return myCallback64(data, index, time, tplate);
111  else if (myCallback32)
112  return myCallback32(data, index, fpreal32(time), tplate);
113  return 0;
114  }
115  bool operator==(const PRM_Callback &other)
116  {
117  return (myCallbackOpt == other.myCallbackOpt
118  && myCallback64 == other.myCallback64
119  && myCallback32 == other.myCallback32);
120  }
121 
122  bool isNotNull() const
123  {
124  return (myCallbackOpt || myCallback64 || myCallback32);
125  }
126  bool isNull() const
127  {
128  return !isNotNull();
129  }
130 
131 private:
132  PRM_CallbackOpt myCallbackOpt;
133  PRM_Callback64 myCallback64;
134  PRM_Callback32 myCallback32;
135 };
136 
137 #endif // __PRM_CALLBACK_H_INCLUDED__
int(* PRM_Callback32)(void *data, int index, fpreal32 time, const PRM_Template *tplate)
Definition: PRM_Callback.h:38
png_voidp ptr
Definition: png.h:2145
bool isNull() const
Definition: PRM_Callback.h:126
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:103
PRM_Callback(PRM_CallbackOpt cb)
Definition: PRM_Callback.h:85
PRM_Callback(PRM_Callback64 cb)
Definition: PRM_Callback.h:79
int operator()(void *data, int index, fpreal64 time, const PRM_Template *tplate)
Definition: PRM_Callback.h:92
PRM_Callback(long int ptr)
Definition: PRM_Callback.h:59
PRM_Callback(std::nullptr_t ptr)
Definition: PRM_Callback.h:66
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:102
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:122
double fpreal64
Definition: SYS_Types.h:185
bool operator==(const PRM_Callback &other)
Definition: PRM_Callback.h:115
GLboolean * data
Definition: glcorearb.h:130
PRM_Callback(PRM_Callback32 cb)
Definition: PRM_Callback.h:73
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:42
typedef int
Definition: png.h:1175
GLuint index
Definition: glcorearb.h:785
float fpreal32
Definition: SYS_Types.h:184