Starting from 2021-07-01, all LRZ GitLab users will be required to explicitly accept the GitLab Terms of Service. Please see the detailed information at https://doku.lrz.de/display/PUBLIC/GitLab and make sure that your projects conform to the requirements.

Commit dce3bfd5 authored by schultezub's avatar schultezub
Browse files

* added Observer

 * added AbstractProperty stub

git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@172 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent 0dfc7a2d
#include "abstractproperty.h"
namespace TUMVis {
const std::string AbstractProperty::loggerCat_ = "TUMVis.core.datastructures.AbstractProperty";
}
#ifndef ABSTRACTPROPERTY_H__
#define ABSTRACTPROPERTY_H__
#include "tgt/logmanager.h"
#include <vector>
namespace TUMVis {
/**
* Abstract base class for TUMVis Pipelines.
*
*/
class AbstractProperty {
public:
/**
* Creates a AbstractProperty.
*/
AbstractProperty();
/**
* Virtual Destructor
**/
virtual ~AbstractProperty();
protected:
static const std::string loggerCat_;
};
}
#endif // ABSTRACTPROPERTY_H__
#include "observer.h"
namespace TUMVis {
Observer::Observer() {
}
Observer::~Observer() {
}
Observable::Observable() {
}
Observable::~Observable() {
}
void Observable::addObserver(Observer* o) const {
_observers.insert(o);
}
void Observable::removeObserver(Observer* o) const {
_observers.erase(o);
}
void Observable::notifyObservers() const {
for (std::set<Observer*>::iterator it = _observers.begin(); it != _observers.end(); ++it) {
(*it)->onNotify();
}
}
}
#ifndef OBSERVER_H__
#define OBSERVER_H__
#include <set>
namespace TUMVis {
/**
* Minimal implementation of the observer pattern.
* \sa Observable
* \todo Add more advanced version supporting arguments during notification.
*/
class Observer {
public:
Observer();
virtual ~Observer();
virtual void onNotify() = 0;
};
/**
* Minimal implementation of the observer pattern.
* \sa Observer
*/
class Observable {
public:
Observable();
virtual ~Observable();
/**
* Adds the given Observer to the observer set.
* \a o will be notified during Observable::notifyObservers().
* \param o Observer to add
*/
void addObserver(Observer* o) const;
/**
* Removes the given Observer from the observer set.
* \a o will no longer be notified during Observable::notifyObservers().
* \param o Observer to remove
*/
void removeObserver(Observer* o) const;
private:
/**
* Notifies all registered observers.
*/
void notifyObservers() const;
mutable std::set<Observer*> _observers; ///< Set of all observers for this subject
};
}
#endif // OBSERVER_H__
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment