Instant.C
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 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 \*---------------------------------------------------------------------------*/
27 
28 #include "Instant.H"
29 
30 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31 
32 template<class T>
34 :
35  val_(0),
36  key_()
37 {}
38 
39 
40 template<class T>
41 Foam::Instant<T>::Instant::Instant(scalar val, const T& key)
42 :
43  val_(val),
44  key_(key)
45 {}
46 
47 
48 template<class T>
50 :
51  val_(val),
52  key_(std::move(key))
53 {}
54 
55 
56 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
57 
58 template<class T>
59 bool Foam::Instant<T>::equal(scalar val) const
60 {
61  return ((val_ > val - SMALL) && (val_ < val + SMALL));
62 }
63 
64 
65 template<class T>
66 template<class T2>
67 bool Foam::Instant<T>::equal(const Instant<T2>& other) const
68 {
69  return this->equal(other.value());
70 }
71 
72 
73 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
74 
75 template<class T1, class T2>
76 bool Foam::operator==(const Instant<T1>& a, const Instant<T2>& b)
77 {
78  return a.equal(b.value());
79 }
80 
81 
82 template<class T1, class T2>
83 bool Foam::operator!=(const Instant<T1>& a, const Instant<T2>& b)
84 {
85  return !a.equal(b.value());
86 }
87 
88 
89 template<class T1, class T2>
90 bool Foam::operator<(const Instant<T1>& a, const Instant<T2>& b)
91 {
92  return a.value() < b.value();
93 }
94 
95 
96 template<class T1, class T2>
97 bool Foam::operator>(const Instant<T1>& a, const Instant<T2>& b)
98 {
99  return a.value() > b.value();
100 }
101 
102 
103 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
104 
105 template<class T>
106 Foam::Istream& Foam::operator>>(Istream& is, Instant<T>& inst)
107 {
108  is >> inst.value() >> inst.name();
109  return is;
110 }
111 
112 
113 template<class T>
114 Foam::Ostream& Foam::operator<<(Ostream& os, const Instant<T>& inst)
115 {
116  os << inst.value() << '\t' << inst.name();
117  return os;
118 }
119 
120 
121 // ************************************************************************* //
Foam::glTF::key
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
Definition: foamGltfBase.H:108
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:230
Foam::dimensioned::value
const Type & value() const
Return const reference to value.
Definition: dimensionedType.C:434
Foam::Instant::equal
bool equal(scalar val) const
True if values are equal (includes SMALL for rounding)
Definition: Instant.C:59
Foam::Instant::Instant
Instant()
Construct null, with value = 0.
Definition: Instant.C:33
Foam::MatrixTools::equal
bool equal(const Matrix< Form1, Type > &A, const Matrix< Form2, Type > &B, const bool verbose=false, const label maxDiffs=10, const scalar relTol=1e-5, const scalar absTol=1e-8)
Compare matrix elements for absolute or relative equality.
Definition: MatrixTools.C:34
Instant.H
Foam::operator!=
bool operator!=(const eddy &a, const eddy &b)
Definition: eddy.H:239
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::constant::physicoChemical::b
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
Foam::operator==
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::IOstream::name
virtual const fileName & name() const
Return the name of the stream.
Definition: IOstream.C:40
os
OBJstream os(runTime.globalPath()/outputName)
T
const volScalarField & T
Definition: createFieldRefs.H:2
Foam::Instant::value
scalar value() const
The value (const access)
Definition: Instant.H:99
Foam::operator<
bool operator<(const IOstreamOption::versionNumber &a, const IOstreamOption::versionNumber &b) noexcept
Version A older than B.
Definition: IOstreamOption.H:398
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::Instant
A tuple of value and key. The value often corresponds to a time value, thus the naming of the class....
Definition: Instant.H:53
Foam::operator>
bool operator>(const IOstreamOption::versionNumber &a, const IOstreamOption::versionNumber &b) noexcept
Version A newer than B.
Definition: IOstreamOption.H:418