00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
00029
00030
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
00044
00045
00046
00047 FunctionWriterPtrToPython::
00048 ~FunctionWriterPtrToPython() {
00049 delete _pointer_type;
00050 }
00051
00052
00053
00054
00055
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
00066
00067
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
00089
00090
00091
00092
00093 CPPType *FunctionWriterPtrToPython::
00094 get_pointer_type() const {
00095 return _pointer_type;
00096 }