inline bool period<point_rep,duration_rep>::is_adjacent(const period<point_rep,duration_rep>& other) const { return (other.begin() == end() || begin_ == other.end()); }
inline period<point_rep,duration_rep> period<point_rep,duration_rep>::span(const period<point_rep,duration_rep>& other) const { point_rep start((begin_ < other.begin_) ? begin() : other.begin()); point_rep newend((last_ < other.last_) ? other.end() : this->end()); return period<point_rep,duration_rep>(start, newend); }
inline bool period<point_rep,duration_rep>::intersects(const period<point_rep,duration_rep>& other) const { return ( contains(other.begin_) || other.contains(begin_) || ((other.begin_ < begin_) && (other.last_ >= begin_))); }
inline period<point_rep,duration_rep> period<point_rep,duration_rep>::intersection(const period<point_rep,duration_rep>& other) const { if (begin_ > other.begin_) { if (last_ <= other.last_) { //case2 return *this; } //case 1 return period<point_rep,duration_rep>(begin_, other.end()); } else { if (last_ <= other.last_) { //case3 return period<point_rep,duration_rep>(other.begin_, this->end()); } //case4 return other; } //unreachable }
inline period<point_rep,duration_rep> period<point_rep,duration_rep>::merge(const period<point_rep,duration_rep>& other) const { if (this->intersects(other)) { if (begin_ < other.begin_) { return period<point_rep,duration_rep>(begin_, last_ > other.last_ ? this->end() : other.end()); } return period<point_rep,duration_rep>(other.begin_, last_ > other.last_ ? this->end() : other.end()); } return period<point_rep,duration_rep>(begin_,begin_); // no intersect return null }
bool operator <= (const period& pe) const {return this->total() <= pe.total();}
bool operator > (const period& pe) const {return this->total() > pe.total();}
/// Allow periods to be compared for equality bool operator==(const period &p) const { return this->period<void>::operator==(p) && value() == p.value(); }
/// Allow periods to be compared for equality bool operator==(const period<void> &p) const { return start() == p.start() && end() == p.end(); }