cppbind: make ghost_type static to keep same pointer on reset.

Using a static naGhostType ensures that always the same
address is used for the same ghost and prevents ghost_types
from getting invalid (eg. on reset).
This commit is contained in:
Thomas Geymayer
2013-12-01 01:18:13 +01:00
parent 6fe1433497
commit dfb07f359e

View File

@@ -67,9 +67,6 @@ namespace nasal
bool isBaseOf(naGhostType* ghost_type) const
{
if( ghost_type == &_ghost_type )
return true;
for( DerivedList::const_iterator derived = _derived_classes.begin();
derived != _derived_classes.end();
++derived )
@@ -86,7 +83,6 @@ namespace nasal
typedef std::vector<const GhostMetadata*> DerivedList;
const std::string _name;
naGhostType _ghost_type;
DerivedList _derived_classes;
std::vector<naRef> _parents;
@@ -105,7 +101,7 @@ namespace nasal
(
SG_NASAL,
SG_INFO,
"Ghost::addDerived: " <<_ghost_type.name << " -> " << derived->_name
"Ghost::addDerived: " << _name << " -> " << derived->_name
);
}
@@ -549,6 +545,8 @@ namespace nasal
{
if( !ghost_type )
return false;
if( ghost_type == &_ghost_type )
return true;
return getSingletonPtr()->GhostMetadata::isBaseOf(ghost_type);
}
@@ -599,6 +597,8 @@ namespace nasal
template<class>
friend class Ghost;
static naGhostType _ghost_type;
typedef naGhostType* (*type_checker_t)(const raw_type*);
typedef std::vector<type_checker_t> DerivedList;
DerivedList _derived_types;
@@ -671,7 +671,7 @@ namespace nasal
// If base is not an instance of any derived class, this class has to
// be the dynamic type.
return &getSingletonPtr()->_ghost_type;
return &_ghost_type;
}
template<class BaseGhost>
@@ -684,7 +684,7 @@ namespace nasal
{
// For non polymorphic classes there is no possibility to get the actual
// dynamic type, therefore we can only use its static type.
return &BaseGhost::getSingletonPtr()->_ghost_type;
return &BaseGhost::_ghost_type;
}
static Ghost* getSingletonPtr()
@@ -703,7 +703,7 @@ namespace nasal
c,
"method called on object of wrong type: is '%s' expected '%s'",
ghost_type ? ghost_type->name : "unknown",
getSingletonPtr()->_ghost_type.name
_ghost_type.name
);
return *obj;
@@ -894,6 +894,9 @@ namespace nasal
}
};
template<class T>
naGhostType Ghost<T>::_ghost_type;
} // namespace nasal
// Needs to be outside any namespace to make ADL work