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

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

Début de gestion des opérations sur les champs + quelques modifications

File size: 3.3 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         virtual int getYearTotalLength(const Date& d) const { return (365 * 86400); } // Retourne la durée d'une année en seconde.
24
25         virtual int getYearLength  (void) const { return (12); } // Retourne la durée d'une année en mois.
26         virtual int getDayLength   (void) const { return (24); } // Retourne la durée d'un jour en heures.
27         virtual int getHourLength  (void) const { return (60); } // Retourne la durée d'une heure en minute.
28         virtual int getMinuteLength(void) const { return (60); } // Retourne la durée d'une minute en secondes.
29
30         virtual int getNbSecond(const Date& d) const
31         { // Retourne le nombre de secondes écoulées depuis le début de l'année.
32            Date _d0(d); int  nbday = 0;
33
34            for(_d0.setMonth(1); _d0.getMonth() < d.getMonth(); _d0.setMonth(_d0.getMonth()+1))
35               nbday += getMonthLength(_d0);
36            return ((((nbday + d.getDay()) * getDayLength() + d.getHour())
37                     * getHourLength() + d.getMinute()) * getMinuteLength() + d.getSecond());
38         }
39
40         virtual string getMonthName(int _mi) const
41         {
42            static const string Monthname_str[] =
43               { "january", "february", "march"    , "april"  , "may"     , "june"    ,
44                 "july"   , "august"  , "september", "october", "november", "december" };
45            return(Monthname_str[_mi-1]);
46         }
47
48         virtual const string getMonthShortName(int _mi) const
49         { string value = getMonthName(_mi); value.resize(3); return (value); }
50
51         const Date& getInitDate(void) const { return(initDate); }
52         Date& getCurrentDate(void) { return(currentDate); }
53
54         virtual ~AbstractCalendar()
55         {/* Ne rien faire de plus */}
56
57      protected :
58
59         AbstractCalendar() : AbstractObject(), initDate(*this), currentDate(initDate)
60         {/* Ne rien faire de plus */}
61
62         AbstractCalendar(const string& _id, int yr = 0, int mth = 1, int d = 1, int hr = 0, int min = 0 , int sec = 0)
63            : AbstractObject(_id), initDate(*this, yr, mth, d, hr, min, sec), currentDate(initDate)
64         {/* Ne rien faire de plus */}
65
66         AbstractCalendar(const string& _id, const string& dateStr)
67            : AbstractObject(_id), initDate(Date::FromString(dateStr, *this)), currentDate(initDate)
68         {/* Ne rien faire de plus */}
69
70      private :
71
72         const Date initDate;
73         Date currentDate;
74
75   }; // class AbstractCalendar
76
77} // namespace XMLIOSERVER
78
79#endif // __XMLIO_ABSTRACT_CALENDAR__
Note: See TracBrowser for help on using the repository browser.