00001 /* 00002 * PROPRIETARY INFORMATION. This software is proprietary to 00003 * Side Effects Software Inc., and is not to be reproduced, 00004 * transmitted, or disclosed in any way without written permission. 00005 * 00006 * Produced by: 00007 * Side Effects Software Inc 00008 * 123 Front Street West, Suite 1401 00009 * Toronto, Ontario 00010 * Canada M5J 2M2 00011 * 416-504-9876 00012 * 00013 * COMMENTS: 00014 * Instances of this class hold a Python callback (any callable Python 00015 * object). You can invoke this callback with the call() method, passing 00016 * it optional arguments. When this object is destroyed, the reference 00017 * count on the Python callback will be decremented. 00018 */ 00019 00020 #ifndef __PY_Callback_h__ 00021 #define __PY_Callback_h__ 00022 00023 #include "PY_API.h" 00024 #include "PY_Result.h" 00025 00026 class PY_API PY_Callback 00027 { 00028 public: 00029 // Construct instances of this class with an abstract PY_PyObject 00030 // containing a callable Python object. The constructor assumes that 00031 // someone else has already incremented the reference count, and the 00032 // destructor will decrement the count. 00033 PY_Callback(void *python_callable_object); 00034 ~PY_Callback(); 00035 00036 PY_Callback(const PY_Callback &callback); 00037 PY_Callback &operator=(const PY_Callback &callback); 00038 00039 bool operator==(const PY_Callback &callback) const; 00040 bool operator!=(const PY_Callback &callback) const 00041 { return !operator==(callback); } 00042 00043 // Given an opaque PyObject *, return whether or not our callback is the 00044 // same as it. 00045 bool equalsOpaqueCallback(void *opaque_callback) const; 00046 00047 // Return a borrowed reference to the opaque PyObject * containing the 00048 // callback. If the caller will hold a reference to this object after 00049 // the PY_Callback has been deleted, it is up to the caller to increment 00050 // the reference count. 00051 void *opaqueCallback() const 00052 { return myOpaqueCallback; } 00053 00054 // Given two strings containing Python expressions (one that evaluates to 00055 // a tuple of arguments and another that evaluates to a dictionary of 00056 // keyword arguments), call the callback. Either or both of the argument 00057 // tuple and keyword argument dictionary may be null. The result is 00058 // returned in the PY_Result object. 00059 void call(PY_Result &result, const char *args_expression=NULL, 00060 const char *kwargs_expression=NULL) const; 00061 00062 // This convenience version of call() returns the PY_Result by value, 00063 // instead of passing it in by reference. This versions can be used by 00064 // code that isn't performance-critical. 00065 PY_Result call(const char *args_expression=NULL, 00066 const char *kwargs_expression=NULL) const 00067 { 00068 PY_Result result; 00069 call(result, args_expression, kwargs_expression); 00070 return result; 00071 } 00072 00073 private: 00074 void *myOpaqueCallback; 00075 }; 00076 00077 #endif
1.5.9