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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011 OpenFOAM Foundation
9  Copyright (C) 2018-2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::clock
29 
30 Description
31  Read access to the system clock with formatting.
32 
33 SourceFiles
34  clock.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef clock_H
39 #define clock_H
40 
41 #include <ctime>
42 #include <string>
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 /*---------------------------------------------------------------------------*\
50  Class clock Declaration
51 \*---------------------------------------------------------------------------*/
52 
53 class clock
54 {
55  // Private Data
56 
57  //- Time point at start (in seconds)
58  time_t start_;
59 
60  //- Last time when elapsedClockTime or clockTimeIncrement was called
61  mutable time_t last_;
62 
63 
64 public:
65 
66  // Constructors
67 
68  //- Construct with the current clock time for the start point
69  clock();
70 
71 
72  // Low-level Member Functions
73 
74  //- Get the current clock time in seconds
75  static time_t getTime();
76 
77  //- The current wall-clock date as a raw struct
78  // \deprecated(2020-05) may be removed in future versions
79  static const struct tm rawDate();
80 
81 
82  // Static Member Functions
83 
84  //- The current wall-clock date/time (in local time) as a string
85  //- in ISO-8601 format (yyyy-mm-ddThh:mm:ss).
86  // Without time-zone information.
87  static std::string dateTime();
88 
89  //- The current wall-clock date as a string formatted as
90  //- (MON dd yyyy), where MON is Jan, Feb, etc.
91  static std::string date();
92 
93  //- The current wall-clock (in local time) as a string formatted as
94  //- as (hh:mm:ss).
95  // Without time-zone information.
96  static std::string clockTime();
97 
98 
99  // Member Functions
100 
101  //- Returns wall-clock time since clock instantiation
102  double elapsedClockTime() const;
103 
104  //- Returns wall-clock time since last clockTimeIncrement() call
105  double clockTimeIncrement() const;
106 };
107 
108 
109 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
110 
111 } // End namespace Foam
112 
113 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
114 
115 #endif
116 
117 // ************************************************************************* //
Foam::clock::clock
clock()
Construct with the current clock time for the start point.
Definition: clock.C:113
Foam::clock::dateTime
static std::string dateTime()
Definition: clock.C:60
Foam::clock::getTime
static time_t getTime()
Get the current clock time in seconds.
Definition: clock.C:46
Foam::clock::clockTimeIncrement
double clockTimeIncrement() const
Returns wall-clock time since last clockTimeIncrement() call.
Definition: clock.C:129
Foam::clock::date
static std::string date()
Definition: clock.C:80
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::clock
Read access to the system clock with formatting.
Definition: clock.H:52
Foam::clock::rawDate
static const struct tm rawDate()
The current wall-clock date as a raw struct.
Definition: clock.C:52
Foam::clock::clockTime
static std::string clockTime()
Definition: clock.C:95
Foam::clock::elapsedClockTime
double elapsedClockTime() const
Returns wall-clock time since clock instantiation.
Definition: clock.C:122