#ifndef LISTENERSET_H_
#define LISTENERSET_H_

#include <vector>

template<typename Listener>
class ListenerSet {
public:
	typedef std::vector<Listener*> ListenersType;
	typedef typename ListenersType::iterator iterator;
public:
	void add(Listener* item) {
		m_listeners.push_back(item);
	}
	void remove(AVDHandle handle) {
		iterator it = find(handle);
		if (m_listeners.end() != it) {
			//delete *it;
			m_listeners.erase(it);
		}
	}
	bool hasModule(AVDHandle handle) {
		return (find(handle) != m_listeners.end());
	}
	iterator find(AVDHandle handle) {
		iterator it = m_listeners.begin();
		for (; m_listeners.end() != it; ++it) {
			if ((*it)->getHandle() == handle) {
				return it;
			}
		}
		return m_listeners.end();
	}
	Listener* getItem(AVDHandle handle) {
		iterator it = find(handle);
		return m_listeners.end() == it ? NULL : (*it);
	}
protected:
	ListenersType m_listeners;
};


#endif //LISTENERSET_H_