summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/listeners/attributelistener.cpp25
-rw-r--r--src/listeners/attributelistener.h13
-rw-r--r--src/listeners/baselistener.hpp37
3 files changed, 38 insertions, 37 deletions
diff --git a/src/listeners/attributelistener.cpp b/src/listeners/attributelistener.cpp
index b547cb219..244bd9a3f 100644
--- a/src/listeners/attributelistener.cpp
+++ b/src/listeners/attributelistener.cpp
@@ -20,31 +20,9 @@
#include "listeners/attributelistener.h"
-#include "listeners/baselistener.hpp"
-
#include "debug.h"
-std::vector<AttributeListener*> AttributeListener::mListeners;
-
-AttributeListener::AttributeListener()
-{
- addListener(this);
-}
-
-AttributeListener::~AttributeListener()
-{
- removeListener(this);
-}
-
-void AttributeListener::addListener(AttributeListener *const listener)
-{
- mListeners.push_back(listener);
-}
-
-void AttributeListener::removeListener(AttributeListener *const listener)
-{
- listenerRemoveListener;
-}
+defineListener(AttributeListener)
void AttributeListener::distributeEvent(const int id,
const int oldVal,
@@ -58,4 +36,3 @@ void AttributeListener::distributeEvent(const int id,
listener->attributeChanged(id, oldVal, newVal);
}
}
-
diff --git a/src/listeners/attributelistener.h b/src/listeners/attributelistener.h
index 83605ffe9..f30dfa26f 100644
--- a/src/listeners/attributelistener.h
+++ b/src/listeners/attributelistener.h
@@ -21,31 +21,22 @@
#ifndef LISTENERS_ATTRIBUTELISTENER_H
#define LISTENERS_ATTRIBUTELISTENER_H
-#include <vector>
+#include "listeners/baselistener.hpp"
#include "localconsts.h"
class AttributeListener
{
public:
- AttributeListener();
-
- virtual ~AttributeListener();
-
virtual void attributeChanged(const int id,
const int oldVal,
const int newVal) = 0;
- static void addListener(AttributeListener *const listener);
-
- static void removeListener(AttributeListener *const listener);
-
static void distributeEvent(const int id,
const int oldVal,
const int newVal);
- private:
- static std::vector<AttributeListener*> mListeners;
+ defineListenerHeader(AttributeListener)
};
#endif // LISTENERS_ATTRIBUTELISTENER_H
diff --git a/src/listeners/baselistener.hpp b/src/listeners/baselistener.hpp
index ae3c7112e..66dd0d7cf 100644
--- a/src/listeners/baselistener.hpp
+++ b/src/listeners/baselistener.hpp
@@ -21,9 +21,29 @@
#ifndef LISTENERS_BASELISTENER_HPP
#define LISTENERS_BASELISTENER_HPP
-#define listenerRemoveListener \
+#include <vector>
+
+#define defineListener(name) \
+ std::vector<name*> name::mListeners; \
+ \
+ name::name() \
+ { \
+ addListener(this); \
+ } \
+ \
+ name::~name() \
+ { \
+ removeListener(this); \
+ } \
+ \
+ void name::addListener(name *const listener) \
{ \
- std::vector<AttributeListener*>::iterator it = mListeners.begin(); \
+ mListeners.push_back(listener); \
+ } \
+ \
+ void name::removeListener(name *const listener) \
+ { \
+ std::vector<name*>::iterator it = mListeners.begin(); \
while (it != mListeners.end()) \
{ \
if (*it == listener) \
@@ -33,4 +53,17 @@
} \
}
+#define defineListenerHeader(name) \
+ public: \
+ name(); \
+ \
+ virtual ~name(); \
+ \
+ static void addListener(name *const listener); \
+ \
+ static void removeListener(name *const listener); \
+ \
+ private: \
+ static std::vector<name*> mListeners;
+
#endif // LISTENERS_BASELISTENER_HPP