mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 01:44:06 -04:00
support explicit default constructors for linmath
This commit is contained in:
parent
180e3f5cd1
commit
4cd6d03cb5
@ -158,7 +158,12 @@ string FunctionRemap::call_function(ostream &out, int indent_level, bool convert
|
||||
|
||||
} else if (_type == T_constructor) {
|
||||
// A special case for constructors.
|
||||
string defconstruct = builder.in_defconstruct(_cpptype->get_local_name(&parser));
|
||||
if (pexprs.empty() && !defconstruct.empty()) {
|
||||
return_expr = defconstruct;
|
||||
} else {
|
||||
return_expr = "new " + get_call_str(container, pexprs);
|
||||
}
|
||||
if (_void_return) {
|
||||
nout << "Error, constructor for " << *_cpptype << " returning void.\n";
|
||||
return_expr = "";
|
||||
|
@ -182,6 +182,28 @@ do_command(const string &command, const string ¶ms) {
|
||||
_ignoretype.insert(type->get_local_name(&parser));
|
||||
}
|
||||
|
||||
} else if (command == "defconstruct") {
|
||||
// defining the parameters that are implicitly supplied to the
|
||||
// generated default constructor. Especially useful for linmath
|
||||
// objects, whose default constructor in C++ is uninitialized, but
|
||||
// whose Python-level constructor should initialize to 0.
|
||||
|
||||
size_t space = params.find(' ');
|
||||
if (space == string::npos) {
|
||||
nout << "No constructor specified for defconstruct " << params << "\n";
|
||||
} else {
|
||||
string class_name = params.substr(0, space);
|
||||
string constructor = params.substr(space + 1);
|
||||
|
||||
CPPType *type = parser.parse_type(class_name);
|
||||
if (type == (CPPType *)NULL) {
|
||||
nout << "Unknown type: defconstruct " << class_name << "\n";
|
||||
} else {
|
||||
type = type->resolve_type(&parser, &parser);
|
||||
_defconstruct[type->get_local_name(&parser)] = constructor;
|
||||
}
|
||||
}
|
||||
|
||||
} else if (command == "ignoreinvolved") {
|
||||
_ignoreinvolved.insert(params);
|
||||
|
||||
@ -783,6 +805,23 @@ in_ignoretype(const string &name) const {
|
||||
return (_ignoretype.count(name) != 0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: InterrogateBuilder::in_defconstruct
|
||||
// Access: Private
|
||||
// Description: If the user requested an explicit default constructor
|
||||
// for this type via the defconstruct command, returns
|
||||
// that string; otherwise, returns the empty string.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
string InterrogateBuilder::
|
||||
in_defconstruct(const string &name) const {
|
||||
CommandParams::const_iterator pi;
|
||||
pi = _defconstruct.find(name);
|
||||
if (pi != _defconstruct.end()) {
|
||||
return (*pi).second;
|
||||
}
|
||||
return string();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: InterrogateBuilder::in_ignoreinvolved
|
||||
// Access: Private
|
||||
|
@ -80,6 +80,7 @@ public:
|
||||
bool in_forcetype(const string &name) const;
|
||||
string in_renametype(const string &name) const;
|
||||
bool in_ignoretype(const string &name) const;
|
||||
string in_defconstruct(const string &name) const;
|
||||
bool in_ignoreinvolved(const string &name) const;
|
||||
bool in_ignoreinvolved(CPPType *type) const;
|
||||
bool in_ignorefile(const string &name) const;
|
||||
@ -141,6 +142,7 @@ public:
|
||||
Commands _forcetype;
|
||||
CommandParams _renametype;
|
||||
Commands _ignoretype;
|
||||
CommandParams _defconstruct;
|
||||
Commands _ignoreinvolved;
|
||||
Commands _ignorefile;
|
||||
Commands _ignoremember;
|
||||
|
Loading…
x
Reference in New Issue
Block a user