00001 //----------------------------------------------------------------------------------- 00002 // 00003 // Pro-Vocation Light Engine (PVLE) 00004 // Copyright (C) 2007-2009 Sukender, KinoX & Buzib 00005 // For more information, contact us : sukender@free.fr 00006 // 00007 // This program is free software; you can redistribute it and/or modify 00008 // it under the terms of the GNU General Public License as published by 00009 // the Free Software Foundation; either version 3 of the License, or 00010 // (at your option) any later version. 00011 // 00012 // For any use that is not compatible with the terms of the GNU 00013 // General Public License, please contact the authors for alternative 00014 // licensing options. 00015 // 00016 // This program is distributed in the hope that it will be useful, 00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 // GNU General Public License for more details. 00020 // 00021 // You should have received a copy of the GNU General Public License along 00022 // with this program; if not, write to the Free Software Foundation, Inc., 00023 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00024 // 00025 //----------------------------------------------------------------------------------- 00026 00027 00028 #ifndef UTIL_CALLBACK_H 00029 #define UTIL_CALLBACK_H 00030 00031 00032 //#include <PVLE/Export.h> 00033 //#include <osg/Referenced> 00034 #include <osg/ref_ptr> 00035 #include <osg/Referenced> 00036 //#include <osg/Object> 00037 00038 00039 namespace Util { 00040 00045 template <class T> 00046 class /*PVLE_EXPORT*/ Callback : public osg::Referenced { 00047 public: 00048 Callback() {} 00049 00050 inline void setNestedCallback(T * nc) { _nestedCallback = nc; } 00051 inline T * getNestedCallback() { return _nestedCallback.get(); } 00052 inline const T * getNestedCallback() const { return _nestedCallback.get(); } 00053 00054 inline void addNestedCallback(T * nc) { 00055 if (nc) { 00056 if (_nestedCallback.valid()) nc->addNestedCallback(_nestedCallback.get()); 00057 _nestedCallback = nc; 00058 } 00059 } 00060 00061 inline void removeNestedCallback(T * nc) { 00062 if (nc) { 00063 if (_nestedCallback==nc) 00064 _nestedCallback = _nestedCallback->getNestedCallback(); 00065 else if (_nestedCallback.valid()) 00066 _nestedCallback->removeNestedCallback(nc); 00067 } 00068 } 00069 00070 //osg::ref_ptr<Callback> _nestedCallback; 00071 osg::ref_ptr<T> _nestedCallback; 00072 00073 protected: 00076 virtual ~Callback() {} 00077 }; 00078 00079 00080 } //namespace Util 00081 00082 #endif // UTIL_CALLBACK_H