15 if(type ==
"int"){
return "i";}
16 else if(type ==
"float"){
return "f";}
17 else if(type ==
"double"){
return "d";}
18 else if(type ==
"char"){
return "c";}
19 else if(type ==
"std::string"){
return "s";}
30 if(type ==
"float" || type ==
"double"){
return "PyFloat_AsDouble";}
31 else if(type ==
"long" || type ==
"short" || type ==
"char"){
return "PyLong_AsLong";}
32 else if(type ==
"int"){
return "PyLong_AsInt";}
33 else if(type ==
"size_t"){
return "PyLong_ToSize_t";}
35 return "UnknownConvertFunctionToValue";
44 if(type ==
"float" || type ==
"double"){
return "PyFloat_FromDouble";}
45 else if(type ==
"long" || type ==
"short" || type ==
"char" || type ==
"int"){
return "PyLong_FromLong";}
46 else if(type ==
"unsigned long" || type ==
"unsigned short" || type ==
"unsigned char" || type ==
"unsigned int"){
return "PyLong_FromLong";}
47 else if(type ==
"size_t"){
return "PyLong_FromSize_t";}
49 return "UnknownConvertFunctionFromValue";
58 if(type ==
"long" || type ==
"int" || type ==
"short" || type ==
"char"){
return "int";}
59 else if(type ==
"float" || type ==
"double"){
return "float";}
60 else if(type ==
"std::string"){
return "std";}
62 return "NoPythonTypeYet";
71 return "WP"+classConfig.
getName();
80 body +=
"\tif(!PyArg_ParseTuple(args, \"O\", &"+varName+
")){\n";
81 body +=
"\t\tPyErr_SetString(PyExc_RuntimeError, \"missing filename or keyword not supported\\n\");\n";
82 body +=
"\t\treturn NULL;\n";
97 body +=
"\tPyObject *";
99 body +=
" "+attr.
getName()+
";\n";
112 body +=
"///Define the type of the "+className+
"\n";
113 body +=
"PyTypeObject "+className+
"Type = {\n";
114 body +=
"\tPyVarObject_HEAD_INIT("+fromOtherType+
", 0)\n";
115 body +=
"\t\""+moduleName+
"."+classConfig.
getName()+
"\", /* tp_name */\n";
116 body +=
"\tsizeof("+className+
"), /* tp_basicsize */\n";
117 body +=
"\t0, /* tp_itemsize */\n";
118 body +=
"\t(destructor)"+className+
"_dealloc, /* tp_dealloc */\n";
119 body +=
"\t0, /* tp_print */\n";
120 body +=
"\t0, /* tp_getattr */\n";
121 body +=
"\t0, /* tp_setattr */\n";
122 body +=
"\t0, /* tp_reserved */\n";
123 body +=
"\t0, /* tp_repr */\n";
124 body +=
"\t0, /* tp_as_number */\n";
125 body +=
"\t0, /* tp_as_sequence */\n";
126 body +=
"\t0, /* tp_as_mapping */\n";
127 body +=
"\t0, /* tp_hash */\n";
128 body +=
"\t0, /* tp_call */\n";
129 body +=
"\t0, /* tp_str */\n";
130 body +=
"\t0, /* tp_getattro */\n";
131 body +=
"\t0, /* tp_setattro */\n";
132 body +=
"\t0, /* tp_as_buffer */\n";
133 body +=
"\tPy_TPFLAGS_DEFAULT |\n";
134 body +=
"\tPy_TPFLAGS_BASETYPE, /* tp_flags */\n";
135 body +=
"\t\""+className+
" doc : "+classConfig.
getClassDocumentation().replace(
"///",
"")+
"\", /* tp_doc */\n";
136 body +=
"\t0, /* tp_traverse */\n";
137 body +=
"\t0, /* tp_clear */\n";
138 body +=
"\t0, /* tp_richcompare */\n";
139 body +=
"\t0, /* tp_weaklistoffset */\n";
140 body +=
"\t0, /* tp_iter */\n";
141 body +=
"\t0, /* tp_iternext */\n";
142 body +=
"\t"+className+
"_methods, /* tp_methods */\n";
143 body +=
"\t"+className+
"_members, /* tp_members */\n";
144 body +=
"\t"+className+
"_getseters,/* tp_getset */\n";
145 body +=
"\t0, /* tp_base */\n";
146 body +=
"\t0, /* tp_dict */\n";
147 body +=
"\t0, /* tp_descr_get */\n";
148 body +=
"\t0, /* tp_descr_set */\n";
149 body +=
"\t0, /* tp_dictoffset */\n";
150 body +=
"\t0, /* tp_init */\n";
151 body +=
"\t0, /* tp_alloc */\n";
152 body +=
"\t"+className+
"_newC, /* tp_new */\n";
Describes a class attribute.
const PString & getDocumentation() const
Gets the documentation of the PClassAttribute.
const PString & getType() const
Gets the type of the PClassAttribute.
const PString & getName() const
Gets the name of the PClassAttribute.
Class to describe a basic class.
const PString & getClassDocumentation() const
Returns the class documentation.
const PString & getName() const
Returns the class name.
bool getIsSimpleType(const PString &varType)
Check if the given type is a simple type.
PString project_wrapper_classImplPythonType(const PClassConfig &classConfig, const PString &moduleName, const PString &fromOtherType)
Create the Python type of the given class.
PString wrapper_getExpectedType(const PString &type)
Get the expected type of a given python type.
PString wrapper_getObjectToValue(const PString &type)
Get the function to convert the given object to a value.
PString project_wrapper_attributeDef(const PClassAttribute &attr)
Get the C++ definition of an attribute.
PString wrapper_getObjectParseTuple(const PString &varName)
Get the proper code for PyArg_ParseTuple with one object.
PString wrapper_getBuildValueStr(const PString &type)
Get the string description of the Py_BuildValue call for the given type.
PString wrapper_getValueToObject(const PString &type)
Get the function to convert the given value to a PyObject.
PString wrapper_getClassName(const PClassConfig &classConfig)
Get the corresponding wrapper class name.