diff --git a/include/osg/Callback b/include/osg/Callback index 35480a39c..02a517168 100644 --- a/include/osg/Callback +++ b/include/osg/Callback @@ -121,6 +121,32 @@ class OSG_EXPORT Callback : public virtual Object { } } + /** Convenience method to find a nested callback by type. */ + template + static T* findNestedCallback(osg::Callback* callback) + { + if (!callback) + return NULL; + + if (T* cb = dynamic_cast(callback)) + return cb; + + return findNestedCallback(callback->getNestedCallback()); + } + + /** Convenience method to find a nested callback by type. */ + template + static const T* findNestedCallback(const osg::Callback* callback) + { + if (!callback) + return NULL; + + if (const T* cb = dynamic_cast(callback)) + return cb; + + return findNestedCallback(callback->getNestedCallback()); + } + protected: virtual ~Callback() {}