mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
support tinyxml's (const string *) return types.
This commit is contained in:
parent
0c4b08731a
commit
383a6e512c
@ -18,7 +18,9 @@
|
|||||||
interfaceMakerPythonSimple.h \
|
interfaceMakerPythonSimple.h \
|
||||||
interfaceMakerPythonNative.h \
|
interfaceMakerPythonNative.h \
|
||||||
interrogate.h interrogateBuilder.h parameterRemap.I \
|
interrogate.h interrogateBuilder.h parameterRemap.I \
|
||||||
parameterRemap.h parameterRemapBasicStringRefToString.h \
|
parameterRemap.h \
|
||||||
|
parameterRemapBasicStringPtrToString.h \
|
||||||
|
parameterRemapBasicStringRefToString.h \
|
||||||
parameterRemapBasicStringToString.h \
|
parameterRemapBasicStringToString.h \
|
||||||
parameterRemapCharStarToString.h \
|
parameterRemapCharStarToString.h \
|
||||||
parameterRemapConcreteToPointer.h \
|
parameterRemapConcreteToPointer.h \
|
||||||
@ -40,6 +42,7 @@
|
|||||||
interfaceMakerPythonSimple.cxx \
|
interfaceMakerPythonSimple.cxx \
|
||||||
interfaceMakerPythonNative.cxx \
|
interfaceMakerPythonNative.cxx \
|
||||||
interrogate.cxx interrogateBuilder.cxx parameterRemap.cxx \
|
interrogate.cxx interrogateBuilder.cxx parameterRemap.cxx \
|
||||||
|
parameterRemapBasicStringPtrToString.cxx \
|
||||||
parameterRemapBasicStringRefToString.cxx \
|
parameterRemapBasicStringRefToString.cxx \
|
||||||
parameterRemapBasicStringToString.cxx \
|
parameterRemapBasicStringToString.cxx \
|
||||||
parameterRemapCharStarToString.cxx \
|
parameterRemapCharStarToString.cxx \
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include "parameterRemapCharStarToString.h"
|
#include "parameterRemapCharStarToString.h"
|
||||||
#include "parameterRemapBasicStringToString.h"
|
#include "parameterRemapBasicStringToString.h"
|
||||||
#include "parameterRemapBasicStringRefToString.h"
|
#include "parameterRemapBasicStringRefToString.h"
|
||||||
|
#include "parameterRemapBasicStringPtrToString.h"
|
||||||
#include "parameterRemapPTToPointer.h"
|
#include "parameterRemapPTToPointer.h"
|
||||||
|
|
||||||
#include "interrogateDatabase.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)) {
|
} else if (TypeManager::is_const_ref_to_basic_string_char(param_type)) {
|
||||||
return new ParameterRemapBasicStringRefToString(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)) {
|
} else if (TypeManager::is_basic_string_wchar(param_type)) {
|
||||||
return new ParameterRemapBasicWStringToWString(param_type);
|
return new ParameterRemapBasicWStringToWString(param_type);
|
||||||
|
|
||||||
} else if (TypeManager::is_const_ref_to_basic_string_wchar(param_type)) {
|
} else if (TypeManager::is_const_ref_to_basic_string_wchar(param_type)) {
|
||||||
return new ParameterRemapBasicWStringRefToWString(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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2383,6 +2383,29 @@ write_function_instance(ostream &out, InterfaceMaker::Object *obj,
|
|||||||
param_name + "_len)";
|
param_name + "_len)";
|
||||||
|
|
||||||
extra_cleanup += " delete[] " + param_name + "_str;";
|
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>((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<char>(" +
|
||||||
|
param_name + "_str, " +
|
||||||
|
param_name + "_len)";
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
indent(out,indent_level) << "char *" << param_name
|
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 PyUnicode_FromWideChar("
|
||||||
<< return_expr << ".data(), (int)" << return_expr << ".length());\n";
|
<< 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 {
|
} else {
|
||||||
indent(out, indent_level)
|
indent(out, indent_level)
|
||||||
<< "return PyString_FromStringAndSize("
|
<< "return PyString_FromStringAndSize("
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include "interrogate.cxx"
|
#include "interrogate.cxx"
|
||||||
#include "typeManager.cxx"
|
#include "typeManager.cxx"
|
||||||
#include "parameterRemap.cxx"
|
#include "parameterRemap.cxx"
|
||||||
|
#include "parameterRemapBasicStringPtrToString.cxx"
|
||||||
#include "parameterRemapBasicStringRefToString.cxx"
|
#include "parameterRemapBasicStringRefToString.cxx"
|
||||||
#include "parameterRemapBasicStringToString.cxx"
|
#include "parameterRemapBasicStringToString.cxx"
|
||||||
#include "parameterRemapCharStarToString.cxx"
|
#include "parameterRemapCharStarToString.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()";
|
||||||
|
}
|
48
dtool/src/interrogate/parameterRemapBasicStringPtrToString.h
Normal file
48
dtool/src/interrogate/parameterRemapBasicStringPtrToString.h
Normal file
@ -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<char> 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<wchar_t> 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
|
@ -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<char>.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
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
|
// Function: TypeManager::is_string
|
||||||
// Access: Public, Static
|
// 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<wchar_t>.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
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
|
// Function: TypeManager::is_wstring
|
||||||
// Access: Public, Static
|
// Access: Public, Static
|
||||||
|
@ -67,10 +67,12 @@ public:
|
|||||||
static bool is_basic_string_char(CPPType *type);
|
static bool is_basic_string_char(CPPType *type);
|
||||||
static bool is_const_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_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_string(CPPType *type);
|
||||||
static bool is_basic_string_wchar(CPPType *type);
|
static bool is_basic_string_wchar(CPPType *type);
|
||||||
static bool is_const_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_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_wstring(CPPType *type);
|
||||||
static bool is_bool(CPPType *type);
|
static bool is_bool(CPPType *type);
|
||||||
static bool is_integer(CPPType *type);
|
static bool is_integer(CPPType *type);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user