Changeset 119
- Timestamp:
- 07/20/10 16:20:13 (14 years ago)
- 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 20 20 virtual int getYearTotalLength(const Date& d) const { return (365 * 86400); } // Retourne la durée d'une année en seconde. 21 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.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 25 virtual int getMinuteLength(void) const { return (60); } // Retourne la durée d'une minute en secondes. 26 26 … … 57 57 AbstractCalendar() : AbstractObject(), initDate(*this), currentDate(initDate) 58 58 {/* 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) 60 66 {/* Ne rien faire de plus */} 61 67 -
XMLIO_V2/dev/dev_rv/src/XMLIO/attribut.hpp
r114 r119 93 93 94 94 #endif //__ATTRIBUT__ 95 96 -
XMLIO_V2/dev/dev_rv/src/XMLIO/c_interface.cpp
r118 r119 3 3 using namespace XMLIOSERVER; 4 4 using namespace XMLIOSERVER::XML; 5 5 6 using namespace std; 6 7 … … 32 33 33 34 string sttr("12/07/2005 - 10:11:30"); 35 string stttr("111s 14.36 mi 7y 3.9y 3.4 mg"); 34 36 Date d3 = Date::FromString(sttr, *calendar); 35 37 … … 38 40 Duration sc1 = Second * 175.3 - Minute * 13109.6 + Hour * 135.1 - Day * 616.4 + Month * 236.0 + Year * 33.9; 39 41 Duration sc2 = 60 * Day; 42 43 Duration sc3 = Duration::FromString(stttr); 40 44 41 45 std::cout << calendar->getInitDate() << std::endl; … … 52 56 53 57 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; 55 61 56 62 delete calendar; 57 63 58 // 64 //On écrit l'arborescence résultante du traitement sur la sortie. 59 65 //Context::ShowTree(std::clog); 60 61 //Calendar::Date date;62 //std::cout << date << std::endl;63 66 64 67 } -
XMLIO_V2/dev/dev_rv/src/XMLIO/calendar.hpp
r118 r119 8 8 public : 9 9 JulianCalendar() : AbstractCalendar("Julian") 10 {/* Ne rien faire de plus */} 11 JulianCalendar(const string& dateStr) : AbstractCalendar("Julian", dateStr) 10 12 {/* Ne rien faire de plus */} 11 13 … … 32 34 public : 33 35 GregorianCalendar() : AbstractCalendar("Gregorian") 36 {/* Ne rien faire de plus */} 37 GregorianCalendar(const string& dateStr) : AbstractCalendar("Gregorian", dateStr) 34 38 {/* Ne rien faire de plus */} 35 39 … … 61 65 NoLeapCalendar() : AbstractCalendar("NoLeap") 62 66 {/* Ne rien faire de plus */} 67 NoLeapCalendar(const string& dateStr) : AbstractCalendar("NoLeap", dateStr) 68 {/* Ne rien faire de plus */} 69 63 70 virtual ~NoLeapCalendar() 64 71 {/* Ne rien faire de plus */} … … 70 77 public : 71 78 AllLeapCalendar() : AbstractCalendar("AllLeap") 79 {/* Ne rien faire de plus */} 80 AllLeapCalendar(const string& dateStr) : AbstractCalendar("AllLeap", dateStr) 72 81 {/* Ne rien faire de plus */} 73 82 … … 87 96 D360Calendar() : AbstractCalendar("D360") 88 97 {/* Ne rien faire de plus */} 98 D360Calendar(const string& dateStr) : AbstractCalendar("D360", dateStr) 99 {/* Ne rien faire de plus */} 89 100 90 101 virtual int getYearTotalLength(const Date& d) const { return (360 * 86400); } -
XMLIO_V2/dev/dev_rv/src/XMLIO/calendar_utils.hpp
r118 r119 4 4 namespace XMLIOSERVER 5 5 { 6 7 6 Date Date::FromString(const string& str, const AbstractCalendar& cal) 8 7 { 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 } 9 40 10 41 Duration& Duration::resolve(const AbstractCalendar& c) -
XMLIO_V2/dev/dev_rv/src/XMLIO/context.hpp
r115 r119 9 9 public: 10 10 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) 12 13 {/* 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) 14 17 {/* Ne rien faire de plus */} 15 18 … … 92 95 { WARNING("Le noeud de définition possÚde un identifiant, ce dernier ne sera pas pris en compte lors du traitement !"); } 93 96 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. 95 98 { fieldDef = CreateInstanceAndParse<FieldDefinition>(_node, FieldDefinition::GetDefName().c_str()); continue; } 96 99 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. 98 101 { fileDef = CreateInstanceAndParse<FileDefinition >(_node, FileDefinition ::GetDefName().c_str()); continue; } 99 102 … … 136 139 } 137 140 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 } 142 164 143 165 ~Context() 144 166 { 167 // Désallocation dynamique de mémoire pour chacun des groupes de définition si nécessaire. 145 168 if(fieldDef != NULL) delete fieldDef; 146 169 if(fileDef != NULL) delete fileDef; 147 170 if(axisDef != NULL) delete axisDef; 148 171 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; 149 174 } 150 175 176 private: 151 177 152 private:178 AbstractCalendar* ccalendar; 153 179 154 180 FieldDefinition* fieldDef; … … 157 183 GridDefinition* gridDef; 158 184 159 160 185 }; //class Context 161 186 }// namespace XMLIOSERVER -
XMLIO_V2/dev/dev_rv/src/XMLIO/date.hpp
r118 r119 8 8 public : 9 9 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) 11 11 , 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 } 13 16 14 17 Date(const Date& d) : relCalendar(d.relCalendar) 15 18 , 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 } 17 23 18 24 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. 19 26 20 27 friend std::ostream& operator<<(std::ostream& out, const Date& d) … … 30 37 in >> d.day >> c >> d.month >> c >> d.year >> c; 31 38 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é."); 32 41 return (in); 33 42 } -
XMLIO_V2/dev/dev_rv/src/XMLIO/duration.hpp
r118 r119 10 10 typedef struct _duration 11 11 { 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 : 18 13 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 } 20 25 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; 22 69 23 70 } Duration; … … 26 73 static const Duration Year = {1.0, 0.0, 0.0, 0.0, 0.0, 0.0}, 27 74 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}, 28 76 Day = {0.0, 0.0, 1.0, 0.0, 0.0, 0.0}, 29 77 Hour = {0.0, 0.0, 0.0, 1.0, 0.0, 0.0},
Note: See TracChangeset
for help on using the changeset viewer.