OpenSceneGraph/include/osg/Observer

65 lines
2.0 KiB
Plaintext
Raw Normal View History

/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_OBSERVER
#define OSG_OBSERVER 1
#include <OpenThreads/Mutex>
#include <osg/Export>
#include <set>
namespace osg {
/** Observer base class for tracking when objects are unreferenced (there reference count goes to 0) and are being deleted.*/
class OSG_EXPORT Observer
{
public:
Observer();
virtual ~Observer();
/** 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. */
virtual void objectDeleted(void*) {}
};
/** Class used by osg::Referenced to track the observers assoicated with it.*/
class OSG_EXPORT ObserverSet
{
public:
ObserverSet();
~ObserverSet();
inline OpenThreads::Mutex* getObserverSetMutex() const { return &_mutex; }
void addObserver(Observer* observer);
void removeObserver(Observer* observer);
void signalObjectDeleted(void* ptr);
typedef std::set<Observer*> Observers;
Observers& getObservers() { return _observers; }
const Observers& getObservers() const { return _observers; }
protected:
mutable OpenThreads::Mutex _mutex;
Observers _observers;
};
}
2010-02-19 06:53:15 +08:00
#endif