Instant.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 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::Instant
28 
29 Description
30  A tuple of value and key.
31  The value often corresponds to a time value, thus the naming of the class.
32  The key will usually be a time name or a file name etc.
33 
34 SourceFiles
35  Instant.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef Instant_H
40 #define Instant_H
41 
42 #include "scalar.H"
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 /*---------------------------------------------------------------------------*\
50  Class Instant Declaration
51 \*---------------------------------------------------------------------------*/
52 
53 template<class T>
54 class Instant
55 {
56  // Private Data
57 
58  //- The value (eg, time)
59  scalar val_;
60 
61  //- The name/key
62  T key_;
63 
64 
65 public:
66 
67  // Public classes
68 
69  //- Less function for sorting
70  struct less
71  {
72  bool operator()(const Instant& a, const Instant& b) const
73  {
74  return a.value() < b.value();
75  }
76  };
77 
78 
79  // Constructors
80 
81  //- Construct null, with value = 0.
82  Instant();
83 
84  //- Copy construct from components
85  Instant(scalar val, const T& key);
86 
87  //- Move construct from components
88  Instant(scalar val, T&& key);
89 
90  //- Copy construct
91  Instant(const Instant&) = default;
92 
93  //- Move construct
94  Instant(Instant&&) = default;
95 
96 
97  // Member Functions
98 
99  //- The value (const access)
100  scalar value() const
101  {
102  return val_;
103  }
104 
105  //- The value (non-const access)
106  scalar& value()
107  {
108  return val_;
109  }
110 
111  //- The name/key (const access)
112  const T& name() const
113  {
114  return key_;
115  }
116 
117  //- The name/key (non-const access)
118  T& name()
119  {
120  return key_;
121  }
122 
123  //- True if values are equal (includes SMALL for rounding)
124  bool equal(scalar val) const;
125 
126  //- True if values are equal (includes SMALL for rounding)
127  template<class T2>
128  bool equal(const Instant<T2>& other) const;
129 
130 
131  // Operators
132 
133  //- Copy assignment
134  Instant& operator=(const Instant&) = default;
135 
136  //- Move assignment
137  Instant& operator=(Instant&&) = default;
138 };
139 
140 
141 // IOstream Operators
142 
143 template<class T> Istream& operator>>(Istream& is, Instant<T>& inst);
144 template<class T> Ostream& operator<<(Ostream& os, const Instant<T>& inst);
145 
146 
147 // Global Operators
148 
149 //- Compare instant values for equality
150 template<class T1, class T2>
151 bool operator==(const Instant<T1>& a, const Instant<T2>& b);
152 
153 //- Compare instant values for inequality
154 template<class T1, class T2>
155 bool operator!=(const Instant<T1>& a, const Instant<T2>& b);
156 
157 //- Compare instant values for less-than
158 template<class T1, class T2>
159 bool operator<(const Instant<T1>& a, const Instant<T2>& b);
160 
161 //- Compare instant values for greater-than
162 template<class T1, class T2>
163 bool operator>(const Instant<T1>& a, const Instant<T2>& b);
164 
165 
166 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
167 
168 } // End namespace Foam
169 
170 
171 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
172 
173 #ifdef NoRepository
174  #include "Instant.C"
175 #endif
176 
177 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
178 
179 #endif
180 
181 // ************************************************************************* //
Foam::Instant::less
Less function for sorting.
Definition: Instant.H:69
Foam::Instant::value
scalar & value()
The value (non-const access)
Definition: Instant.H:105
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::Instant::less::operator()
bool operator()(const Instant &a, const Instant &b) const
Definition: Instant.H:71
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
Instant.C
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::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:58
scalar.H
os
OBJstream os(runTime.globalPath()/outputName)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::Instant::name
const T & name() const
The name/key (const access)
Definition: Instant.H:111
Foam::Instant::name
T & name()
The name/key (non-const access)
Definition: Instant.H:117
Foam::Instant::operator=
Instant & operator=(const Instant &)=default
Copy assignment.
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::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