00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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;
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
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
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
00244 private:
00245 ActualEvent* m_ev;
00246 Clock* p_clock;
00248 };
00249
00250 }
00251
00252 #endif