diff --git a/dtool/src/interrogate/Sources.pp b/dtool/src/interrogate/Sources.pp index 07510a6275..8bc1e057fe 100644 --- a/dtool/src/interrogate/Sources.pp +++ b/dtool/src/interrogate/Sources.pp @@ -18,7 +18,9 @@ interfaceMakerPythonSimple.h \ interfaceMakerPythonNative.h \ interrogate.h interrogateBuilder.h parameterRemap.I \ - parameterRemap.h parameterRemapBasicStringRefToString.h \ + parameterRemap.h \ + parameterRemapBasicStringPtrToString.h \ + parameterRemapBasicStringRefToString.h \ parameterRemapBasicStringToString.h \ parameterRemapCharStarToString.h \ parameterRemapConcreteToPointer.h \ @@ -40,6 +42,7 @@ interfaceMakerPythonSimple.cxx \ interfaceMakerPythonNative.cxx \ interrogate.cxx interrogateBuilder.cxx parameterRemap.cxx \ + parameterRemapBasicStringPtrToString.cxx \ parameterRemapBasicStringRefToString.cxx \ parameterRemapBasicStringToString.cxx \ parameterRemapCharStarToString.cxx \ diff --git a/dtool/src/interrogate/interfaceMaker.cxx b/dtool/src/interrogate/interfaceMaker.cxx index 69918d64b0..00014dc35b 100644 --- a/dtool/src/interrogate/interfaceMaker.cxx +++ b/dtool/src/interrogate/interfaceMaker.cxx @@ -28,6 +28,7 @@ #include "parameterRemapCharStarToString.h" #include "parameterRemapBasicStringToString.h" #include "parameterRemapBasicStringRefToString.h" +#include "parameterRemapBasicStringPtrToString.h" #include "parameterRemapPTToPointer.h" #include "interrogateDatabase.h" @@ -354,11 +355,20 @@ remap_parameter(CPPType *struct_type, CPPType *param_type) { } else if (TypeManager::is_const_ref_to_basic_string_char(param_type)) { return new ParameterRemapBasicStringRefToString(param_type); + } else if (TypeManager::is_const_ptr_to_basic_string_char(param_type)) { + return new ParameterRemapBasicStringPtrToString(param_type); + } else if (TypeManager::is_basic_string_wchar(param_type)) { return new ParameterRemapBasicWStringToWString(param_type); } else if (TypeManager::is_const_ref_to_basic_string_wchar(param_type)) { return new ParameterRemapBasicWStringRefToWString(param_type); + + } else if (TypeManager::is_const_ptr_to_basic_string_char(param_type)) { + return new ParameterRemapBasicStringPtrToString(param_type); + + } else if (TypeManager::is_const_ptr_to_basic_string_wchar(param_type)) { + return new ParameterRemapBasicWStringPtrToWString(param_type); } } } diff --git a/dtool/src/interrogate/interfaceMakerPythonNative.cxx b/dtool/src/interrogate/interfaceMakerPythonNative.cxx index 4a04880cb7..98dcf9b0dd 100755 --- a/dtool/src/interrogate/interfaceMakerPythonNative.cxx +++ b/dtool/src/interrogate/interfaceMakerPythonNative.cxx @@ -2383,6 +2383,29 @@ write_function_instance(ostream &out, InterfaceMaker::Object *obj, param_name + "_len)"; extra_cleanup += " delete[] " + param_name + "_str;"; + + } else if (TypeManager::is_const_ptr_to_basic_string_wchar(orig_type)) { + indent(out,indent_level) << "PyUnicodeObject *" << param_name << "\n"; + format_specifiers += "U"; + parameter_list += ", &" + param_name; + + extra_convert += " int " + param_name + "_len = PyUnicode_GetSize((PyObject *)" + param_name + "); wchar_t *" + param_name + "_str = new wchar_t[" + param_name + "_len]; PyUnicode_AsWideChar(" + param_name + ", " + param_name + "_str, " + param_name + "_len);"; + + pexpr_string = "&basic_string((wchar_t *)" + + param_name + "_str, " + + param_name + "_len)"; + + extra_cleanup += " delete[] " + param_name + "_str;"; + + } else if (TypeManager::is_const_ptr_to_basic_string_char(orig_type)) { + indent(out,indent_level) << "char *" << param_name + << "_str; int " << param_name << "_len"; + format_specifiers += "s#"; + parameter_list += ", &" + param_name + + "_str, &" + param_name + "_len"; + pexpr_string = "&basic_string(" + + param_name + "_str, " + + param_name + "_len)"; } else { indent(out,indent_level) << "char *" << param_name @@ -2767,6 +2790,28 @@ void InterfaceMakerPythonNative::pack_return_value(ostream &out, int indent_leve << "return PyUnicode_FromWideChar(" << return_expr << ".data(), (int)" << return_expr << ".length());\n"; + } else if (TypeManager::is_const_ptr_to_basic_string_wchar(orig_type)) { + indent(out, indent_level)<<"if("<< return_expr<< " == NULL)\n"; + indent(out, indent_level)<<"{\n"; + indent(out, indent_level)<<" Py_INCREF(Py_None);\n"; + indent(out, indent_level)<<" return Py_None;\n"; + indent(out, indent_level)<<"}\n"; + + indent(out, indent_level) + << "return PyUnicode_FromWideChar(" + << return_expr << "->data(), (int)" << return_expr << "->length());\n"; + + } else if (TypeManager::is_const_ptr_to_basic_string_char(orig_type)) { + indent(out, indent_level)<<"if("<< return_expr<< " == NULL)\n"; + indent(out, indent_level)<<"{\n"; + indent(out, indent_level)<<" Py_INCREF(Py_None);\n"; + indent(out, indent_level)<<" return Py_None;\n"; + indent(out, indent_level)<<"}\n"; + + indent(out, indent_level) + << "return PyString_FromStringAndSize(" + << return_expr << "->data(), (int)" << return_expr << "->length());\n"; + } else { indent(out, indent_level) << "return PyString_FromStringAndSize(" diff --git a/dtool/src/interrogate/interrogate_composite2.cxx b/dtool/src/interrogate/interrogate_composite2.cxx index 60450ad348..39000d2778 100644 --- a/dtool/src/interrogate/interrogate_composite2.cxx +++ b/dtool/src/interrogate/interrogate_composite2.cxx @@ -2,6 +2,7 @@ #include "interrogate.cxx" #include "typeManager.cxx" #include "parameterRemap.cxx" +#include "parameterRemapBasicStringPtrToString.cxx" #include "parameterRemapBasicStringRefToString.cxx" #include "parameterRemapBasicStringToString.cxx" #include "parameterRemapCharStarToString.cxx" diff --git a/dtool/src/interrogate/parameterRemapBasicStringPtrToString.cxx b/dtool/src/interrogate/parameterRemapBasicStringPtrToString.cxx new file mode 100644 index 0000000000..bb111935b2 --- /dev/null +++ b/dtool/src/interrogate/parameterRemapBasicStringPtrToString.cxx @@ -0,0 +1,85 @@ +// Filename: parameterRemapBasicStringPtrToString.cxx +// Created by: drose (11Aug09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "parameterRemapBasicStringPtrToString.h" + +//////////////////////////////////////////////////////////////////// +// Function: ParameterRemapBasicStringPtrToString::Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +ParameterRemapBasicStringPtrToString:: +ParameterRemapBasicStringPtrToString(CPPType *orig_type) : + ParameterRemapToString(orig_type) +{ +} + +//////////////////////////////////////////////////////////////////// +// Function: ParameterRemapBasicStringPtrToString::pass_parameter +// Access: Public, Virtual +// Description: Outputs an expression that converts the indicated +// variable from the original type to the new type, for +// passing into the actual C++ function. +//////////////////////////////////////////////////////////////////// +void ParameterRemapBasicStringPtrToString:: +pass_parameter(ostream &out, const string &variable_name) { + out << "&" << variable_name; +} + +//////////////////////////////////////////////////////////////////// +// Function: ParameterRemapBasicStringPtrToString::get_return_expr +// Access: Public, Virtual +// Description: Returns an expression that evalutes to the +// appropriate value type for returning from the +// function, given an expression of the original type. +//////////////////////////////////////////////////////////////////// +string ParameterRemapBasicStringPtrToString:: +get_return_expr(const string &expression) { + return "(" + expression + ")->c_str()"; +} + +//////////////////////////////////////////////////////////////////// +// Function: ParameterRemapBasicWStringPtrToWString::Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +ParameterRemapBasicWStringPtrToWString:: +ParameterRemapBasicWStringPtrToWString(CPPType *orig_type) : + ParameterRemapToWString(orig_type) +{ +} + +//////////////////////////////////////////////////////////////////// +// Function: ParameterRemapBasicWStringPtrToWString::pass_parameter +// Access: Public, Virtual +// Description: Outputs an expression that converts the indicated +// variable from the original type to the new type, for +// passing into the actual C++ function. +//////////////////////////////////////////////////////////////////// +void ParameterRemapBasicWStringPtrToWString:: +pass_parameter(ostream &out, const string &variable_name) { + out << "&" << variable_name; +} + +//////////////////////////////////////////////////////////////////// +// Function: ParameterRemapBasicWStringPtrToWString::get_return_expr +// Access: Public, Virtual +// Description: Returns an expression that evalutes to the +// appropriate value type for returning from the +// function, given an expression of the original type. +//////////////////////////////////////////////////////////////////// +string ParameterRemapBasicWStringPtrToWString:: +get_return_expr(const string &expression) { + return "(" + expression + ")->c_str()"; +} diff --git a/dtool/src/interrogate/parameterRemapBasicStringPtrToString.h b/dtool/src/interrogate/parameterRemapBasicStringPtrToString.h new file mode 100644 index 0000000000..ef4f686195 --- /dev/null +++ b/dtool/src/interrogate/parameterRemapBasicStringPtrToString.h @@ -0,0 +1,48 @@ +// Filename: parameterRemapBasicStringPtrToString.h +// Created by: drose (11Aug09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef PARAMETERREMAPBASICSTRINGPTRTOSTRING_H +#define PARAMETERREMAPBASICSTRINGPTRTOSTRING_H + +#include "dtoolbase.h" + +#include "parameterRemapToString.h" + +//////////////////////////////////////////////////////////////////// +// Class : ParameterRemapBasicStringPtrToString +// Description : Maps a const pointer to a basic_string to an +// atomic string. +//////////////////////////////////////////////////////////////////// +class ParameterRemapBasicStringPtrToString : public ParameterRemapToString { +public: + ParameterRemapBasicStringPtrToString(CPPType *orig_type); + + virtual void pass_parameter(ostream &out, const string &variable_name); + virtual string get_return_expr(const string &expression); +}; + +//////////////////////////////////////////////////////////////////// +// Class : ParameterRemapBasicWStringPtrToWString +// Description : Maps a const pointer to a basic_string to an +// atomic string. +//////////////////////////////////////////////////////////////////// +class ParameterRemapBasicWStringPtrToWString : public ParameterRemapToWString { +public: + ParameterRemapBasicWStringPtrToWString(CPPType *orig_type); + + virtual void pass_parameter(ostream &out, const string &variable_name); + virtual string get_return_expr(const string &expression); +}; + +#endif diff --git a/dtool/src/interrogate/typeManager.cxx b/dtool/src/interrogate/typeManager.cxx index 04de4cac66..7b414dfe78 100644 --- a/dtool/src/interrogate/typeManager.cxx +++ b/dtool/src/interrogate/typeManager.cxx @@ -529,6 +529,23 @@ is_const_ref_to_basic_string_char(CPPType *type) { } } +//////////////////////////////////////////////////////////////////// +// Function: TypeManager::is_const_ptr_to_basic_string_char +// Access: Public, Static +// Description: Returns true if the indicated type is a const +// pointer to basic_string. +//////////////////////////////////////////////////////////////////// +bool TypeManager:: +is_const_ptr_to_basic_string_char(CPPType *type) { + switch (type->get_subtype()) { + case CPPDeclaration::ST_pointer: + return is_const_basic_string_char(type->as_pointer_type()->_pointing_at); + + default: + return false; + } +} + //////////////////////////////////////////////////////////////////// // Function: TypeManager::is_string // Access: Public, Static @@ -607,6 +624,23 @@ is_const_ref_to_basic_string_wchar(CPPType *type) { } } +//////////////////////////////////////////////////////////////////// +// Function: TypeManager::is_const_ptr_to_basic_string_wchar +// Access: Public, Static +// Description: Returns true if the indicated type is a const +// pointer to basic_string. +//////////////////////////////////////////////////////////////////// +bool TypeManager:: +is_const_ptr_to_basic_string_wchar(CPPType *type) { + switch (type->get_subtype()) { + case CPPDeclaration::ST_pointer: + return is_const_basic_string_wchar(type->as_pointer_type()->_pointing_at); + + default: + return false; + } +} + //////////////////////////////////////////////////////////////////// // Function: TypeManager::is_wstring // Access: Public, Static diff --git a/dtool/src/interrogate/typeManager.h b/dtool/src/interrogate/typeManager.h index 9ec4c3f174..1c20782673 100644 --- a/dtool/src/interrogate/typeManager.h +++ b/dtool/src/interrogate/typeManager.h @@ -67,10 +67,12 @@ public: static bool is_basic_string_char(CPPType *type); static bool is_const_basic_string_char(CPPType *type); static bool is_const_ref_to_basic_string_char(CPPType *type); + static bool is_const_ptr_to_basic_string_char(CPPType *type); static bool is_string(CPPType *type); static bool is_basic_string_wchar(CPPType *type); static bool is_const_basic_string_wchar(CPPType *type); static bool is_const_ref_to_basic_string_wchar(CPPType *type); + static bool is_const_ptr_to_basic_string_wchar(CPPType *type); static bool is_wstring(CPPType *type); static bool is_bool(CPPType *type); static bool is_integer(CPPType *type);