clockValue.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) 2018-2019 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::clockValue
28 
29 Description
30  Access to high-resolution clock value with some basic operations.
31 
32 SourceFiles
33  clockValue.C
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef clockValue_H
38 #define clockValue_H
39 
40 #include <chrono>
41 #include <string>
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 /*---------------------------------------------------------------------------*\
49  Class clockValue Declaration
50 \*---------------------------------------------------------------------------*/
51 
52 class clockValue
53 {
54  // Private Data
55 
56  //- Time structure used
57  typedef std::chrono::high_resolution_clock::duration value_type;
58 
59  value_type value_;
60 
61 
62 public:
63 
64  // Constructors
65 
66  //- Construct zero initialized
67  clockValue();
68 
69  //- Construct from duration with the same clock base
70  explicit clockValue(const value_type& value);
71 
72  //- Construct zero initialized or with current time
73  explicit clockValue(bool useNow);
74 
75 
76  // Factory Methods
77 
78  //- Return the current time value from the system
79  inline static clockValue now()
80  {
81  return clockValue(true);
82  }
83 
84 
85  // Member Functions
86 
87  //- Return the value
88  inline const value_type& value() const
89  {
90  return value_;
91  }
92 
93  //- Reset to zero
94  void clear();
95 
96  //- Update to the current now() time from the system
97  void update();
98 
99  //- The time elapsed from now() since the start time.
100  clockValue elapsed() const;
101 
102  //- The value in seconds (rounded)
103  long seconds() const;
104 
105  //- Format as day-hh:mm:ss string
106  std::string str() const;
107 
108 
109  // Operators
110 
111  //- Conversion operator to seconds in floating point
112  operator double() const;
113 
114  //- Subtract time value
115  clockValue& operator-=(const clockValue& rhs);
116 
117  //- Add time value
118  clockValue& operator+=(const clockValue& rhs);
119 };
120 
121 
122 // Global Operators
123 
124 //- Subtraction of clock values
125 clockValue operator-(const clockValue& a, const clockValue& b);
126 
127 //- Addition of clock values
128 clockValue operator+(const clockValue& a, const clockValue& b);
129 
130 
131 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
132 
133 } // End namespace Foam
134 
135 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
136 
137 #endif
138 
139 // ************************************************************************* //
Foam::clockValue::seconds
long seconds() const
The value in seconds (rounded)
Definition: clockValue.C:79
Foam::operator-
tmp< faMatrix< Type > > operator-(const faMatrix< Type > &)
Foam::clockValue::operator-=
clockValue & operator-=(const clockValue &rhs)
Subtract time value.
Definition: clockValue.C:143
Foam::clockValue::elapsed
clockValue elapsed() const
The time elapsed from now() since the start time.
Definition: clockValue.C:73
Foam::clockValue::clockValue
clockValue()
Construct zero initialized.
Definition: clockValue.C:36
Foam::clockValue::value
const value_type & value() const
Return the value.
Definition: clockValue.H:87
Foam::constant::physicoChemical::b
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
Foam::clockValue::update
void update()
Update to the current now() time from the system.
Definition: clockValue.C:67
Foam::clockValue::str
std::string str() const
Format as day-hh:mm:ss string.
Definition: clockValue.C:85
Foam::clockValue
Access to high-resolution clock value with some basic operations.
Definition: clockValue.H:51
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::clockValue::clear
void clear()
Reset to zero.
Definition: clockValue.C:61
Foam::operator+
tmp< faMatrix< Type > > operator+(const faMatrix< Type > &, const faMatrix< Type > &)
Foam::clockValue::operator+=
clockValue & operator+=(const clockValue &rhs)
Add time value.
Definition: clockValue.C:150
Foam::clockValue::now
static clockValue now()
Return the current time value from the system.
Definition: clockValue.H:78