mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-27 15:25:54 -04:00
interrogate: fix ability to return ReferenceCount-like classes
Classes with virtual ref(), unref() and get_ref_count() methods, like RecorderBase, could not be returned by PT() from methods because they didn't inherit from ReferenceCount. However, classes do not need to inherit ReferenceCount to be able to be tracked by a PointerTo, and defining an abstract base class with pure virtual ref()/unref()/get_ref_count() is a way to avoid dual inheritance of ReferenceCount.
This commit is contained in:
parent
391578ea1f
commit
4ef8e5228e
@ -1442,7 +1442,7 @@ is_void(CPPType *type) {
|
||||
|
||||
/**
|
||||
* Returns true if the indicated type is some class that derives from
|
||||
* ReferenceCount, or false otherwise.
|
||||
* ReferenceCount, or defines ref and unref(), or false otherwise.
|
||||
*/
|
||||
bool TypeManager::
|
||||
is_reference_count(CPPType *type) {
|
||||
@ -1459,6 +1459,14 @@ is_reference_count(CPPType *type) {
|
||||
case CPPDeclaration::ST_struct:
|
||||
{
|
||||
CPPStructType *stype = type->as_struct_type();
|
||||
|
||||
// If we have methods named ref() and unref(), this is good enough.
|
||||
if (stype->_scope->_functions.count("ref") &&
|
||||
stype->_scope->_functions.count("unref") &&
|
||||
stype->_scope->_functions.count("get_ref_count")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
CPPStructType::Derivation::const_iterator di;
|
||||
for (di = stype->_derivation.begin();
|
||||
di != stype->_derivation.end();
|
||||
|
Loading…
x
Reference in New Issue
Block a user