Project

General

Profile

Task #3118

Updated by Zhiyi Zhang over 8 years ago

This is a draft abstraction for schedule. It consists of three class. 

 
 -1-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 

 -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 is used to be the return value of the functions in Schedule. It only contains a start time and an end time. 


     class Schedule 
     { 
     public: 
       ///@brief Construct an empty schedule 
       Schedule(TimePoint m_startTime; 
                TimePoint m_endTime); 

       template<encoding::Tag TAG> 
       size_t 
       wireEncode(EncodingImpl<TAG>& encoder) const; 

       Block 
       wireEncode(); 

       void 
       wireDecode(); 

       ///@brief Add a new agenda 
       Schedule& 
       addRepetitiveInterval(RepetitiveInterval repetitiveInterval); 

       ///@brief Delete an agenda 
       ///@throw Error if there's no match RepetitiveInterval 
       Schedule& 
       deleteRepetitiveInterval(RepetitiveInterval repetitiveInterval); 

       ///@brief Get the Interval that cover the ts 
       Interval 
       getRepetitiveInterval(const TimePoint& ts); 

       ///@brief Get the next Interval that cover the ts 
       Interval 
       getNextRepetitiveInterval(const TimePoint& ts); 

     private: 
       ///@brief Check if two RepetitiveInterval is conflicted 
       bool 
       isConflict(RepetitiveInterval repetitiveIntervalA, RepetitiveInterval repetitiveIntervalB); 

       TimePoint m_startTime; 
       TimePoint m_endTime; 
       std::list<RepetitiveInterval> m_repetitiveIntervalList; 

       Block m_wire; 
     }; 

     class RepetitiveInterval 
     { 
     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 startTime, 
                          TimePoint endTime, 
                          RepeatPattern pattern = RepetitiveInterval::NONE, 
                          TimePoint repeatEndTime = 0, 
                          size_T repeatUnit = 0); 

       

      template<encoding::Tag TAG> 
       size_t 
       wireEncode(EncodingImpl<TAG>& encoder) const; 

       Block 
       wireEncode(); 

       void 
       wireDecode(); 

       ///@brief Get the start time of the RepetitiveInterval 
       TimePoint 
       getStartTime(); 

       ///@brief Get the end time of the RepetitiveInterval 
       TimePoint 
       getEndTime(); 

       ///@brief Get the repeat pattern of the RepetitiveInterval 
       RepeatPattern 
       getRepeatPattern(); 

       ///@brief Get the repeat unit of the RepetitiveInterval 
       size_t 
       getRepeatUnit() 

       ///@brief Check if the time point is in the RepetitiveInterval 
       bool 
       isInAgenda(TimePoint tp); 

       ///@brief Check if two RepetitiveInterval    are same 
       bool 
       equals(RepetitiveInterval repetitiveInterval); 

       ///@brief reload the operator 
       bool 
       operator==(const RepetitiveInterval& repetitiveInterval) 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; 
     };

Back