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

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