00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 #ifndef CINTERVALMANAGER_H
00020 #define CINTERVALMANAGER_H
00021 
00022 #include "directbase.h"
00023 #include "cInterval.h"
00024 #include "pointerTo.h"
00025 #include "pvector.h"
00026 #include "pmap.h"
00027 #include "vector_int.h"
00028 
00029 class EventQueue;
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 
00041 
00042 
00043 
00044 
00045 
00046 class EXPCL_DIRECT CIntervalManager {
00047 PUBLISHED:
00048   CIntervalManager();
00049   ~CIntervalManager();
00050 
00051   INLINE void set_event_queue(EventQueue *event_queue);
00052   INLINE EventQueue *get_event_queue() const;
00053 
00054   int add_c_interval(CInterval *interval, bool external);
00055   int find_c_interval(const string &name) const;
00056 
00057   CInterval *get_c_interval(int index) const;
00058   void remove_c_interval(int index);
00059 
00060   int interrupt();
00061   int get_num_intervals() const;
00062 
00063   void step();
00064   int get_next_event();
00065   int get_next_removal();
00066 
00067   void output(ostream &out) const;
00068   void write(ostream &out) const;
00069 
00070   static CIntervalManager *get_global_ptr();
00071 
00072 private:
00073   void finish_interval(CInterval *interval);
00074   void remove_index(int index);
00075 
00076   enum Flags {
00077     F_external      = 0x0001,
00078     F_meta_interval = 0x0002,
00079   };
00080   class IntervalDef {
00081   public:
00082     PT(CInterval) _interval;
00083     int _flags;
00084     int _next_slot;
00085   };
00086   typedef pvector<IntervalDef> Intervals;
00087   Intervals _intervals;
00088   typedef pmap<string, int> NameIndex;
00089   NameIndex _name_index;
00090   typedef vector_int Removed;
00091   Removed _removed;
00092   EventQueue *_event_queue;
00093 
00094   int _first_slot;
00095   int _next_event_index;
00096 
00097   static CIntervalManager *_global_ptr;
00098 };
00099 
00100 INLINE ostream &operator << (ostream &out, const CInterval &ival_mgr);
00101 
00102 #include "cIntervalManager.I"
00103 
00104 #endif
00105 
00106 
00107