// (C) Copyright David Abrahams 2000. Permission to copy, use, modify, sell and // distribute this software is granted provided this copyright notice appears // in all copies. This software is provided "as is" without express or implied // warranty, and with no claim as to its suitability for any purpose. // // The author gratefully acknowleges the support of Dragon Systems, Inc., in // producing this work. #ifndef BASE_OBJECT_DWA051600_H_ # define BASE_OBJECT_DWA051600_H_ # include "pyconfig.h" # include "signatures.h" // really just for type<> # include "wrap_python.h" # include namespace python { namespace detail { // base_object - adds a constructor and non-virtual destructor to a // base Python type (e.g. PyObject, PyTypeObject). template struct base_object : python_type { typedef python_type base_python_type; // Initializes type and reference count. All other fields of base_python_type are 0 base_object(PyTypeObject* type_obj); // Decrements reference count on the type ~base_object(); }; // Easy typedefs for common usage typedef base_object python_object; typedef base_object python_type; // // class_t template member function implementations // template base_object::base_object(PyTypeObject* type_obj) { base_python_type* bp = this; #if !defined(_MSC_VER) || defined(__STLPORT) std:: #endif memset(bp, 0, sizeof(base_python_type)); ob_refcnt = 1; ob_type = type_obj; Py_INCREF(type_obj); } template inline base_object::~base_object() { Py_DECREF(ob_type); } }} // namespace python::detail #endif // BASE_OBJECT_DWA051600_H_