HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PY_AutoObject.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  * Use this class to automatically decrement the reference count on
8  * python objects.
9  *
10  * So many functions in the python API return a new reference
11  * that we don't increment the reference when you assign to this
12  * smart pointer. If you're calling a python function that returns
13  * a borrowed reference, use a PyObject* instead of this class.
14  *
15  * You should only need to include this file in .C files, not in .h files.
16  * For a class that is ok to include from .h files see PY_OpaqueObject.
17  */
18 
19 #ifndef __PY_AutoObject_h__
20 #define __PY_AutoObject_h__
21 
22 // Note that including this file may include the Python headers, which need
23 // to be included first to avoid gcc warnings.
24 #include "PY_CPythonAPI.h"
25 
26 // This class takes care of automatically decrementing the reference count
27 // on python objects.
29 {
30 public:
31  // This class will work with null py_object pointers because it calls
32  // PY_Py_XDECREF().
34  : myPyObject(py_object)
35  {}
36 
38  { PY_Py_XDECREF(myPyObject); }
39 
41  {
42  if (myPyObject != py_object)
43  {
44  PY_Py_XDECREF(myPyObject);
45  myPyObject = py_object;
46  }
47  return *this;
48  }
49 
50  operator PY_PyObject*()
51  { return myPyObject; }
52 
54  { return myPyObject; }
55 
57  { return myPyObject; }
58 
59 private:
60  PY_PyObject *myPyObject;
61 };
62 
63 #endif
PY_PyObject * ptr()
Definition: PY_AutoObject.h:56
PY_AutoObject & operator=(PY_PyObject *py_object)
Definition: PY_AutoObject.h:40
PY_AutoObject(PY_PyObject *py_object)
Definition: PY_AutoObject.h:33
#define PY_Py_XDECREF(op)
PY_PyObject * operator->()
Definition: PY_AutoObject.h:53
PY_PyObject