Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   Related Pages  

dsched.h

Go to the documentation of this file.
00001 
00012 #ifndef __dsched_h
00013 #define __dsched_h
00014 
00015 #include <math.h>
00016 
00017 #include <functional>
00018 #include <map>
00019 #include <set>
00020 #include <vector>
00021 #include <queue>
00022 #include <string>
00023 
00024 #include "punnets_base.h"
00025 
00027 namespace punnets_common {
00029 
00030 class tsched_double;
00031 typedef tsched_double tscheduler;
00032 
00033 class tevent;
00034 class greater_tevent;
00035 typedef std::priority_queue< tevent, std::vector<tevent>, greater_tevent > tqueue;
00036 
00039 
00052 class taction
00053 {
00054 public:
00055     taction() { }
00056     virtual ~taction() { }
00057     
00060     virtual void activate(tscheduler &scheduler, ntime_t current_time) = 0;
00062     virtual tqueue *queue() const = 0;
00064     virtual const char *getClassName() const = 0;
00065 };
00066 
00074 class tevent
00075 {
00076     ntime_t time;
00077     taction *act;
00078 
00079 public:
00081     tevent(ntime_t itime, taction &iact)
00082         : time(itime), act(&iact) { /*act->getName();*/ }
00083 
00085     ntime_t getTime() const { return time; }
00087     taction& getAction() const { return *act; }
00088     
00090     void activate(tscheduler &scheduler) const 
00091         { act->activate(scheduler, time); }
00092 };
00093 
00094 
00101 
00102 struct greater_tevent 
00103     : public std::binary_function<const tevent &, const tevent &, bool>
00104 {
00105     bool operator() (const tevent &a, const tevent &b) 
00106         { return a.getTime() > b.getTime(); }
00107 };
00108 
00109 
00114 
00115 class tsched_double
00116 {
00118     typedef std::pair< ntime_t, tqueue * > sched_entry;
00119     
00121     struct less_sched_entry 
00122         : public std::binary_function< const sched_entry &, const sched_entry &, bool >
00123     {
00124         bool operator() (const sched_entry &a, const sched_entry &b) 
00125         { return (a.first != b.first ? a.first < b.first : a.second < b.second); }
00126     };
00127 
00129     std::set< sched_entry, less_sched_entry > global_queue;
00131     const tqueue * processing_queue;
00132 
00133 public:
00135     tsched_double();
00136 
00138     void scheduleEvent(const tevent &event);
00140     void scheduleEvent(ntime_t t, taction &act) 
00141             { scheduleEvent( tevent(t, act) ); }
00143     bool isScheduled() const { return ! global_queue.empty(); }
00145     ntime_t run(ntime_t until = HUGE_VAL);
00146 };
00147 
00150 } // namespace punnets_common
00152 
00153 #endif // __dsched_h

Generated on Mon Jun 16 15:42:25 2003 for Punnets by doxygen1.2.18