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 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 structure used
58  typedef time_t value_type;
59 
60  //- Start time in seconds, at the time of construction
61  value_type start_;
62 
63  //- Last time when elapsedClockTime or clockTimeIncrement was called
64  mutable value_type last_;
65 
66 public:
67 
68  // Constructors
69 
70  //- Construct null, storing the start time
71  clock();
72 
73 
74  // Static Member Functions
75 
76  //- Get the current clock time in seconds
77  static time_t getTime();
78 
79  //- Return the current wall-clock date as a raw struct
80  static const struct tm rawDate();
81 
82  //- Return the current wall-clock date/time as a string
83  // format according to ISO-8601 (yyyy-mm-ddThh:mm:ss)
84  static std::string dateTime();
85 
86  //- Return the current wall-clock date as a string
87  static std::string date();
88 
89  //- Return the current wall-clock time as a string
90  static std::string clockTime();
91 
92 
93  // Member Functions
94 
95  //- Returns wall-clock time from clock instantiation
96  double elapsedClockTime() const;
97 
98  //- Returns wall-clock time from last call of clockTimeIncrement()
99  double clockTimeIncrement() const;
100 };
101 
102 
103 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
104 
105 } // End namespace Foam
106 
107 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
108 
109 #endif
110 
111 // ************************************************************************* //
Foam::clock::clock
clock()
Construct null, storing the start time.
Definition: clock.C:113
Foam::clock::dateTime
static std::string dateTime()
Return the current wall-clock date/time as a string.
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 from last call of clockTimeIncrement()
Definition: clock.C:129
Foam::clock::date
static std::string date()
Return the current wall-clock date as a string.
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()
Return the current wall-clock date as a raw struct.
Definition: clock.C:52
Foam::clock::clockTime
static std::string clockTime()
Return the current wall-clock time as a string.
Definition: clock.C:95
Foam::clock::elapsedClockTime
double elapsedClockTime() const
Returns wall-clock time from clock instantiation.
Definition: clock.C:122