source: XMLIO_V2/dev/dev_rv/src/XMLIO/duration.hpp @ 123

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

Début de gestion des opérations sur les champs + quelques modifications

File size: 3.1 KB
Line 
1#ifndef __XMLIO_DURATION__
2#define __XMLIO_DURATION__
3
4namespace XMLIOSERVER
5{
6   class AbstractCalendar;
7
8   typedef long long int Time;
9
10   typedef struct _duration
11   {
12      public :
13
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         }
25
26         friend std::istream& operator>>(std::istream& in, struct _duration& d)
27         {
28            d.year = d.month = d.day = d.hour = d.minute = d.second = 0.0;
29            double v = 1.0;
30            char   c = '/';
31            while (!in.eof())
32            {
33               in >> v >> c;
34               switch (c)
35               {
36                  case 'y': d.year   = v; continue;
37                  case 'd': d.day    = v; continue;
38                  case 'h': d.hour   = v; continue;
39                  case 's': d.second = v; continue;
40                  case 'm':
41                     in >> c;
42                     if (c == 'i') d.minute   = v;
43                     else if(c == 'o') d.month   = v;
44                     else
45                     {
46                        string valc("m"); valc.append(1, c);
47                        WARNING("La chaine \""+valc+"\" ne permet pas de définir une unité de durée.");
48                        continue;
49                     }
50                     continue;
51                  default:
52                     string valc; valc.append(1, c);
53                     WARNING("La chaine \""+valc+"\" ne permet pas de définir une unité de durée.");
54                     continue;
55               }
56            }
57            return (in);
58         }
59
60         static struct _duration FromString(const string& str)
61         {
62            struct _duration dr = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
63            std::istringstream iss(str);
64            iss >> dr; return dr;
65         }
66
67         struct _duration& resolve(const AbstractCalendar&);
68
69         double year, month, day, hour, minute, second;
70
71   } Duration;
72
73   // Les principales durées constantes : année, mois, jour, ...
74   static const Duration Year   = {1.0, 0.0, 0.0, 0.0, 0.0, 0.0},
75                         Month  = {0.0, 1.0, 0.0, 0.0, 0.0, 0.0},
76                         Week   = {0.0, 0.0, 7.0, 0.0, 0.0, 0.0},
77                         Day    = {0.0, 0.0, 1.0, 0.0, 0.0, 0.0},
78                         Hour   = {0.0, 0.0, 0.0, 1.0, 0.0, 0.0},
79                         Minute = {0.0, 0.0, 0.0, 0.0, 1.0, 0.0},
80                         Second = {0.0, 0.0, 0.0, 0.0, 0.0, 1.0},
81                         NoneDu = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
82
83} // namespace XMLIOSERVER
84
85#endif // __XMLIO_DURATION__
Note: See TracBrowser for help on using the repository browser.