aboutsummaryrefslogtreecommitdiffstats
path: root/signal-composer-binding/observer-pattern.hpp
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-09-25 01:10:42 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2017-12-14 11:00:25 +0100
commit1a832ce483ff8c1276bc3cd3d97e3caadb38c4df (patch)
treec0d62a2ef4aff80eebea1454124a324ca6ccc5d2 /signal-composer-binding/observer-pattern.hpp
parent51ee5299a7db41e52da2cf52dd9cd9c05b76740a (diff)
Implement recursionCheck using observer pattern
Change-Id: Ic404c098f316106abe1918c3cd100ae047f4f555 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'signal-composer-binding/observer-pattern.hpp')
-rw-r--r--signal-composer-binding/observer-pattern.hpp41
1 files changed, 8 insertions, 33 deletions
diff --git a/signal-composer-binding/observer-pattern.hpp b/signal-composer-binding/observer-pattern.hpp
index aba2847..940a80b 100644
--- a/signal-composer-binding/observer-pattern.hpp
+++ b/signal-composer-binding/observer-pattern.hpp
@@ -63,31 +63,11 @@ public:
if(it != observableList_.end())
{observableList_.erase(it);}
}
-/*
- void recursionCheck(T* obs)
- {
- for (const auto& obs: observersList_)
- {
- if( id_ == obs->id())
- {return -1;}
- if( origId == obs->id())
- {return -1;}
- if(! obs->recursionCheck(origId))
- {return -1;}
- }
- return 0;
- }
-*/
};
template <class T>
class Observable
{
-private:
- std::list<Observer<T>*> observerList_;
- typedef typename std::list<Observer<T>*>::iterator iterator_;
- typedef typename std::list<Observer<T>*>::const_iterator const_iterator_;
-
public:
void addObserver(Observer<T>* observer)
{
@@ -101,19 +81,10 @@ public:
if(it != observerList_.end())
{observerList_.erase(it);}
}
-/*
- int recursionCheck()
- {
- for (auto& obs: observerList_)
- {
- if( static_cast<T*>(obs) == static_cast<T*>(this))
- {return -1;}
- if( obs->recursionCheck(id_))
- {return -1;}
- }
- return 0;
- }
-*/
+
+ virtual int initialRecursionCheck() = 0;
+ virtual int recursionCheck(T* obs) = 0;
+
virtual ~Observable()
{
iterator_ itb = observerList_.begin();
@@ -126,6 +97,10 @@ public:
}
protected:
+ std::list<Observer<T>*> observerList_;
+ typedef typename std::list<Observer<T>*>::iterator iterator_;
+ typedef typename std::list<Observer<T>*>::const_iterator const_iterator_;
+
void notify()
{
iterator_ itb=observerList_.begin();