Task #3118
Updated by Zhiyi Zhang over 8 years ago
This is a draft abstraction for schedule. It consists of three two class. -1-Schedule Schedule contains One is Schedule, another is Agenda(maybe there's a list of RepetitiveIntervals. Schedule itself contains a start time and an end time, better name), which defines is 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 -2-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 pattern: every day repeat unit: 2 repeat end time: 2015-08-25-00-00-00 -3-Interval A simple class which Here is used to be the return value of the functions in Schedule. It only contains a start time and an end time. abstraction: class Schedule { public: ///@brief Construct an empty schedule Schedule(TimePoint m_startTime; TimePoint m_endTime); Schedule(); template<encoding::Tag TAG> size_t wireEncode(EncodingImpl<TAG>& encoder) const; Block wireEncode(); void wireDecode(); ///@brief Add a new agenda, if there's a conflict, the agenda will use the union set of the agendas Schedule& addRepetitiveInterval(RepetitiveInterval repetitiveInterval); addAgenda(Agenda); ///@brief Delete an agenda, if the agenda ///@throw Error if there's no match RepetitiveInterval covers time that is not in existing agenda, this part time will be omitted Schedule& deleteRepetitiveInterval(RepetitiveInterval repetitiveInterval); deleteAgenda(Agenda); ///@brief Get Change an existing agenda, replace the Interval that cover the ts Interval getRepetitiveInterval(const TimePoint& ts); old one Schedule& replaceAgenda(Agenda, Agenda); ///@brief Get the next Interval agenda that cover the ts Interval getNextRepetitiveInterval(const Agenda getAgenda(const TimePoint& ts); private: ///@brief Check if two RepetitiveInterval agenda is conflicted bool isConflict(RepetitiveInterval repetitiveIntervalA, RepetitiveInterval repetitiveIntervalB); TimePoint m_startTime; TimePoint m_endTime; std::list<RepetitiveInterval> m_repetitiveIntervalList; isConflict(Agenda, Agenda); std::list<Agenda> m_agendaList; Block m_wire; }; class RepetitiveInterval Agenda { public: enum RepeatPattern{ NONE = 0, EVERY_DAY = 1, EVERY_WEEK = 2, EVERY_MONTH = 3 } public: ///@brief The construction, once the object is created, it becomes read-only RepetitiveInterval(TimePoint Agenda(TimePoint startTime, TimePoint endTime); Agenda(TimePoint startTime, TimePoint endTime, RepeatPattern pattern = RepetitiveInterval::NONE, pattern, TimePoint repeatEndTime = 0, size_T repeatUnit = 0); repeatEndTime); template<encoding::Tag TAG> size_t wireEncode(EncodingImpl<TAG>& encoder) const; Block wireEncode(); void wireDecode(); ///@brief Get the start time of the RepetitiveInterval agenda TimePoint getStartTime(); ///@brief Get the end time of the RepetitiveInterval agenda TimePoint getEndTime(); ///@brief Get the repeat pattern of the RepetitiveInterval agenda RepeatPattern getRepeatPattern(); ///@brief Get the repeat unit of the RepetitiveInterval size_t getRepeatUnit() ///@brief Check if the time point is in the RepetitiveInterval agenda bool isInAgenda(TimePoint tp); ///@brief Check if two RepetitiveInterval agendas are same bool equals(RepetitiveInterval repetitiveInterval); equals(Agenda); ///@brief reload the operator == bool operator==(const RepetitiveInterval& repetitiveInterval) Agenda& agenda) const; private: TimePoint m_startTime; TimePoint m_endTime; RepeatPattern m_repeatPattern; size_t m_repeatUnit; TimePoint m_repeatEndTime; Block m_wire; }; class Interval { public: TimePoint m_startTime; TimePoint m_endTime; };