Task #3118
Updated by Zhiyi Zhang over 8 years ago
This is a draft abstraction for schedule. It consists of two class. **Schedule** ------------ Schedule contains a list of RepetitiveIntervals. Schedule itself contains a start time and an end time, which defines the start point and the end point of the schedule. Schedule implement wire encode and decode to support storage and transfer. The class can support: + An schedule with a start time and an end time + An infinite schedule with a start time only ### Nested Class in Schedule : RepetitiveInterval The element object in Schedule. A RepetitiveInterval is a time interval with the repeat pattern. RepetitiveInterval include the start time, end time, repeat pattern, repeat unit, repeat end time. RepetitiveInterval implement wire encode and decode to support storage and transfer. RepetitiveInterval can support: + An interval without any repeat pattern + An interval with a repeat pattern with/without a repeat end time + An interval with a repeat pattern and a repeat unit with/without a repeat end time An every two day interval with an repeat end time object maybe like: + start time: 2015-08-20-14-00-00 + end time: 2015-08-20-16-00-00 + repeat union: day + repeat quantity: 2 + repeat start time: 2015-08-18-00-00-00 + repeat end time: 2015-08-25-00-00-00 **Interval** ------------ A simple class which is used to be the return value of the functions in Schedule. It only contains a start time and an end time. Here is the abstraction of these two classes: ---------------------------------------------- class Schedule { public: ///@brief Construct an schedule Schedule(); Schedule(Block& block); Schedule(TimePoint m_startTime; TimePoint m_endTime); public: template<encoding::Tag TAG> size_t wireEncode(EncodingImpl<TAG>& encoder) const; Block wireEncode(); void wireDecode(); ///@brief Add a new repetitive interval Schedule& addWhiteInterval(TimePoint startTime, TimePoint endTime, RepeatUnit Unit = RepetitiveInterval::NONE, TimePoint repeatStartTime = 0, TimePoint repeatEndTime = 0, size_T repeatQuantity = 0); ///@brief Delete an repetitive interval Schedule& addBlackInterval(TimePoint startTime, TimePoint endTime, RepeatUnit Unit = RepetitiveInterval::NONE, TimePoint repeatStartTime = 0, TimePoint repeatEndTime = 0, size_T repeatQuantity = 0); ///@brief Get the Interval that cover the ts Interval getCoveringInterval(const TimePoint& ts); private: class RepetitiveInterval { public: enum RepeatUnit{ NONE = 0, DAY = 1, WEEK = 2, MONTH = 3 } public: RepetitiveInterval(); RepetitiveInterval(Block& block); RepetitiveInterval(TimePoint startTime, TimePoint endTime, RepeatUnit Unit = RepetitiveInterval::NONE, TimePoint repeatStartTime = 0, TimePoint repeatEndTime = 0, size_T repeatQuantity = 0); template<encoding::Tag TAG> size_t wireEncode(EncodingImpl<TAG>& encoder) const; Block wireEncode(); void wireDecode(); ///@brief Check if the time point is in the RepetitiveInterval bool isInRepetitiveInterval(TimePoint tp); ///@brief Get the covering interval Interval getCoveringInterval(); ///@brief To store in std::set bool operator <(RepetitiveInterval interval) const; private: TimePoint m_startTime; TimePoint m_endTime; RepeatUnit m_repeatUnit; size_t m_repeatQuantity; TimePoint m_repeatStartTime; TimePoint m_repeatEndTime; Block m_wire; }; private: TimePoint m_startTime; TimePoint m_endTime; std::set<RepetitiveInterval> std::list<RepetitiveInterval> m_whiteIntervalList; std::set<RepetitiveInterval> std::list<RepetitiveInterval> m_blackIntervalList; Block m_wire; }; class Interval { public: Interval(TimePoint startTime, TimePoint endTime); bool isInInterval(TimePoint tp); Interval getIntersection(Interval interval); private: TimePoint m_startTime; TimePoint m_endTime; };