Project

General

Profile

Task #3118

Updated by Zhiyi Zhang over 8 years ago

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

 **Schedule** -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 

 ### Nested Class in Schedule : RepetitiveInterval 

 -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 union: pattern: every day 
 +     
   repeat quantity: unit: 2 
 +     
   repeat start time: 2015-08-18-00-00-00 
 +     repeat end time: 2015-08-25-00-00-00 

 **Interval** -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. 

 Here is the abstraction of these two classes: 
 ---------------------------------------------- 

     


     class Schedule 
     { 
     public: 
       ///@brief Construct an empty 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 agenda 
       Schedule& 
       addWhiteInterval(TimePoint startTime, 
                        TimePoint endTime, 
                        RepeatUnit Unit = RepetitiveInterval::NONE, 
                        TimePoint repeatStartTime = 0, 
                        TimePoint repeatEndTime = 0, 
                        size_T repeatQuantity = 0); addRepetitiveInterval(RepetitiveInterval repetitiveInterval); 

       ///@brief Delete an repetitive interval agenda 
       ///@throw Error if there's no match RepetitiveInterval 
       Schedule& 
       addBlackInterval(TimePoint startTime, 
                        TimePoint endTime, 
                        RepeatUnit Unit = RepetitiveInterval::NONE, 
                        TimePoint repeatStartTime = 0, 
                        TimePoint repeatEndTime = 0, 
                        size_T repeatQuantity = 0); 

      deleteRepetitiveInterval(RepetitiveInterval repetitiveInterval); 

       ///@brief Get the Interval that cover the ts 
       Interval 
       getCoveringInterval(const 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: 
       public: enum RepeatPattern{ 
         enum RepeatUnit{ 
           NONE = 0, 
           DAY 
         EVERY_DAY = 1, 
           WEEK 
         EVERY_WEEK = 2, 
           MONTH 
         EVERY_MONTH = 3 
         
       } 

       

     public: 
         RepetitiveInterval(); 

         RepetitiveInterval(Block& block); 

         
       ///@brief The construction, once the object is created, it becomes read-only 
       RepetitiveInterval(TimePoint startTime, 
                            
                          TimePoint endTime, 
                            RepeatUnit Unit 
                          RepeatPattern pattern = RepetitiveInterval::NONE, 
                            
                          TimePoint repeatStartTime = 0, 
                            TimePoint repeatEndTime = 0, 
                            
                          size_T repeatQuantity 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 
         isInRepetitiveInterval(TimePoint 
       isInAgenda(TimePoint tp); 

         

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

       ///@brief reload the covering interval 
         Interval 
         getCoveringInterval(); 

       private: 
         TimePoint m_startTime; 
         TimePoint m_endTime; 

         RepeatUnit m_repeatUnit; 
         size_t m_repeatQuantity; 
         TimePoint m_repeatStartTime; 
         TimePoint m_repeatEndTime; 

         Block m_wire; operator 
       }; bool 
       operator==(const RepetitiveInterval& repetitiveInterval) const; 

     private: 
       TimePoint m_startTime; 
       TimePoint m_endTime; 

       RepeatPattern m_repeatPattern; 
       std::list<RepetitiveInterval> m_whiteIntervalList; size_t m_repeatUnit; 
       std::list<RepetitiveInterval> m_blackIntervalList; TimePoint m_repeatEndTime; 

       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; 
     };

Back