summaryrefslogtreecommitdiff
path: root/src/listeners/baselistener.hpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-04-27 15:30:00 +0300
committerAndrei Karas <akaras@inbox.ru>2014-04-27 15:36:23 +0300
commitaf0ae4d0b7c56d540639bb1f4ba7cc458ec718c1 (patch)
treef95b356e4b201acb146c3aaed777d4cecd6b23eb /src/listeners/baselistener.hpp
parentd5586e6b6d5c7b1b83b3ec681e9da62840b5adaf (diff)
downloadplus-af0ae4d0b7c56d540639bb1f4ba7cc458ec718c1.tar.gz
plus-af0ae4d0b7c56d540639bb1f4ba7cc458ec718c1.tar.bz2
plus-af0ae4d0b7c56d540639bb1f4ba7cc458ec718c1.tar.xz
plus-af0ae4d0b7c56d540639bb1f4ba7cc458ec718c1.zip
Simplify AttributeListener.
Diffstat (limited to 'src/listeners/baselistener.hpp')
-rw-r--r--src/listeners/baselistener.hpp37
1 files changed, 35 insertions, 2 deletions
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