clock.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2020 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  //- Returns wall-clock time from clock instantiation
95  time_t elapsedClockTime() const;
96 
97  //- Returns wall-clock time from last call of clockTimeIncrement()
98  time_t clockTimeIncrement() const;
99 };
100 
101 
102 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
103 
104 } // End namespace Foam
105 
106 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
107 
108 #endif
109 
110 // ************************************************************************* //
Read access to the system clock with formatting.
Definition: clock.H:51
time_t elapsedClockTime() const
Returns wall-clock time from clock instantiation.
Definition: clock.C:122
static time_t getTime()
Get the current clock time in seconds.
Definition: clock.C:43
static string dateTime()
Return the current wall-clock date/time as a string.
Definition: clock.C:57
static string clockTime()
Return the current wall-clock time as a string.
Definition: clock.C:93
static string date()
Return the current wall-clock date as a string.
Definition: clock.C:77
static const struct tm rawDate()
Return the current wall-clock date as a raw struct.
Definition: clock.C:49
time_t clockTimeIncrement() const
Returns wall-clock time from last call of clockTimeIncrement()
Definition: clock.C:129
clock()
Null constructor which stores the start time.
Definition: clock.C:112
Namespace for OpenFOAM.