event.h

Go to the documentation of this file.
00001 //    sampalib.org ESL library and tools
00002 //    Copyright (C) 2007  Thierry Grellier
00003 //
00004 //    This program is free software; you can redistribute it and/or modify
00005 //    it under the terms of the GNU General Public License version 2 as
00006 //    published by the Free Software Foundation.
00007 //
00008 //    This program is distributed in the hope that it will be useful,
00009 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 //    GNU General Public License for more details.
00012 //
00013 //    You should have received a copy of the GNU General Public License along
00014 //    with this program; if not, write to the Free Software Foundation, Inc.,
00015 //    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00016 //
00017 //    contact: www.sampalib.org
00018 
00019 #ifndef SAMPA_EVENT_H
00020 #define SAMPA_EVENT_H
00021 
00022 #include "sampa/core/object.h"
00023 #include "sampa/core/triggerable.h"
00024 
00025 namespace Sampa {
00026 
00027   class Time;
00028   class ActualEvent;
00029   class ActualEventSingle;
00030   class ActualAndEventSingle;
00031   class ActualAndEvent;
00032   class EventListenerSingle;
00033   class Clock;
00034   class ActualClock;
00035   
00037   class SAMPA_PERSISTENT_CLASS(EventFinder) {
00038   public:
00039     EventFinder(const EventFinder&);
00040     EventFinder(ActualEventSingle*);
00041     ~EventFinder();
00042     EventFinder& operator=(const EventFinder&);
00043     ActualEventSingle* resolve();
00044     ActualEventSingle* is_resolved() const;
00045     void unsubscribe(Triggerable*);  
00046     void subscribe(Triggerable*);
00047     void notify();
00048     void notify_in(const Time&);
00049     void notify_at(const Time&);
00050     class Helper;
00051     void set_actual_event(ActualEventSingle* event);
00052     ActualEventSingle* get_actual_event() const { return m_actual_event; }
00053   protected:
00054     void propagate_actual_event(ActualEventSingle* event);
00055     ActualEventSingle*  m_actual_event;
00056   private:
00057     Helper*             m_finder_group; // transient...
00058     SAMPA_PERSISTENT(EventFinder);  
00059   };
00060 
00061   class TemporaryEventExpression {
00062   public:
00063     TemporaryEventExpression(const TemporaryEventExpression& other) 
00064       { m_expression = other.m_expression; }
00065     TemporaryEventExpression& operator=(const TemporaryEventExpression& other) 
00066       { m_expression = other.m_expression; return *this; }
00067     ActualAndEventSingle* get_expression() const { return m_expression; }
00068     ActualAndEvent* convert_to_multiple_subscriber() const;
00069   private:
00070     bool is_or() const;
00071     bool is_and() const;
00072     TemporaryEventExpression(ActualAndEventSingle*);
00073     friend TemporaryEventExpression operator|(EventListenerSingle&, EventListenerSingle&);
00074     friend TemporaryEventExpression operator|(TemporaryEventExpression&, EventListenerSingle&);
00075     friend TemporaryEventExpression operator&(EventListenerSingle&, EventListenerSingle&);
00076     friend TemporaryEventExpression operator&(TemporaryEventExpression&, EventListenerSingle&);
00077     mutable ActualAndEventSingle* m_expression;
00078   };
00080 
00091   class EventListenerSingle : public Object {
00092   public:
00093     EventListenerSingle(const Name&); 
00094     EventListenerSingle& operator=(const EventListenerSingle&); 
00095     EventListenerSingle& operator=(const TemporaryEventExpression&); 
00096 
00097     EventListenerSingle(const EventListenerSingle&);
00098     ~EventListenerSingle();
00099     void unsubscribe(Triggerable&);  
00100     void subscribe(Triggerable&);  
00101     ActualEventSingle* is_resolved() const;
00102     ActualEventSingle* resolve();
00103     bool check_binding();  
00104     EventFinder& get_finder();
00105   protected:
00106     friend class ActualClock;
00107     void set_actual_event(ActualEventSingle*);
00108     EventListenerSingle(const Name&, ActualEventSingle*);
00109     EventListenerSingle(ActualEventSingle*);
00110     EventFinder                 m_finder;
00111     EventListenerSingle*        m_pool_next;
00112     static EventListenerSingle* M_pool;
00113     friend TemporaryEventExpression operator|(EventListenerSingle&, EventListenerSingle&);
00114     friend TemporaryEventExpression operator|(TemporaryEventExpression&, EventListenerSingle&);
00115     friend TemporaryEventExpression operator&(EventListenerSingle&, EventListenerSingle&);
00116     friend TemporaryEventExpression operator&(TemporaryEventExpression&, EventListenerSingle&); 
00117   public:
00118     SAMPA_PERSISTENT(EventListenerSingle);  
00120   };
00121 
00122   TemporaryEventExpression operator|(EventListenerSingle&, EventListenerSingle&);
00123   TemporaryEventExpression operator|(TemporaryEventExpression&, EventListenerSingle&);
00124   TemporaryEventExpression operator&(EventListenerSingle&, EventListenerSingle&);
00125   TemporaryEventExpression operator&(TemporaryEventExpression&, EventListenerSingle&);
00126 
00134   class EventSingle : public EventListenerSingle {
00135   public:
00136     EventSingle(const Name&);
00137     void notify();                     
00138     void notify_in(const Time& delay); 
00139     void notify_at(const Time& date);  
00140 
00141   private:
00142     // disabled
00143     EventSingle(const EventSingle&);
00144     EventSingle& operator=(const EventSingle&);
00145   public:
00146     SAMPA_PERSISTENT(EventSingle);  
00148   };
00149 
00154   class EventListener : public EventListenerSingle {
00155   public:
00156     EventListener(const Name&);
00157     EventListener& operator=(const TemporaryEventExpression&); 
00158     EventListener& operator=(const EventListener&); 
00159 
00160     EventListener(const EventListener&);
00161   protected:
00162     friend class Clock;
00163     EventListener(const Name&, ActualEventSingle*);
00164     EventListener(ActualEventSingle*);
00165       friend class ActualClock;
00166   public:
00167     SAMPA_PERSISTENT(EventListener);  
00169   };
00170 
00177   class Event : public EventListener {
00178   public:
00179     Event(const Name&);
00180     void notify();                     
00181     void notify_in(const Time& delay); 
00182     void notify_at(const Time& date);  
00183 
00184   private:
00185     // disabled
00186     Event(const Event&);
00187     Event& operator=(const Event&);
00188   public:
00189     SAMPA_PERSISTENT(Event);  
00191   };
00192 
00198   class ClockedEvent : public EventListener {
00199     SAMPA_PERSISTENT(ClockedEvent);
00200   public:
00201     ClockedEvent(const Name&);    
00202     void set_clock(Clock* clock)
00203       {  p_clock = clock; }
00204     Clock* get_clock() const 
00205       {  return p_clock; }
00206     void cancel(); 
00207     void notify(); 
00208     void notify_next_falling() 
00209       { notify_in_n_falling(1); }
00210     void notify_in_n_falling(int n); 
00211     void notify_next_rising() 
00212       { notify_in_n_rising(1); }
00213     void notify_in_n_rising(int n); 
00214 
00215     bool check_binding();
00216   private:
00217     ActualEvent* m_ev;
00218     Clock*       p_clock;
00220   };
00221   
00225   class ClockedEventSingle : public EventListenerSingle {
00226     SAMPA_PERSISTENT(ClockedEventSingle);
00227   public:
00228     ClockedEventSingle(const Name&);    
00229     void set_clock(Clock* clock)
00230       {  p_clock = clock; }
00231     Clock* get_clock() const 
00232       {  return p_clock; }
00233     void cancel(); 
00234     void notify(); 
00235     void notify_next_falling() 
00236       { notify_in_n_falling(1); }
00237     void notify_in_n_falling(int n); 
00238     void notify_next_rising() 
00239       { notify_in_n_rising(1); }
00240     void notify_in_n_rising(int n); 
00241 
00242     bool check_binding();
00243 //    bool check_binding() { return p_clock != 0 }
00244   private:
00245     ActualEvent* m_ev;
00246     Clock*       p_clock;
00248   };
00249 
00250 }
00251 
00252 #endif

Generated on Sat Feb 16 16:23:15 2008 for Sampa by  doxygen 1.5.3