cppbind: from_nasal/to_nasal for SGWeakReferenced based objects
This commit is contained in:
@@ -1067,7 +1067,11 @@ from_nasal_helper(naContext c, naRef ref, const T*)
|
||||
* Convert any pointer to a SGReference based object to a ghost.
|
||||
*/
|
||||
template<class T>
|
||||
typename boost::enable_if<boost::is_base_of<SGReferenced, T>, naRef>::type
|
||||
typename boost::enable_if_c<
|
||||
boost::is_base_of<SGReferenced, T>::value
|
||||
|| boost::is_base_of<SGWeakReferenced, T>::value,
|
||||
naRef
|
||||
>::type
|
||||
to_nasal_helper(naContext c, T* ptr)
|
||||
{
|
||||
return nasal::Ghost<SGSharedPtr<T> >::create(c, SGSharedPtr<T>(ptr));
|
||||
@@ -1077,8 +1081,15 @@ to_nasal_helper(naContext c, T* ptr)
|
||||
* Convert nasal ghosts/hashes to pointer (of a SGReference based ghost).
|
||||
*/
|
||||
template<class T>
|
||||
typename boost::enable_if<
|
||||
boost::is_base_of<SGReferenced, typename boost::remove_pointer<T>::type>,
|
||||
typename boost::enable_if_c<
|
||||
boost::is_base_of<
|
||||
SGReferenced,
|
||||
typename boost::remove_pointer<T>::type
|
||||
>::value
|
||||
|| boost::is_base_of<
|
||||
SGWeakReferenced,
|
||||
typename boost::remove_pointer<T>::type
|
||||
>::value,
|
||||
T
|
||||
>::type
|
||||
from_nasal_helper(naContext c, naRef ref, const T*)
|
||||
|
||||
@@ -82,10 +82,17 @@ class SGReferenceBasedClass:
|
||||
|
||||
};
|
||||
|
||||
class SGWeakReferenceBasedClass:
|
||||
public SGWeakReferenced
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
typedef boost::shared_ptr<Derived> DerivedPtr;
|
||||
typedef boost::shared_ptr<DoubleDerived> DoubleDerivedPtr;
|
||||
typedef boost::shared_ptr<DoubleDerived2> DoubleDerived2Ptr;
|
||||
typedef SGSharedPtr<SGReferenceBasedClass> SGRefBasedPtr;
|
||||
typedef SGSharedPtr<SGWeakReferenceBasedClass> SGWeakRefBasedPtr;
|
||||
|
||||
typedef boost::weak_ptr<Derived> DerivedWeakPtr;
|
||||
|
||||
@@ -228,6 +235,21 @@ int main(int argc, char* argv[])
|
||||
|
||||
Ghost<DerivedWeakPtr>::init("DerivedWeakPtr");
|
||||
Ghost<SGRefBasedPtr>::init("SGRefBasedPtr");
|
||||
Ghost<SGWeakRefBasedPtr>::init("SGWeakRefBasedPtr");
|
||||
|
||||
SGWeakRefBasedPtr weak_ptr(new SGWeakReferenceBasedClass());
|
||||
naRef nasal_ref = to_nasal(c, weak_ptr),
|
||||
nasal_ptr = to_nasal(c, weak_ptr.get());
|
||||
|
||||
VERIFY( naIsGhost(nasal_ref) );
|
||||
VERIFY( naIsGhost(nasal_ptr) );
|
||||
|
||||
SGWeakRefBasedPtr ptr1 = from_nasal<SGWeakRefBasedPtr>(c, nasal_ref),
|
||||
ptr2 = from_nasal<SGWeakRefBasedPtr>(c, nasal_ptr);
|
||||
|
||||
VERIFY( weak_ptr == ptr1 );
|
||||
VERIFY( weak_ptr == ptr2 );
|
||||
|
||||
|
||||
VERIFY( Ghost<BasePtr>::isInit() );
|
||||
nasal::to_nasal(c, DoubleDerived2Ptr());
|
||||
|
||||
Reference in New Issue
Block a user