clock.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::clock
26 
27 Description
28  Read access to the system clock with formatting.
29 
30 SourceFiles
31  clock.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef clock_H
36 #define clock_H
37 
38 #include <ctime>
39 
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 
42 namespace Foam
43 {
44 
45 class string;
46 
47 /*---------------------------------------------------------------------------*\
48  Class clock Declaration
49 \*---------------------------------------------------------------------------*/
50 
51 class clock
52 {
53  // Private data
54 
55  //- Start time in seconds
56  time_t startTime_;
57 
58  //- Time when clockTimeIncrement() was last called
59  mutable time_t lastTime_;
60 
61  //- Latest time from either elapsedClockTime() or clockTimeIncrement()
62  mutable time_t newTime_;
63 
64  //- Names of the months
65  static const char *monthNames[];
66 
67 
68 public:
69 
70  // Constructors
71 
72  //- Null constructor which stores the start time
73  clock();
74 
75 
76  // Member Functions
77 
78  //- Get the current clock time in seconds
79  static time_t getTime();
80 
81  //- Return the current wall-clock date as a raw struct
82  static const struct tm rawDate();
83 
84  //- Return the current wall-clock date/time as a string
85  // format according to ISO-8601 (yyyy-mm-ddThh:mm:ss)
86  static string dateTime();
87 
88  //- Return the current wall-clock date as a string
89  static string date();
90 
91  //- Return the current wall-clock time as a string
92  static string clockTime();
93 
94 #ifdef MSWIN
95  // Satisfy assumptions elsewhere e.g., streams
96  typedef long TIME_T;
97 #else
98  typedef time_t TIME_T;
99 #endif
100 
101  //- Returns wall-clock time from clock instantiation
102  TIME_T elapsedClockTime() const;
103 
104  //- Returns wall-clock time from last call of clockTimeIncrement()
105  TIME_T clockTimeIncrement() const;
106 };
107 
108 
109 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
110 
111 } // End namespace Foam
112 
113 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
114 
115 #endif
116 
117 // ************************************************************************* //
Foam::clock::clockTimeIncrement
TIME_T clockTimeIncrement() const
Returns wall-clock time from last call of clockTimeIncrement()
Definition: clock.C:129
Foam::clock::clock
clock()
Null constructor which stores the start time.
Definition: clock.C:112
Foam::clock::lastTime_
time_t lastTime_
Time when clockTimeIncrement() was last called.
Definition: clock.H:58
Foam::clock::startTime_
time_t startTime_
Start time in seconds.
Definition: clock.H:55
Foam::clock::date
static string date()
Return the current wall-clock date as a string.
Definition: clock.C:77
Foam::clock::clockTime
static string clockTime()
Return the current wall-clock time as a string.
Definition: clock.C:93
Foam::clock::getTime
static time_t getTime()
Get the current clock time in seconds.
Definition: clock.C:43
Foam::clock::TIME_T
time_t TIME_T
Definition: clock.H:97
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::clock
Read access to the system clock with formatting.
Definition: clock.H:50
Foam::clock::monthNames
static const char * monthNames[]
Names of the months.
Definition: clock.H:64
Foam::clock::dateTime
static string dateTime()
Return the current wall-clock date/time as a string.
Definition: clock.C:57
Foam::clock::newTime_
time_t newTime_
Latest time from either elapsedClockTime() or clockTimeIncrement()
Definition: clock.H:61
Foam::clock::elapsedClockTime
TIME_T elapsedClockTime() const
Returns wall-clock time from clock instantiation.
Definition: clock.C:122
Foam::clock::rawDate
static const struct tm rawDate()
Return the current wall-clock date as a raw struct.
Definition: clock.C:49