Code_TYMPAN  4.4.0
Industrial site acoustic simulation
chrono.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012-2024> <EDF-DTG> <FRANCE>
3  * This file is part of Code_TYMPAN (R).
4  * Code_TYMPAN (R) is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * Code_TYMPAN (R) is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  * You should have received a copy of the GNU General Public License along
13  * with Code_TYMPAN (R). If not, see <https://www.gnu.org/licenses/>.
14  */
15 
16 /*
17  *
18  *
19  *
20  *
21  */
22 
23 #ifndef __O_CHRONO__
24 #define __O_CHRONO__
25 
26 #include "Tympan/core/defines.h"
27 
28 #if TY_PLATFORM == TY_PLATFORM_WIN32 || TY_PLATFORM == TY_PLATFORM_WIN64
29  #include <windows.h>
30 
36 {
37 public:
39  {
40  _time = ::timeGetTime();
41  }
42  unsigned long getTime() const
43  {
44  return _time;
45  }
49  OChronoTime operator+(const OChronoTime& other) const
50  {
51  return OChronoTime(getTime() + other.getTime());
52  }
56  OChronoTime operator-(const OChronoTime& other) const
57  {
58  return OChronoTime(getTime() - other.getTime());
59  }
60 
61 private:
62  OChronoTime(unsigned long time)
63  {
64  _time = time;
65  }
66 
67  unsigned long _time;
68 };
69 
70 #else
71 
72  #include <sys/timeb.h>
73 
78 class OChronoTime
79 {
80 public:
81  OChronoTime()
82  {
83 
84  struct timeb time_b;
85  ftime(&time_b);
86 
87  _time = time_b.time * 1000; // TODO: this is not the good way to get time because overflow is possible
88  _time += time_b.millitm;
89  }
90  unsigned long getTime() const
91  {
92  return _time;
93  }
97  OChronoTime operator+(const OChronoTime& other) const
98  {
99  return OChronoTime(getTime() + other.getTime());
100  }
104  OChronoTime operator-(const OChronoTime& other) const
105  {
106  return OChronoTime(getTime() - other.getTime());
107  }
108 
109 private:
110  OChronoTime(unsigned long time)
111  {
112  _time = time;
113  }
114 
115  unsigned long _time;
116 };
117 
118 #endif
119 
120 #endif // __O_CHRONO__
OChronoTime(unsigned long time)
Definition: chrono.h:62
OChronoTime()
Definition: chrono.h:38
OChronoTime operator+(const OChronoTime &other) const
Definition: chrono.h:49
unsigned long getTime() const
Definition: chrono.h:42
OChronoTime operator-(const OChronoTime &other) const
Definition: chrono.h:56
unsigned long _time
Definition: chrono.h:67