Changeset 119 for XMLIO_V2/dev/dev_rv


Ignore:
Timestamp:
07/20/10 16:20:13 (14 years ago)
Author:
hozdoba
Message:

Quelques modifications supplémentaires apportées aux dates et calendriers.

Location:
XMLIO_V2/dev/dev_rv/src/XMLIO
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • XMLIO_V2/dev/dev_rv/src/XMLIO/abstract_calendar.hpp

    r118 r119  
    2020         virtual int getYearTotalLength(const Date& d) const { return (365 * 86400); } // Retourne la durée d'une année en seconde. 
    2121 
    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. 
     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. 
    2525         virtual int getMinuteLength(void) const { return (60); } // Retourne la durée d'une minute en secondes. 
    2626 
     
    5757         AbstractCalendar() : AbstractObject(), initDate(*this), currentDate(initDate) 
    5858         {/* Ne rien faire de plus */} 
    59          AbstractCalendar(const string& _id) : AbstractObject(_id), initDate(*this), currentDate(initDate) 
     59 
     60         AbstractCalendar(const string& _id, int yr = 0, int mth = 1, int d = 1, int hr = 0, int min = 0 , int sec = 0) 
     61            : AbstractObject(_id), initDate(*this, yr, mth, d, hr, min, sec), currentDate(initDate) 
     62         {/* Ne rien faire de plus */} 
     63 
     64         AbstractCalendar(const string& _id, const string& dateStr) 
     65            : AbstractObject(_id), initDate(Date::FromString(dateStr, *this)), currentDate(initDate) 
    6066         {/* Ne rien faire de plus */} 
    6167 
  • XMLIO_V2/dev/dev_rv/src/XMLIO/attribut.hpp

    r114 r119  
    9393 
    9494#endif //__ATTRIBUT__ 
     95 
     96 
  • XMLIO_V2/dev/dev_rv/src/XMLIO/c_interface.cpp

    r118 r119  
    33using namespace XMLIOSERVER; 
    44using namespace XMLIOSERVER::XML; 
     5 
    56using namespace std; 
    67 
     
    3233 
    3334      string sttr("12/07/2005 - 10:11:30"); 
     35      string stttr("111s 14.36 mi 7y 3.9y 3.4 mg"); 
    3436      Date d3 = Date::FromString(sttr, *calendar); 
    3537 
     
    3840      Duration sc1 = Second * 175.3 - Minute * 13109.6 + Hour * 135.1 - Day * 616.4 + Month * 236.0 + Year * 33.9; 
    3941      Duration sc2 = 60 * Day; 
     42 
     43      Duration sc3 = Duration::FromString(stttr); 
    4044 
    4145      std::cout << calendar->getInitDate()    << std::endl; 
     
    5256 
    5357      std::cout << (dd+sc2) << std::endl; 
    54       std::cout << (d3) << std::endl; 
     58      std::cout << (d3)  << std::endl; 
     59 
     60      std::cout << (sc3) << std::endl; 
    5561 
    5662      delete calendar; 
    5763 
    58       // On écrit l'arborescence résultante du traitement sur la sortie. 
     64      //On écrit l'arborescence résultante du traitement sur la sortie. 
    5965      //Context::ShowTree(std::clog); 
    60  
    61       //Calendar::Date date; 
    62       //std::cout << date << std::endl; 
    6366 
    6467   } 
  • XMLIO_V2/dev/dev_rv/src/XMLIO/calendar.hpp

    r118 r119  
    88      public : 
    99         JulianCalendar() : AbstractCalendar("Julian") 
     10         {/* Ne rien faire de plus */} 
     11         JulianCalendar(const string& dateStr) : AbstractCalendar("Julian", dateStr) 
    1012         {/* Ne rien faire de plus */} 
    1113 
     
    3234      public : 
    3335         GregorianCalendar() : AbstractCalendar("Gregorian") 
     36         {/* Ne rien faire de plus */} 
     37         GregorianCalendar(const string& dateStr) : AbstractCalendar("Gregorian", dateStr) 
    3438         {/* Ne rien faire de plus */} 
    3539 
     
    6165         NoLeapCalendar() : AbstractCalendar("NoLeap") 
    6266         {/* Ne rien faire de plus */} 
     67         NoLeapCalendar(const string& dateStr) : AbstractCalendar("NoLeap", dateStr) 
     68         {/* Ne rien faire de plus */} 
     69 
    6370         virtual ~NoLeapCalendar() 
    6471         {/* Ne rien faire de plus */} 
     
    7077      public : 
    7178         AllLeapCalendar() : AbstractCalendar("AllLeap") 
     79         {/* Ne rien faire de plus */} 
     80         AllLeapCalendar(const string& dateStr) : AbstractCalendar("AllLeap", dateStr) 
    7281         {/* Ne rien faire de plus */} 
    7382 
     
    8796         D360Calendar() : AbstractCalendar("D360") 
    8897         {/* Ne rien faire de plus */} 
     98         D360Calendar(const string& dateStr) : AbstractCalendar("D360", dateStr) 
     99         {/* Ne rien faire de plus */} 
    89100 
    90101         virtual int getYearTotalLength(const Date& d) const { return (360 * 86400); } 
  • XMLIO_V2/dev/dev_rv/src/XMLIO/calendar_utils.hpp

    r118 r119  
    44namespace XMLIOSERVER 
    55{ 
    6  
    76   Date Date::FromString(const string& str, const AbstractCalendar& cal) 
    87   { Date dt(cal); std::istringstream iss(str); iss >> dt; return dt; } 
     8 
     9   bool Date::checkDate(void) 
     10   { 
     11      bool retValue = true; 
     12 
     13      // Vérificatio de la valeur du mois. 
     14      if (month  < 1) { retValue = false; month  = 1; } 
     15      if (month  > relCalendar.getYearLength()) 
     16      { retValue = false; month = relCalendar.getYearLength(); } 
     17 
     18      // Vérification de la valeur du jour. 
     19      if (day    < 1) { retValue = false; month  = 1; } 
     20      if (day    > relCalendar.getMonthLength(*this)) 
     21      { retValue = false; day = relCalendar.getMonthLength(*this); } 
     22 
     23      // Vérification de la valeur de l'heure. 
     24      if (hour   < 0) { retValue = false; hour  = 0; } 
     25      if (hour   >= relCalendar.getDayLength()) 
     26      { retValue = false; hour = relCalendar.getDayLength()-1; } 
     27 
     28      // Vérification de la valeur des minutes. 
     29      if (minute < 0) { retValue = false; minute = 0; } 
     30      if (minute >= relCalendar.getHourLength()) 
     31      { retValue = false; minute = relCalendar.getHourLength()-1; } 
     32 
     33      // Vérification de la valeur des secondes. 
     34      if (second < 0) { retValue = false; month  = 0; } 
     35      if (second >= relCalendar.getMinuteLength()) 
     36      { retValue = false; second = relCalendar.getMinuteLength()-1; } 
     37 
     38      return retValue; 
     39   } 
    940 
    1041   Duration& Duration::resolve(const AbstractCalendar& c) 
  • XMLIO_V2/dev/dev_rv/src/XMLIO/context.hpp

    r115 r119  
    99      public: 
    1010 
    11          Context(void) : ObjectTemplate<Context>(), fieldDef(NULL), fileDef(NULL), axisDef(NULL), gridDef(NULL) 
     11         Context(void) : ObjectTemplate<Context>(), ccalendar(NULL), 
     12            fieldDef(NULL), fileDef(NULL), axisDef(NULL), gridDef(NULL) 
    1213         {/* Ne rien faire de plus */} 
    13          Context(const string& _id) : ObjectTemplate<Context>(_id), fieldDef(NULL), fileDef(NULL), axisDef(NULL), gridDef(NULL) 
     14 
     15         Context(const string& _id) : ObjectTemplate<Context>(_id), ccalendar(NULL), 
     16            fieldDef(NULL), fileDef(NULL), axisDef(NULL), gridDef(NULL) 
    1417         {/* Ne rien faire de plus */} 
    1518 
     
    9295                  { WARNING("Le noeud de définition possÚde un identifiant, ce dernier ne sera pas pris en compte lors du traitement !"); } 
    9396 
    94                   if (name.compare(FieldDefinition::GetDefName()) == 0) // Parsing définition des champs. 
     97                  if (name.compare(FieldDefinition::GetDefName()) == 0) // Parsing pour la définition des champs. 
    9598                  { fieldDef = CreateInstanceAndParse<FieldDefinition>(_node, FieldDefinition::GetDefName().c_str()); continue; } 
    9699 
    97                   if (name.compare(FileDefinition::GetDefName()) == 0) // Parsing définition des fichiers. 
     100                  if (name.compare(FileDefinition::GetDefName()) == 0) // Parsing pour la définition des fichiers. 
    98101                  { fileDef  = CreateInstanceAndParse<FileDefinition >(_node, FileDefinition ::GetDefName().c_str()); continue; } 
    99102 
     
    136139         } 
    137140 
    138          FieldDefinition* getFieldDefinition(void) { return (this->fieldDef); } 
    139          FileDefinition * getFileDefinition(void)  { return (this->fileDef ); } 
    140          AxisDefinition * getAxisDefinition(void)  { return (this->axisDef ); } 
    141          GridDefinition * getGridDefinition(void)  { return (this->gridDef ); } 
     141         FieldDefinition* getFieldDefinition(void) const { return (this->fieldDef); } 
     142         FileDefinition * getFileDefinition(void)  const { return (this->fileDef ); } 
     143         AxisDefinition * getAxisDefinition(void)  const { return (this->axisDef ); } 
     144         GridDefinition * getGridDefinition(void)  const { return (this->gridDef ); } 
     145 
     146         AbstractCalendar * getCalendar(void) const { return (this->ccalendar ); } 
     147         AbstractCalendar * setCalendar(const string& _calName, const string& dateStr) 
     148         { 
     149            if (_calName.compare("D360")      == 0) 
     150               return (ccalendar = new D360Calendar(dateStr)); 
     151            if (_calName.compare("AllLeap")   == 0) 
     152               return (ccalendar = new AllLeapCalendar(dateStr)); 
     153            if (_calName.compare("NoLeap")    == 0) 
     154               return (ccalendar = new NoLeapCalendar(dateStr)); 
     155            if (_calName.compare("Julian")    == 0) 
     156               return (ccalendar = new JulianCalendar(dateStr)); 
     157            if (_calName.compare("Gregorian") == 0) 
     158               return (ccalendar = new GregorianCalendar(dateStr)); 
     159 
     160            WARNING("L'identifiant "+_calName+" est inconnu, le calendrier grégorien sera choisi par défault pour le contexte "+getId()); 
     161 
     162            return (ccalendar = new GregorianCalendar(dateStr)); 
     163         } 
    142164 
    143165         ~Context() 
    144166         { 
     167            // Désallocation dynamique de mémoire pour chacun des groupes de définition si nécessaire. 
    145168            if(fieldDef != NULL) delete fieldDef; 
    146169            if(fileDef  != NULL) delete fileDef; 
    147170            if(axisDef  != NULL) delete axisDef; 
    148171            if(gridDef  != NULL) delete gridDef; 
     172            // Désallocation dynamique de mémoire pour le calendrier associé au contexte courant si nécessaire. 
     173            if(ccalendar !=  NULL) delete ccalendar; 
    149174         } 
    150175 
     176      private: 
    151177 
    152       private: 
     178         AbstractCalendar* ccalendar; 
    153179 
    154180         FieldDefinition*  fieldDef; 
     
    157183         GridDefinition*   gridDef; 
    158184 
    159  
    160185   }; //class Context 
    161186}// namespace XMLIOSERVER 
  • XMLIO_V2/dev/dev_rv/src/XMLIO/date.hpp

    r118 r119  
    88      public : 
    99 
    10          Date(const AbstractCalendar& cal, int yr = 0, int mth = 0, int d = 0, int hr = 0, int min = 0 , int sec = 0) : relCalendar(cal) 
     10         Date(const AbstractCalendar& cal, int yr = 0, int mth = 1, int d = 1, int hr = 0, int min = 0 , int sec = 0) : relCalendar(cal) 
    1111            , year(yr), month(mth), day(d), hour(hr), minute(min), second(sec) 
    12          {/* Ne rien faire de plus */} 
     12         { 
     13            if(!checkDate()) 
     14               WARNING("La date initialisée a été modifiée car elle était incorrecte par rapport au calendrier souhaité."); 
     15         } 
    1316 
    1417         Date(const Date& d) : relCalendar(d.relCalendar) 
    1518            , year(d.year), month(d.month), day(d.day), hour(d.hour), minute(d.minute), second(d.second) 
    16          {/* Ne rien faire de plus */} 
     19         { 
     20            if(!checkDate()) 
     21               WARNING("La date initialisée a été modifiée car elle était incorrecte par rapport au calendrier souhaité."); 
     22         } 
    1723 
    1824         operator Time(void); // Retourne le nombre de secondes écoulées depuis la date initiale définie dans le calendrier. 
     25         bool checkDate(void); // Vérifie la validité de la date. 
    1926 
    2027         friend std::ostream& operator<<(std::ostream& out, const Date& d) 
     
    3037            in >> d.day  >> c >> d.month  >> c >> d.year   >> c; 
    3138            in >> d.hour >> c >> d.minute >> c >> d.second; 
     39            if(!d.checkDate()) 
     40               WARNING("La date initialisée (depuis une chaîne de caractÚres) a été modifiée car elle était incorrecte par rapport au calendrier souhaité."); 
    3241            return (in); 
    3342         } 
  • XMLIO_V2/dev/dev_rv/src/XMLIO/duration.hpp

    r118 r119  
    1010   typedef struct _duration 
    1111   { 
    12       friend std::ostream& operator<<(std::ostream& out, const struct _duration& d) 
    13       { 
    14          out << d.year  << "y. " << d.month  << "mo. "   <<  d.day   << "d. " 
    15              << d.hour  << "h. " << d.minute << "min. " << d.second << "sec. "; 
    16          return (out); 
    17       } 
     12      public : 
    1813 
    19       struct _duration& resolve(const AbstractCalendar&); 
     14         friend std::ostream& operator<<(std::ostream& out, const struct _duration& d) 
     15         { 
     16            bool testValue = true; 
     17            if(d.year   != 0.0) { testValue = false; out << d.year   << "y " ; } 
     18            if(d.month  != 0.0) { testValue = false; out << d.month  << "mo "; } 
     19            if(d.day    != 0.0) { testValue = false; out << d.day    << "d " ; } 
     20            if(d.hour   != 0.0) { testValue = false; out << d.hour   << "h " ; } 
     21            if(d.minute != 0.0) { testValue = false; out << d.minute << "mi "; } 
     22            if(d.second != 0.0 || testValue) { out << d.second << "s " ; } 
     23            return (out); 
     24         } 
    2025 
    21       double year, month, day, hour, minute, second; 
     26         friend std::istream& operator>>(std::istream& in, struct _duration& d) 
     27         { 
     28            double v = 1.0; 
     29            char   c = '/'; 
     30            while (!in.eof()) 
     31            { 
     32               in >> v >> c; 
     33               switch (c) 
     34               { 
     35                  case 'y': d.year   = v; continue; 
     36                  case 'd': d.day    = v; continue; 
     37                  case 'h': d.hour   = v; continue; 
     38                  case 's': d.second = v; continue; 
     39                  case 'm': 
     40                     in >> c; 
     41                     if (c == 'i') d.minute   = v; 
     42                     else if(c == 'o') d.month   = v; 
     43                     else 
     44                     { 
     45                        string valc("m"); valc.append(1, c); 
     46                        WARNING("La chaine \""+valc+"\" ne permet pas de définir une unité de durée."); 
     47                        continue; 
     48                     } 
     49                     continue; 
     50                  default: 
     51                     string valc; valc.append(1, c); 
     52                     WARNING("La chaine \""+valc+"\" ne permet pas de définir une unité de durée."); 
     53                     continue; 
     54               } 
     55            } 
     56            return (in); 
     57         } 
     58 
     59         static struct _duration FromString(const string& str) 
     60         { 
     61            struct _duration dr = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; 
     62            std::istringstream iss(str); 
     63            iss >> dr; return dr; 
     64         } 
     65 
     66         struct _duration& resolve(const AbstractCalendar&); 
     67 
     68         double year, month, day, hour, minute, second; 
    2269 
    2370   } Duration; 
     
    2673   static const Duration Year   = {1.0, 0.0, 0.0, 0.0, 0.0, 0.0}, 
    2774                         Month  = {0.0, 1.0, 0.0, 0.0, 0.0, 0.0}, 
     75                         Week   = {0.0, 0.0, 7.0, 0.0, 0.0, 0.0}, 
    2876                         Day    = {0.0, 0.0, 1.0, 0.0, 0.0, 0.0}, 
    2977                         Hour   = {0.0, 0.0, 0.0, 1.0, 0.0, 0.0}, 
Note: See TracChangeset for help on using the changeset viewer.