source: XMLIO_V2/dev/dev_rv/src/XMLIO/abstract_calendar.hpp @ 124

Last change on this file since 124 was 124, checked in by hozdoba, 14 years ago

Commit pour sauvegarde - diverses corrections de bogues et améliorations du code.

File size: 3.5 KB
Line 
1#ifndef __XMLIO_ABSTRACT_CALENDAR__
2#define __XMLIO_ABSTRACT_CALENDAR__
3
4namespace XMLIOSERVER
5{
6   typedef enum _monthEnum
7   {  JAN = 1, FEB = 2, MAR = 3, APR = 4 , MAY = 5 , JUN = 6 ,
8      JUL = 7, AUG = 8, SEP = 9, OCT = 10, NOV = 11, DEC = 12  } MonthEnum;
9
10   class AbstractCalendar : public AbstractObject
11   {
12      public :
13
14         virtual int getMonthLength(const Date& d) const
15         { // Retourne la durée du mois en jour.
16            static const int NoLeapMonthLength[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
17            return (NoLeapMonthLength[d.getMonth()-1]);
18         }
19
20         friend std::ostream& operator<<(std::ostream& out, AbstractCalendar& c)
21         { out << "[type: " << c.getId() << ", start: " << c.getInitDate() << ", current: " << c.getCurrentDate() << "]"; return (out); }
22
23         const Date& getInitDate(void) const { return(initDate); }
24         Date& getCurrentDate(void) { return(currentDate); }
25
26         void setTempo(const Duration& dr) { tempo = dr; }
27         Duration getTempo(void) const { return (tempo); }
28
29         Date& update(void);
30
31         virtual int getYearTotalLength(const Date& d) const { return (365 * 86400); } // Retourne la durée d'une année en seconde.
32
33         virtual int getYearLength  (void) const { return (12); } // Retourne la durée d'une année en mois.
34         virtual int getDayLength   (void) const { return (24); } // Retourne la durée d'un jour en heures.
35         virtual int getHourLength  (void) const { return (60); } // Retourne la durée d'une heure en minute.
36         virtual int getMinuteLength(void) const { return (60); } // Retourne la durée d'une minute en secondes.
37
38         virtual int getNbSecond(const Date& d) const
39         { // Retourne le nombre de secondes écoulées depuis le début de l'année.
40            Date _d0(d); int  nbday = 0;
41
42            for(_d0.setMonth(1); _d0.getMonth() < d.getMonth(); _d0.setMonth(_d0.getMonth()+1))
43               nbday += getMonthLength(_d0);
44            return ((((nbday + d.getDay()) * getDayLength() + d.getHour())
45                     * getHourLength() + d.getMinute()) * getMinuteLength() + d.getSecond());
46         }
47
48         virtual string getMonthName(int _mi) const
49         {
50            static const string Monthname_str[] =
51               { "january", "february", "march"    , "april"  , "may"     , "june"    ,
52                 "july"   , "august"  , "september", "october", "november", "december" };
53            return(Monthname_str[_mi-1]);
54         }
55
56         virtual const string getMonthShortName(int _mi) const
57         { string value = getMonthName(_mi); value.resize(3); return (value); }
58
59         virtual ~AbstractCalendar()
60         {/* Ne rien faire de plus */}
61
62      protected :
63
64         AbstractCalendar()
65            : AbstractObject(), initDate(*this), currentDate(initDate), tempo(Hour)
66         {/* Ne rien faire de plus */}
67
68         AbstractCalendar(const string& _id, int yr = 0, int mth = 1, int d = 1, int hr = 0, int min = 0 , int sec = 0)
69            : AbstractObject(_id), initDate(*this, yr, mth, d, hr, min, sec), currentDate(initDate), tempo(Hour)
70         {/* Ne rien faire de plus */}
71
72         AbstractCalendar(const string& _id, const string& dateStr)
73            : AbstractObject(_id), initDate(Date::FromString(dateStr, *this)), currentDate(initDate), tempo(Hour)
74         {/* Ne rien faire de plus */}
75
76      private :
77
78         const Date initDate;
79         Date currentDate;
80         Duration tempo;
81
82   }; // class AbstractCalendar
83
84} // namespace XMLIOSERVER
85
86#endif // __XMLIO_ABSTRACT_CALENDAR__
Note: See TracBrowser for help on using the repository browser.