Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef GUI_WIDGETS_AUXILIARY_NOTIFIER_HPP_INCLUDED
00017 #define GUI_WIDGETS_AUXILIARY_NOTIFIER_HPP_INCLUDED
00018
00019 #include "foreach.hpp"
00020
00021 #include "gui/auxiliary/notifiee.hpp"
00022
00023 #include <cassert>
00024 #include <map>
00025
00026 namespace gui2 {
00027
00028
00029
00030
00031
00032
00033
00034
00035 template<class FUNCTOR>
00036 class tnotifier
00037 {
00038 public:
00039
00040 typedef FUNCTOR tfunctor;
00041
00042 tnotifier()
00043 : notifiees_()
00044 {
00045 }
00046
00047 ~tnotifier()
00048 {
00049 typedef std::pair<tnotifiee<tfunctor>* const, tfunctor> thack;
00050 foreach(thack& item, notifiees_) {
00051 assert(item.first);
00052 assert((*item.first).notifier_ == this);
00053
00054 (*item.first).notifier_ = NULL;
00055 }
00056 }
00057
00058
00059
00060
00061
00062
00063
00064
00065 void connect_notifiee(
00066 tnotifiee<tfunctor>& notifiee
00067 , tfunctor functor)
00068 {
00069 notifiees_.insert(std::make_pair(¬ifiee, functor));
00070
00071 assert(!notifiee.notifier_);
00072
00073 notifiee.notifier_ = this;
00074 }
00075
00076
00077
00078
00079
00080
00081
00082
00083 void disconnect_notifiee(tnotifiee<tfunctor>& notifiee)
00084 {
00085 typename std::map<tnotifiee<tfunctor>*, tfunctor>::iterator
00086 itor = notifiees_.find(¬ifiee);
00087
00088 if(itor != notifiees_.end()) {
00089
00090 assert(notifiee.notifier_ == this);
00091
00092 notifiee.notifier_ = NULL;
00093
00094 notifiees_.erase(itor);
00095 }
00096 }
00097
00098
00099
00100 const std::map<tnotifiee<tfunctor>*, tfunctor>& notifiees() const
00101 {
00102 return notifiees_;
00103 }
00104
00105 private:
00106
00107
00108 std::map<tnotifiee<tfunctor>*, tfunctor> notifiees_;
00109
00110 };
00111
00112 }
00113
00114 #endif
00115
00116