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) 2011 OpenFOAM Foundation
9  Copyright (C) 2018-2022 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::instant
29 
30 Description
31  An instant of time. Contains the time value and name.
32  Uses Foam::Time when formatting the name.
33 
34 SourceFiles
35  instant.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef Foam_instant_H
40 #define Foam_instant_H
41 
42 #include "Instant.H"
43 #include "word.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 // Forward Declarations
51 template<class T> class Pair;
52 template<class T> class UList;
53 
54 /*---------------------------------------------------------------------------*\
55  Class instant Declaration
56 \*---------------------------------------------------------------------------*/
57 
58 class instant
59 :
60  public Instant<word>
61 {
62 public:
63 
64  // Static Data Members
65 
66  //- The type name (eg, for pTraits)
67  static const char* const typeName;
68 
69 
70  // Generated Methods
71 
72  //- Default construct, with value = 0 and empty name
73  instant() = default;
74 
75  //- Copy construct
76  instant(const instant&) = default;
77 
78  //- Move construct
79  instant(instant&&) = default;
80 
81  //- Copy assignment
82  instant& operator=(const instant&) = default;
83 
84  //- Move assignment
85  instant& operator=(instant&&) = default;
86 
87 
88  // Constructors
89 
90  //- Inherit all constructors (eg, copy/move construct from components)
92 
93  //- Construct from timeValue, auto generating the name
94  explicit instant(scalar timeValue);
95 
96  //- Copy construct from timeName, parsing timeName for a value
97  explicit instant(const word& timeName);
98 
99  //- Move construct from timeName, parsing timeName for a value
100  explicit instant(word&& timeName);
101 
102 
103  // Helper Functions (for searching)
104 
105  //- Find and return index of given start time (linear search)
106  static label findStart
107  (
108  const UList<instant>& times,
109  const scalar timeVal
110  );
111 
112  //- Find lower/upper indices for given time value in list of instances
113  //- (linear search) continuing \em after the given start index.
114  // \returns the range indices or (-1,-1) if unsuccessful.
115  static Pair<label> findRange
116  (
117  const UList<instant>& times,
118  const scalar timeVal,
119  const label start = -1
120  );
121 };
122 
123 
124 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
125 
126 } // End namespace Foam
127 
128 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
129 
130 #endif
131 
132 // ************************************************************************* //
static Pair< label > findRange(const UList< instant > &times, const scalar timeVal, const label start=-1)
Find lower/upper indices for given time value in list of instances (linear search) continuing after t...
Definition: instant.C:54
static label findStart(const UList< instant > &times, const scalar timeVal)
Find and return index of given start time (linear search)
Definition: instant.C:37
word timeName
Definition: getTimeIndex.H:3
An ordered pair of two objects of type <T> with first() and second() elements.
Definition: instant.H:46
A class for handling words, derived from Foam::string.
Definition: word.H:63
instant()=default
Default construct, with value = 0 and empty name.
static const char *const typeName
The type name (eg, for pTraits)
Definition: instant.H:64
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:105
An instant of time. Contains the time value and name. Uses Foam::Time when formatting the name...
Definition: instant.H:53
instant & operator=(const instant &)=default
Copy assignment.
A tuple of scalar value and key. The value often corresponds to a time value, thus the naming of the ...
Definition: Instant.H:45
Namespace for OpenFOAM.