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

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

Mise à jour intermédiaire ...
A venir : commit d'une version stable intégrant l'écriture de fichiers NetCDF4.
(en cours de finalisation actuellement)

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