BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Kinetic/Multi_listener.h
Go to the documentation of this file.
00001 // Copyright (c) 2005  Stanford University (USA).
00002 // All rights reserved.
00003 //
00004 // This file is part of CGAL (www.cgal.org); you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public License as
00006 // published by the Free Software Foundation; version 2.1 of the License.
00007 // See the file LICENSE.LGPL distributed with CGAL.
00008 //
00009 // Licensees holding a valid commercial license may use this file in
00010 // accordance with the commercial license agreement provided with the software.
00011 //
00012 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00013 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00014 //
00015 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Kinetic_data_structures/include/CGAL/Kinetic/Multi_listener.h $
00016 // $Id: Multi_listener.h 42714 2008-04-01 18:03:41Z drussel $
00017 // 
00018 //
00019 // Author(s)     : Daniel Russel <drussel@alumni.princeton.edu>
00020 
00021 #ifndef CGAL_TOOLS_MULTI_LISTENER_BASE_H
00022 #define CGAL_TOOLS_MULTI_LISTENER_BASE_H
00023 #include <CGAL/basic.h>
00024 CGAL_KINETIC_BEGIN_NAMESPACE
00025 
00027 
00032 template <class Interface>
00033 class Multi_listener_base: public Interface
00034 {
00035   typedef Multi_listener_base<Interface> This;
00036 public:
00037   typedef typename Interface::Notifier_handle::element_type Notifier;
00038 
00039   Multi_listener_base(){}
00040 
00041   virtual ~Multi_listener_base() {
00042     if (h_ != NULL) h_->delete_listener(this);
00043   }
00044 
00045   void set_notifier(Notifier * n) {
00046     if (h_!= NULL) h_->delete_listener(this);
00047     h_=n;
00048     h_->new_listener(this);
00049   }
00050   void set_notifier(typename Interface::Notifier_handle t) {
00051     set_notifier(t.get());
00052   }
00053 
00054 
00055   typename Interface::Notifier_handle::element_type* notifier() {
00056     return h_.get();
00057   }
00058 
00059   const typename Interface::Notifier_handle::element_type* notifier() const
00060   {
00061 
00062     return h_.get();
00063   }
00064 
00065   virtual void new_notification(typename Interface::Notification_type nt)=0;
00066 
00067 
00068   Multi_listener_base(const This &o) {
00069     h_= o.h_;
00070     h_->new_listener(this);
00071   }
00072 
00073   const This& operator=(const This &o) {
00074     h_= o.h_;
00075     h_->new_listener(this);
00076     return *this;
00077   }
00078 protected:
00079   typename Interface::Notifier_handle h_;
00080 };
00081 
00082 /*
00083 #define CGAL_KINETIC_MULTILISTENER(...) private:                \
00084   struct Listener_core{                                         \
00085     typedef typename This::Handle Notifier_handle;              \
00086       typedef enum {__VA_ARGS__} Notification_type;             \
00087   };                                                            \
00088 public:                                                         \
00089  typedef Multi_listener_base<Listener_core> Listener;           \
00090  friend class Multi_listener_base<Listener_core>;               \
00091 private:                                                        \
00092  void new_listener(Listener *sk) {                              \
00093    listeners_.push_back(sk);                                    \
00094  }                                                              \
00095  void delete_listener(Listener *kds) {                          \
00096    for (unsigned int i=0; i< listeners_.size(); ++i){           \
00097      if (listeners_[i] == kds) {                                \
00098        std::swap(listeners_[i], listeners_.back());             \
00099        listeners_.pop_back();                                   \
00100        return;                                                  \
00101      }                                                          \
00102    }                                                            \
00103  }                                                              \
00104  std::vector<Listener*> listeners_;
00105 
00106 
00107 #define CGAL_KINETIC_MULTILISTENERNT(...) private:              \
00108   struct Listener_core{                                         \
00109     typedef This::Handle Notifier_handle;                       \
00110     typedef enum {__VA_ARGS__} Notification_type;               \
00111   };                                                            \
00112 public:                                                         \
00113  typedef Multi_listener_base<Listener_core> Listener;           \
00114  friend class Multi_listener_base<Listener_core>;               \
00115 private:                                                        \
00116  void new_listener(Listener *sk) {                              \
00117    listeners_.push_back(sk);                                    \
00118  }                                                              \
00119  void delete_listener(Listener *kds) {                          \
00120    for (unsigned int i=0; i< listeners_.size(); ++i){           \
00121      if (listeners_[i] == kds) {                                \
00122        std::swap(listeners_[i], listeners_.back());             \
00123        listeners_.pop_back();                                   \
00124        return;                                                  \
00125      }                                                          \
00126    }                                                            \
00127  }                                                              \
00128  std::vector<Listener*> listeners_;
00129 */
00130 
00131 
00132 
00133 #define CGAL_KINETIC_MULTILISTENER1(A) private:                         \
00134   struct Listener_core{                                                 \
00135     typedef typename This::Handle Notifier_handle;                      \
00136     typedef enum {A} Notification_type;                                 \
00137   };                                                                    \
00138 public:                                                                 \
00139  typedef CGAL::Kinetic::Multi_listener_base<Listener_core> Listener;    \
00140  friend class CGAL::Kinetic::Multi_listener_base<Listener_core>;                       \
00141 private:                                                                \
00142  void new_listener(Listener *sk) {                                      \
00143    listeners_.push_back(sk);                                            \
00144  }                                                                      \
00145  void delete_listener(Listener *kds) {                                  \
00146    for (unsigned int i=0; i< listeners_.size(); ++i){                   \
00147      if (listeners_[i] == kds) {                                        \
00148        std::swap(listeners_[i], listeners_.back());                     \
00149        listeners_.pop_back();                                           \
00150        return;                                                          \
00151      }                                                                  \
00152    }                                                                    \
00153  }                                                                      \
00154  std::vector<Listener*> listeners_;
00155 
00156 
00157 #define CGAL_KINETIC_MULTILISTENERNT1(A) private:                       \
00158   struct Listener_core{                                                 \
00159     typedef This::Handle Notifier_handle;                               \
00160     typedef enum {A} Notification_type;                                 \
00161   };                                                                    \
00162 public:                                                                 \
00163  typedef CGAL::Kinetic::Multi_listener_base<Listener_core> Listener;    \
00164  friend class CGAL::Kinetic::Multi_listener_base<Listener_core>;        \
00165 private:                                                                \
00166  void new_listener(Listener *sk) {                                      \
00167    listeners_.push_back(sk);                                            \
00168  }                                                                      \
00169  void delete_listener(Listener *kds) {                                  \
00170    for (unsigned int i=0; i< listeners_.size(); ++i){                   \
00171      if (listeners_[i] == kds) {                                        \
00172        std::swap(listeners_[i], listeners_.back());                     \
00173        listeners_.pop_back();                                           \
00174        return;                                                          \
00175      }                                                                  \
00176    }                                                                    \
00177  }                                                                      \
00178  std::vector<Listener*> listeners_;
00179 
00180 
00181 
00182 #define CGAL_KINETIC_MULTILISTENER2(A,B) private:                       \
00183   struct Listener_core{                                                 \
00184     typedef typename This::Handle Notifier_handle;                      \
00185     typedef enum {A,B} Notification_type;                               \
00186   };                                                                    \
00187 public:                                                                 \
00188  typedef CGAL::Kinetic::Multi_listener_base<Listener_core> Listener;    \
00189  friend class CGAL::Kinetic::Multi_listener_base<Listener_core>;        \
00190 private:                                                                \
00191  void new_listener(Listener *sk) {                                      \
00192    listeners_.push_back(sk);                                            \
00193  }                                                                      \
00194  void delete_listener(Listener *kds) {                                  \
00195    for (unsigned int i=0; i< listeners_.size(); ++i){                   \
00196      if (listeners_[i] == kds) {                                        \
00197        std::swap(listeners_[i], listeners_.back());                     \
00198        listeners_.pop_back();                                           \
00199        return;                                                          \
00200      }                                                                  \
00201    }                                                                    \
00202  }                                                                      \
00203  std::vector<Listener*> listeners_;
00204 
00205 
00206 #define CGAL_KINETIC_MULTILISTENERNT2(A,B) private:                     \
00207   struct Listener_core{                                                 \
00208     typedef This::Handle Notifier_handle;                               \
00209     typedef enum {A,B} Notification_type;                               \
00210   };                                                                    \
00211 public:                                                                 \
00212  typedef CGAL::Kinetic::Multi_listener_base<Listener_core> Listener;    \
00213  friend class CGAL::Kinetic::Multi_listener_base<Listener_core>;        \
00214 private:                                                                \
00215  void new_listener(Listener *sk) {                                      \
00216    listeners_.push_back(sk);                                            \
00217  }                                                                      \
00218  void delete_listener(Listener *kds) {                                  \
00219    for (unsigned int i=0; i< listeners_.size(); ++i){                   \
00220      if (listeners_[i] == kds) {                                        \
00221        std::swap(listeners_[i], listeners_.back());                     \
00222        listeners_.pop_back();                                           \
00223        return;                                                          \
00224      }                                                                  \
00225    }                                                                    \
00226  }                                                                      \
00227  std::vector<Listener*> listeners_;
00228 
00229 #define CGAL_KINETIC_MULTINOTIFY(field) for(typename std::vector<Listener*>::iterator it= listeners_.begin(); it != listeners_.end(); ++it){ \
00230     (*it)->new_notification(Listener::field);                           \
00231   }
00232 
00233 #define CGAL_KINETIC_MULTILISTENER_DESTRUCTOR CGAL_assertion(listeners_.empty());
00234 CGAL_KINETIC_END_NAMESPACE
00235 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines