Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

dtool/src/interrogate/functionWriterPtrToPython.cxx

Go to the documentation of this file.
00001 // Filename: functionWriterPtrToPython.cxx
00002 // Created by:  drose (14Sep01)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #include "functionWriterPtrToPython.h"
00020 #include "typeManager.h"
00021 #include "interrogateBuilder.h"
00022 #include "interrogate.h"
00023 #include "interfaceMakerPythonObj.h"
00024 
00025 #include "cppPointerType.h"
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //     Function: FunctionWriterPtrToPython::Constructor
00029 //       Access: Public
00030 //  Description:
00031 ////////////////////////////////////////////////////////////////////
00032 FunctionWriterPtrToPython::
00033 FunctionWriterPtrToPython(CPPType *type) {
00034   _type = TypeManager::unwrap_const(TypeManager::unwrap_pointer(type));
00035   _name = 
00036     "to_python_" + 
00037     InterrogateBuilder::clean_identifier(_type->get_local_name(&parser));
00038 
00039   _pointer_type = new CPPPointerType(_type);
00040 }
00041 
00042 ////////////////////////////////////////////////////////////////////
00043 //     Function: FunctionWriterPtrToPython::Destructor
00044 //       Access: Public
00045 //  Description:
00046 ////////////////////////////////////////////////////////////////////
00047 FunctionWriterPtrToPython::
00048 ~FunctionWriterPtrToPython() {
00049   delete _pointer_type;
00050 }
00051 
00052 ////////////////////////////////////////////////////////////////////
00053 //     Function: FunctionWriterPtrToPython::write_prototype
00054 //       Access: Public, Virtual
00055 //  Description: Outputs the prototype for the function.
00056 ////////////////////////////////////////////////////////////////////
00057 void FunctionWriterPtrToPython::
00058 write_prototype(ostream &out) {
00059   out << "static PyObject *" << _name << "(";
00060   _pointer_type->output_instance(out, "addr", &parser);
00061   out << ", int caller_manages);\n";
00062 }
00063 
00064 ////////////////////////////////////////////////////////////////////
00065 //     Function: FunctionWriterPtrToPython::write_code
00066 //       Access: Public, Virtual
00067 //  Description: Outputs the code for the function.
00068 ////////////////////////////////////////////////////////////////////
00069 void FunctionWriterPtrToPython::
00070 write_code(ostream &out) {
00071   string classobj_func = InterfaceMakerPythonObj::get_builder_name(_type);
00072   out << "static PyObject *\n"
00073       << _name << "(";
00074   _pointer_type->output_instance(out, "addr", &parser);
00075   out << ", int caller_manages) {\n"
00076       << "  PyObject *" << classobj_func << "();\n"
00077       << "  PyObject *classobj = " << classobj_func << "();\n"
00078       << "  PyInstanceObject *instance = (PyInstanceObject *)PyInstance_New(classobj, (PyObject *)NULL, (PyObject *)NULL);\n"
00079       << "  if (instance != (PyInstanceObject *)NULL) {\n"
00080       << "    PyObject *thisptr = PyInt_FromLong((long)addr);\n"
00081       << "    PyDict_SetItemString(instance->in_dict, \"this\", thisptr);\n"
00082       << "  }\n"
00083       << "  return (PyObject *)instance;\n"
00084       << "}\n\n";
00085 }
00086 
00087 ////////////////////////////////////////////////////////////////////
00088 //     Function: FunctionWriterPtrToPython::get_pointer_type
00089 //       Access: Public
00090 //  Description: Returns the type that represents a pointer to the
00091 //               data type.
00092 ////////////////////////////////////////////////////////////////////
00093 CPPType *FunctionWriterPtrToPython::
00094 get_pointer_type() const {
00095   return _pointer_type;
00096 }

Generated on Thu May 1 22:13:00 2003 for DTool by doxygen1.3