HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PY_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  * COMMENTS:
7  * Instances of this class hold a Python callback (any callable Python
8  * object). You can invoke this callback with the call() method, passing
9  * it optional arguments. When this object is destroyed, the reference
10  * count on the Python callback will be decremented.
11  */
12 
13 #ifndef __PY_Callback_h__
14 #define __PY_Callback_h__
15 
16 #include "PY_API.h"
17 #include "PY_OpaqueObject.h"
18 #include "PY_Result.h"
19 
21 {
22 public:
23  // Construct instances of this class with an opaque PY_PyObject
24  // containing a callable Python object.
25  PY_Callback(void *python_callable_object)
26  : PY_OpaqueObject(python_callable_object)
27  {}
28 
29  PY_Callback(const PY_Callback &callback)
30  : PY_OpaqueObject(callback)
31  {}
32 
33  PY_Callback &operator=(const PY_Callback &callback)
34  { return (PY_Callback &)PY_OpaqueObject::operator=(callback); }
35 
36  // Given two strings containing Python expressions (one that evaluates to
37  // a tuple of arguments and another that evaluates to a dictionary of
38  // keyword arguments), call the callback. Either or both of the argument
39  // tuple and keyword argument dictionary may be null. The result is
40  // returned in the PY_Result object.
41  void call(PY_Result &result, const char *args_expression=NULL,
42  const char *kwargs_expression=NULL) const;
43 
44  // This convenience version of call() returns the PY_Result by value,
45  // instead of passing it in by reference. This versions can be used by
46  // code that isn't performance-critical.
47  PY_Result call(const char *args_expression=NULL,
48  const char *kwargs_expression=NULL) const
49  {
50  PY_Result result;
51  call(result, args_expression, kwargs_expression);
52  return result;
53  }
54 
55 };
56 
57 #endif
PY_Callback(void *python_callable_object)
Definition: PY_Callback.h:25
PY_Callback & operator=(const PY_Callback &callback)
Definition: PY_Callback.h:33
#define PY_API
Definition: PY_API.h:10
PY_OpaqueObject & operator=(const PY_OpaqueObject &opaque_object)
PY_Callback(const PY_Callback &callback)
Definition: PY_Callback.h:29
PY_Result call(const char *args_expression=NULL, const char *kwargs_expression=NULL) const
Definition: PY_Callback.h:47