From 61121daaab7d55e7a9f1ed8b0c5b7b08ebc9bb5c Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 17 May 2010 18:37:32 +0000 Subject: [PATCH] Updated wrappers --- include/osg/Observer | 3 + include/osg/observer_ptr | 44 +++++------ src/osgWrappers/introspection/genwrapper.conf | 5 +- .../introspection/osg/Observer.cpp | 77 ------------------- .../introspection/osg/ObserverNodePath.cpp | 18 +---- .../introspection/osg/Referenced.cpp | 16 ++-- src/osgWrappers/introspection/osg/State.cpp | 1 - .../introspection/osg/observer_ptr.cpp | 39 ---------- .../introspection/osgDB/DatabasePager.cpp | 24 +++--- .../osgTerrain/TerrainTechnique.cpp | 1 - .../introspection/osgWidget/Widget.cpp | 24 +++--- .../introspection/osgWidget/Window.cpp | 24 +++--- 12 files changed, 72 insertions(+), 204 deletions(-) delete mode 100644 src/osgWrappers/introspection/osg/observer_ptr.cpp diff --git a/include/osg/Observer b/include/osg/Observer index f0d60189e..07f98cbdb 100644 --- a/include/osg/Observer +++ b/include/osg/Observer @@ -55,6 +55,9 @@ class OSG_EXPORT ObserverSet protected: + ObserverSet(const ObserverSet& rhs) {} + ObserverSet& operator = (const ObserverSet& rhs) { return *this; } + mutable OpenThreads::Mutex _mutex; Observers _observers; }; diff --git a/include/osg/observer_ptr b/include/osg/observer_ptr index 498b3e5c0..3d72a8629 100644 --- a/include/osg/observer_ptr +++ b/include/osg/observer_ptr @@ -30,7 +30,27 @@ struct WeakReference : public Observer, public Referenced { WeakReference(const T* ptr) : _ptr(const_cast(ptr)) {} - void objectDeleted(void*); + virtual void objectDeleted(void*) + { + bool deleteNeeded = false; + { + OpenThreads::ScopedLock lock(_mutex); + if (!_ptr) + { + // The last weak reference was deleted after the last + // reference, but the observer hasn't run yet. The + // observer can't be prevented from running, so it + // must delete itself. + deleteNeeded = true; + } + else + { + _ptr = 0; + } + } + if (deleteNeeded) delete this; + } + /** * "Lock" a Referenced object i.e., protect it from being deleted * by incrementing its reference count. @@ -71,6 +91,7 @@ struct UnsafeWeakReference : public WeakReference return 0; } }; + /** Delete the WeakReference object, if necessary. The WeakReference should be deleted when the last observer_ptr pointing to it goes @@ -259,27 +280,6 @@ protected: WeakReference* _reference; }; -template -void WeakReference::objectDeleted(void*) -{ - bool deleteNeeded = false; - { - OpenThreads::ScopedLock lock(_mutex); - if (!_ptr) - { - // The last weak reference was deleted after the last - // reference, but the observer hasn't run yet. The - // observer can't be prevented from running, so it - // must delete itself. - deleteNeeded = true; - } - else - { - _ptr = 0; - } - } - if (deleteNeeded) delete this; -} template WeakReference* diff --git a/src/osgWrappers/introspection/genwrapper.conf b/src/osgWrappers/introspection/genwrapper.conf index 91beb7304..c74f36bce 100644 --- a/src/osgWrappers/introspection/genwrapper.conf +++ b/src/osgWrappers/introspection/genwrapper.conf @@ -320,6 +320,9 @@ suppress reflector "osgTerrain::TerrainNeighbours" suppress reflector "osgDB::Registry::getObjectWrapperManager" +suppress reflector "osg::Observer" +suppress reflector "osg::ObserverSet" + configure reflector "osgDB::Registry" configure property "ObjectWrapperManager" replace with "" @@ -435,7 +438,7 @@ configure reflector "osg::DeleteHandler" end configure reflector "osg::GraphicsContext" - abstract-object-type + abstract-object-type end ############################################################################# diff --git a/src/osgWrappers/introspection/osg/Observer.cpp b/src/osgWrappers/introspection/osg/Observer.cpp index f39648230..839304272 100644 --- a/src/osgWrappers/introspection/osg/Observer.cpp +++ b/src/osgWrappers/introspection/osg/Observer.cpp @@ -21,84 +21,7 @@ #undef OUT #endif -BEGIN_VALUE_REFLECTOR(osg::Observer) - I_DeclaringFile("osg/Observer"); - I_Constructor0(____Observer, - "", - ""); - I_Method0(OpenThreads::Mutex *, getObserverMutex, - Properties::NON_VIRTUAL, - __OpenThreads_Mutex_P1__getObserverMutex, - "", - ""); - I_Method1(bool, objectUnreferenced, IN, void *, x, - Properties::VIRTUAL, - __bool__objectUnreferenced__void_P1, - "objectUnreferenced(void*) is called when the observed object's referenced count goes to zero, indicating that the object will be deleted unless a new reference is made to it. ", - "If you wish to prevent deletion of the object then it's reference count should be incremented such as via taking a ref_ptr<> to it, if no refernce is taken by any of the observers of the object then the object will be deleted, and objectDeleted will in turn be called. return true if the Observer wishes to removed from the oberseved objects observer set. "); - I_Method1(void, objectDeleted, IN, void *, x, - Properties::VIRTUAL, - __void__objectDeleted__void_P1, - "objectDeleted is called when the observed object is about to be deleted. ", - "The observer will be automatically removed from the observerd objects observer set so there is no need for the objectDeleted implementation to call removeObserver() on the observed object. "); - I_StaticMethod0(OpenThreads::Mutex *, getGlobalObserverMutex, - __OpenThreads_Mutex_P1__getGlobalObserverMutex_S, - "Get the optional global observer mutex, this can be shared between all osg::Observer. ", - ""); - I_SimpleProperty(OpenThreads::Mutex *, ObserverMutex, - __OpenThreads_Mutex_P1__getObserverMutex, - 0); -END_REFLECTOR - TYPE_NAME_ALIAS(std::set< osg::Observer * >, osg::ObserverSet::Observers) -BEGIN_VALUE_REFLECTOR(osg::ObserverSet) - I_DeclaringFile("osg/Observer"); - I_Constructor0(____ObserverSet, - "", - ""); - I_Method0(OpenThreads::Mutex *, getObserverSetMutex, - Properties::NON_VIRTUAL, - __OpenThreads_Mutex_P1__getObserverSetMutex, - "", - ""); - I_Method1(void, addObserver, IN, osg::Observer *, observer, - Properties::NON_VIRTUAL, - __void__addObserver__Observer_P1, - "", - ""); - I_Method1(void, removeObserver, IN, osg::Observer *, observer, - Properties::NON_VIRTUAL, - __void__removeObserver__Observer_P1, - "", - ""); - I_Method1(void, signalObjectUnreferenced, IN, void *, ptr, - Properties::NON_VIRTUAL, - __void__signalObjectUnreferenced__void_P1, - "", - ""); - I_Method1(void, signalObjectDeleted, IN, void *, ptr, - Properties::NON_VIRTUAL, - __void__signalObjectDeleted__void_P1, - "", - ""); - I_Method0(osg::ObserverSet::Observers &, getObservers, - Properties::NON_VIRTUAL, - __Observers_R1__getObservers, - "", - ""); - I_Method0(const osg::ObserverSet::Observers &, getObservers, - Properties::NON_VIRTUAL, - __C5_Observers_R1__getObservers, - "", - ""); - I_SimpleProperty(OpenThreads::Mutex *, ObserverSetMutex, - __OpenThreads_Mutex_P1__getObserverSetMutex, - 0); - I_SimpleProperty(osg::ObserverSet::Observers &, Observers, - __Observers_R1__getObservers, - 0); -END_REFLECTOR - STD_SET_REFLECTOR(std::set< osg::Observer * >) diff --git a/src/osgWrappers/introspection/osg/ObserverNodePath.cpp b/src/osgWrappers/introspection/osg/ObserverNodePath.cpp index a042c8faf..05fd2aa94 100644 --- a/src/osgWrappers/introspection/osg/ObserverNodePath.cpp +++ b/src/osgWrappers/introspection/osg/ObserverNodePath.cpp @@ -21,9 +21,8 @@ #undef OUT #endif -BEGIN_OBJECT_REFLECTOR(osg::ObserverNodePath) +BEGIN_VALUE_REFLECTOR(osg::ObserverNodePath) I_DeclaringFile("osg/ObserverNodePath"); - I_BaseType(osg::Observer); I_Constructor0(____ObserverNodePath, "", ""); @@ -37,11 +36,6 @@ BEGIN_OBJECT_REFLECTOR(osg::ObserverNodePath) ____ObserverNodePath__C5_osg_NodePath_R1, "", ""); - I_Method0(bool, valid, - Properties::NON_VIRTUAL, - __bool__valid, - "", - ""); I_Method1(void, setNodePathTo, IN, osg::Node *, node, Properties::NON_VIRTUAL, __void__setNodePathTo__osg_Node_P1, @@ -89,12 +83,6 @@ BEGIN_OBJECT_REFLECTOR(osg::ObserverNodePath) __void___clearNodePath, "", ""); - I_ProtectedMethod1(bool, objectUnreferenced, IN, void *, x, - Properties::VIRTUAL, - Properties::NON_CONST, - __bool__objectUnreferenced__void_P1, - "objectUnreferenced(void*) is called when the observed object's referenced count goes to zero, indicating that the object will be deleted unless a new reference is made to it. ", - "If you wish to prevent deletion of the object then it's reference count should be incremented such as via taking a ref_ptr<> to it, if no refernce is taken by any of the observers of the object then the object will be deleted, and objectDeleted will in turn be called. return true if the Observer wishes to removed from the oberseved objects observer set. "); I_SimpleProperty(const osg::RefNodePath &, NodePath, 0, __void__setNodePath__C5_osg_RefNodePath_R1); @@ -103,7 +91,5 @@ BEGIN_OBJECT_REFLECTOR(osg::ObserverNodePath) __void__setNodePathTo__osg_Node_P1); END_REFLECTOR -TYPE_NAME_ALIAS(std::list< osg::ref_ptr< osg::Node > >, osg::RefNodePath) - -STD_LIST_REFLECTOR(std::list< osg::ref_ptr< osg::Node > >) +TYPE_NAME_ALIAS(std::vector< osg::ref_ptr< osg::Node > >, osg::RefNodePath) diff --git a/src/osgWrappers/introspection/osg/Referenced.cpp b/src/osgWrappers/introspection/osg/Referenced.cpp index 5f0db9775..bd95e6e39 100644 --- a/src/osgWrappers/introspection/osg/Referenced.cpp +++ b/src/osgWrappers/introspection/osg/Referenced.cpp @@ -53,19 +53,19 @@ BEGIN_OBJECT_REFLECTOR(osg::Referenced) __OpenThreads_Mutex_P1__getRefMutex, "Get the mutex used to ensure thread safety of ref()/unref(). ", ""); - I_Method0(void, ref, + I_Method0(int, ref, Properties::NON_VIRTUAL, - __void__ref, + __int__ref, "Increment the reference count by one, indicating that this object has another pointer which is referencing it. ", ""); - I_Method0(void, unref, + I_Method0(int, unref, Properties::NON_VIRTUAL, - __void__unref, + __int__unref, "Decrement the reference count by one, indicating that a pointer to this object is referencing it. ", "If the reference count goes to zero, it is assumed that this object is no longer referenced and is automatically deleted. "); - I_Method0(void, unref_nodelete, + I_Method0(int, unref_nodelete, Properties::NON_VIRTUAL, - __void__unref_nodelete, + __int__unref_nodelete, "Decrement the reference count by one, indicating that a pointer to this object is referencing it. ", "However, do not delete it, even if ref count goes to 0. Warning, unref_nodelete() should only be called if the user knows exactly who will be responsible for, one should prefer unref() over unref_nodelete() as the later can lead to memory leaks. "); I_Method0(int, referenceCount, @@ -113,10 +113,10 @@ BEGIN_OBJECT_REFLECTOR(osg::Referenced) __DeleteHandler_P1__getDeleteHandler_S, "Get a DeleteHandler. ", ""); - I_ProtectedMethod3(void, signalObserversAndDelete, IN, bool, signalUnreferened, IN, bool, signalDelete, IN, bool, doDelete, + I_ProtectedMethod2(void, signalObserversAndDelete, IN, bool, signalDelete, IN, bool, doDelete, Properties::NON_VIRTUAL, Properties::CONST, - __void__signalObserversAndDelete__bool__bool__bool, + __void__signalObserversAndDelete__bool__bool, "", ""); I_ProtectedMethod0(void, deleteUsingDeleteHandler, diff --git a/src/osgWrappers/introspection/osg/State.cpp b/src/osgWrappers/introspection/osg/State.cpp index cb7387e08..c48944eff 100644 --- a/src/osgWrappers/introspection/osg/State.cpp +++ b/src/osgWrappers/introspection/osg/State.cpp @@ -54,7 +54,6 @@ TYPE_NAME_ALIAS(std::vector< osg::State::AttributePair >, osg::State::AttributeV BEGIN_OBJECT_REFLECTOR(osg::State) I_DeclaringFile("osg/State"); I_BaseType(osg::Referenced); - I_BaseType(osg::Observer); I_Constructor0(____State, "", ""); diff --git a/src/osgWrappers/introspection/osg/observer_ptr.cpp b/src/osgWrappers/introspection/osg/observer_ptr.cpp deleted file mode 100644 index 47c2e4cab..000000000 --- a/src/osgWrappers/introspection/osg/observer_ptr.cpp +++ /dev/null @@ -1,39 +0,0 @@ -// *************************************************************************** -// -// Generated automatically by genwrapper. -// Please DO NOT EDIT this file! -// -// *************************************************************************** - -#include -#include -#include -#include - -#include - -// Must undefine IN and OUT macros defined in Windows headers -#ifdef IN -#undef IN -#endif -#ifdef OUT -#undef OUT -#endif - -BEGIN_VALUE_REFLECTOR(osg::Observer) - I_DeclaringFile("osg/observer_ptr"); - I_Constructor0(____Observer, - "", - ""); - I_Method1(bool, objectUnreferenced, IN, void *, x, - Properties::VIRTUAL, - __bool__objectUnreferenced__void_P1, - "objectUnreferenced(void*) is called when the observed object's referenced count goes to zero, indicating that the object will be deleted unless a new reference is made to it. ", - "If you wish to prevent deletion of the object then it's reference count should be incremented such as via taking a ref_ptr<> to it, if no refernce is taken by any of the observers of the object then the object will be deleted, and objectDeleted will in turn be called. return true if the Observer wishes to removed from the oberseved objects observer set. "); - I_Method1(void, objectDeleted, IN, void *, x, - Properties::VIRTUAL, - __void__objectDeleted__void_P1, - "objectDeleted is called when the observed object is about to be deleted. ", - "The observer will be automatically removed from the observerd objects observer set so there is no need for the objectDeleted implementation to call removeObserver() on the observed object. "); -END_REFLECTOR - diff --git a/src/osgWrappers/introspection/osgDB/DatabasePager.cpp b/src/osgWrappers/introspection/osgDB/DatabasePager.cpp index 2a9cd492f..07eb2b2b7 100644 --- a/src/osgWrappers/introspection/osgDB/DatabasePager.cpp +++ b/src/osgWrappers/introspection/osgDB/DatabasePager.cpp @@ -543,16 +543,20 @@ END_REFLECTOR BEGIN_OBJECT_REFLECTOR(osg::observer_ptr< osg::GraphicsContext >) I_DeclaringFile("osg/observer_ptr"); - I_BaseType(osg::Observer); I_Constructor0(____observer_ptr, "", ""); - I_Constructor1(IN, osg::GraphicsContext *, t, + I_Constructor1(IN, osg::ref_ptr< osg::GraphicsContext > &, rp, + Properties::NON_EXPLICIT, + ____observer_ptr__ref_ptrT1_T__R1, + "Create a observer_ptr from a ref_ptr. ", + ""); + I_Constructor1(IN, osg::GraphicsContext *, rp, Properties::NON_EXPLICIT, ____observer_ptr__T_P1, - "", - ""); - I_Constructor1(IN, const osg::observer_ptr< osg::GraphicsContext > &, rp, + "Create a observer_ptr from a raw pointer. ", + "For compatibility; the result might not be lockable. "); + I_Constructor1(IN, const osg::observer_ptr< osg::GraphicsContext > &, wp, Properties::NON_EXPLICIT, ____observer_ptr__C5_observer_ptr_R1, "", @@ -560,8 +564,8 @@ BEGIN_OBJECT_REFLECTOR(osg::observer_ptr< osg::GraphicsContext >) I_Method0(osg::ref_ptr< osg::GraphicsContext >, lock, Properties::NON_VIRTUAL, __ref_ptrT1_T___lock, - "", - ""); + "Create a ref_ptr from a observer_ptr. ", + "The ref_ptr will be valid if the referenced object hasn't been deleted and has a ref count > 0. "); I_Method0(osg::GraphicsContext *, get, Properties::NON_VIRTUAL, __T_P1__get, @@ -572,12 +576,6 @@ BEGIN_OBJECT_REFLECTOR(osg::observer_ptr< osg::GraphicsContext >) __bool__valid, "", ""); - I_ProtectedMethod1(void, objectDeleted, IN, void *, x, - Properties::VIRTUAL, - Properties::NON_CONST, - __void__objectDeleted__void_P1, - "objectDeleted is called when the observed object is about to be deleted. ", - "The observer will be automatically removed from the observerd objects observer set so there is no need for the objectDeleted implementation to call removeObserver() on the observed object. "); I_SimpleProperty(osg::GraphicsContext *, , __T_P1__get, 0); diff --git a/src/osgWrappers/introspection/osgTerrain/TerrainTechnique.cpp b/src/osgWrappers/introspection/osgTerrain/TerrainTechnique.cpp index 1ac48f706..5f9efbb24 100644 --- a/src/osgWrappers/introspection/osgTerrain/TerrainTechnique.cpp +++ b/src/osgWrappers/introspection/osgTerrain/TerrainTechnique.cpp @@ -30,7 +30,6 @@ BEGIN_OBJECT_REFLECTOR(osgTerrain::TerrainTechnique) I_DeclaringFile("osgTerrain/TerrainTechnique"); I_BaseType(osg::Object); - I_BaseType(osg::Observer); I_Constructor0(____TerrainTechnique, "", ""); diff --git a/src/osgWrappers/introspection/osgWidget/Widget.cpp b/src/osgWrappers/introspection/osgWidget/Widget.cpp index 6722cca21..3de377323 100644 --- a/src/osgWrappers/introspection/osgWidget/Widget.cpp +++ b/src/osgWrappers/introspection/osgWidget/Widget.cpp @@ -951,16 +951,20 @@ TYPE_NAME_ALIAS(std::list< osg::observer_ptr< osgWidget::Widget > >, osgWidget:: BEGIN_OBJECT_REFLECTOR(osg::observer_ptr< osgWidget::Widget >) I_DeclaringFile("osg/observer_ptr"); - I_BaseType(osg::Observer); I_Constructor0(____observer_ptr, "", ""); - I_Constructor1(IN, osgWidget::Widget *, t, + I_Constructor1(IN, osg::ref_ptr< osgWidget::Widget > &, rp, + Properties::NON_EXPLICIT, + ____observer_ptr__ref_ptrT1_T__R1, + "Create a observer_ptr from a ref_ptr. ", + ""); + I_Constructor1(IN, osgWidget::Widget *, rp, Properties::NON_EXPLICIT, ____observer_ptr__T_P1, - "", - ""); - I_Constructor1(IN, const osg::observer_ptr< osgWidget::Widget > &, rp, + "Create a observer_ptr from a raw pointer. ", + "For compatibility; the result might not be lockable. "); + I_Constructor1(IN, const osg::observer_ptr< osgWidget::Widget > &, wp, Properties::NON_EXPLICIT, ____observer_ptr__C5_observer_ptr_R1, "", @@ -968,8 +972,8 @@ BEGIN_OBJECT_REFLECTOR(osg::observer_ptr< osgWidget::Widget >) I_Method0(osg::ref_ptr< osgWidget::Widget >, lock, Properties::NON_VIRTUAL, __ref_ptrT1_T___lock, - "", - ""); + "Create a ref_ptr from a observer_ptr. ", + "The ref_ptr will be valid if the referenced object hasn't been deleted and has a ref count > 0. "); I_Method0(osgWidget::Widget *, get, Properties::NON_VIRTUAL, __T_P1__get, @@ -980,12 +984,6 @@ BEGIN_OBJECT_REFLECTOR(osg::observer_ptr< osgWidget::Widget >) __bool__valid, "", ""); - I_ProtectedMethod1(void, objectDeleted, IN, void *, x, - Properties::VIRTUAL, - Properties::NON_CONST, - __void__objectDeleted__void_P1, - "objectDeleted is called when the observed object is about to be deleted. ", - "The observer will be automatically removed from the observerd objects observer set so there is no need for the objectDeleted implementation to call removeObserver() on the observed object. "); I_SimpleProperty(osgWidget::Widget *, , __T_P1__get, 0); diff --git a/src/osgWrappers/introspection/osgWidget/Window.cpp b/src/osgWrappers/introspection/osgWidget/Window.cpp index 9bc476b47..b0d3fb667 100644 --- a/src/osgWrappers/introspection/osgWidget/Window.cpp +++ b/src/osgWrappers/introspection/osgWidget/Window.cpp @@ -953,16 +953,20 @@ TYPE_NAME_ALIAS(osgWidget::Window::WindowList, osgWidget::WindowList) BEGIN_OBJECT_REFLECTOR(osg::observer_ptr< osgWidget::Window >) I_DeclaringFile("osg/observer_ptr"); - I_BaseType(osg::Observer); I_Constructor0(____observer_ptr, "", ""); - I_Constructor1(IN, osgWidget::Window *, t, + I_Constructor1(IN, osg::ref_ptr< osgWidget::Window > &, rp, + Properties::NON_EXPLICIT, + ____observer_ptr__ref_ptrT1_T__R1, + "Create a observer_ptr from a ref_ptr. ", + ""); + I_Constructor1(IN, osgWidget::Window *, rp, Properties::NON_EXPLICIT, ____observer_ptr__T_P1, - "", - ""); - I_Constructor1(IN, const osg::observer_ptr< osgWidget::Window > &, rp, + "Create a observer_ptr from a raw pointer. ", + "For compatibility; the result might not be lockable. "); + I_Constructor1(IN, const osg::observer_ptr< osgWidget::Window > &, wp, Properties::NON_EXPLICIT, ____observer_ptr__C5_observer_ptr_R1, "", @@ -970,8 +974,8 @@ BEGIN_OBJECT_REFLECTOR(osg::observer_ptr< osgWidget::Window >) I_Method0(osg::ref_ptr< osgWidget::Window >, lock, Properties::NON_VIRTUAL, __ref_ptrT1_T___lock, - "", - ""); + "Create a ref_ptr from a observer_ptr. ", + "The ref_ptr will be valid if the referenced object hasn't been deleted and has a ref count > 0. "); I_Method0(osgWidget::Window *, get, Properties::NON_VIRTUAL, __T_P1__get, @@ -982,12 +986,6 @@ BEGIN_OBJECT_REFLECTOR(osg::observer_ptr< osgWidget::Window >) __bool__valid, "", ""); - I_ProtectedMethod1(void, objectDeleted, IN, void *, x, - Properties::VIRTUAL, - Properties::NON_CONST, - __void__objectDeleted__void_P1, - "objectDeleted is called when the observed object is about to be deleted. ", - "The observer will be automatically removed from the observerd objects observer set so there is no need for the objectDeleted implementation to call removeObserver() on the observed object. "); I_SimpleProperty(osgWidget::Window *, , __T_P1__get, 0);