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

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

suite du précédent commit

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