/* -*- mode: c++; c-basic-offset: 3; -*- */ #ifndef SEGLIST_HH #define SEGLIST_HH #include "LockSegment.hh" #include #include //====================================== Segment list class /** LockSegList is an ordered list of segments of a given type. * @memo Segment list class. * @author J.Zweizig * @version 1.2; last modified 11/03/2006 */ class LockSegList { public: typedef unsigned long size_type; public: /** Segment list constructor. */ explicit LockSegList(const char* lid, const char* file=0); /** Segment list destructor. */ virtual ~LockSegList(void) {} /** Erase all the segments in the list. */ void clear(void); /** Coalesce overlapping segments. */ void coalesce(void); /** Look for the segment containing the specified time. */ int find(const Time& t) const throw(std::domain_error); /** Find the first segment that ends after the specified time. The index * of the found segment is returned. If there are no segments after the * specified time, an index equal to the size of segment list is returned. */ int findafter(const Time& t) const; const char* getListID(void) const; bool inSegment(const Time& t) const; bool inSegment(const Time& t, const Time& t2) const; void insert(const LockSegment& l); void invert(void); void read(const std::string& file); void setDebug(int lvl); size_type size(void) const; const LockSegment& operator[](size_type seg) const; const LockSegment& operator[](const Time& t) const throw(std::domain_error); LockSegList& operator|=(const LockSegList& t); LockSegList& operator&=(const LockSegList& t); bool overlap(const Time& t, const Time& t2) const; std::ostream& putID(std::ostream& out, size_type inx) const; private: LockSegment& ref(size_type seg); public: typedef std::vector SegList_type; typedef SegList_type::const_iterator seg_iter; private: std::string mListID; SegList_type mList; int mDebug; }; //====================================== Segment list inlined methods inline const char* LockSegList::getListID(void) const { return mListID.c_str(); } inline const LockSegment& LockSegList::operator[](size_type seg) const { return mList[seg]; } inline const LockSegment& LockSegList::operator[](const Time& t) const throw(std::domain_error) { return mList[find(t)]; } inline LockSegment& LockSegList::ref(size_type seg) { return mList[seg]; } inline LockSegList::size_type LockSegList::size(void) const { return mList.size(); } #endif // !defined(SEGLIST_HH)