PairI.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) 2017-2020 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
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// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
29
30template<class T>
31inline int Foam::Pair<T>::compare(const Pair<T>& a, const Pair<T>& b)
32{
33 if (a.first() == b.first() && a.second() == b.second())
34 {
35 return 1;
36 }
37 if (a.first() == b.second() && a.second() == b.first())
38 {
39 return -1;
40 }
41
42 return 0;
43}
44
45
46// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
47
48template<class T>
49inline Foam::Pair<T>::Pair(const T& f, const T& s)
50{
51 first() = f;
52 second() = s;
53}
54
55
56template<class T>
58{
59 first() = std::move(f);
60 second() = std::move(s);
61}
62
63
64template<class T>
65inline Foam::Pair<T>::Pair(const std::pair<T,T>& vals)
66{
67 first() = vals.first;
68 second() = vals.second;
69}
70
71
72template<class T>
73inline Foam::Pair<T>::Pair(std::pair<T,T>&& vals)
74{
75 first() = std::move(vals.first);
76 second() = std::move(vals.second);
77}
79
80template<class T>
82:
83 FixedList<T, 2>(list)
84{}
85
86
87template<class T>
88inline Foam::Pair<T>::Pair(const T& f, const T& s, const bool doSort)
89{
90 if (doSort && s < f)
91 {
92 first() = s;
93 second() = f;
94 }
95 else
96 {
97 first() = f;
98 second() = s;
99 }
100}
101
102
103template<class T>
104inline Foam::Pair<T>::Pair(const FixedList<T, 2>& list, const bool doSort)
105:
106 Pair<T>(list.first(), list.last(), doSort)
107{}
108
109
110template<class T>
112:
113 FixedList<T, 2>(is)
114{}
115
117// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
118
119template<class T>
120inline const T& Foam::Pair<T>::second() const noexcept
121{
122 return last();
123}
124
126template<class T>
128{
129 return last();
130}
132
133template<class T>
134inline const T& Foam::Pair<T>::other(const T& a) const
135{
136 if (first() == second())
137 {
139 << "Call to other only valid for Pair with differing elements:"
140 << *this << abort(FatalError);
141 }
142 else if (a == first())
143 {
144 return second();
145 }
146 else if (a != second())
147 {
149 << "Pair " << *this
150 << " does not contain " << a << abort(FatalError);
151 }
152
153 return first();
154}
155
156
157template<class T>
159{
160 Foam::Swap(first(), second());
161}
162
163
164template<class T>
165inline bool Foam::Pair<T>::sorted() const
166{
167 return !(second() < first());
168}
169
170
171template<class T>
173{
174 if (second() < first())
175 {
176 flip();
177 }
178}
179
180
181// ************************************************************************* //
A 1D vector of objects of type <T> with a fixed length <N>.
Definition: FixedList.H:81
T & first() noexcept
The first element of the list, position [0].
Definition: FixedListI.H:207
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
An ordered pair of two objects of type <T> with first() and second() elements.
Definition: Pair.H:69
Pair()=default
Default construct.
void flip()
Flip the Pair in-place.
Definition: PairI.H:158
bool sorted() const
True if first() is less-than second()
Definition: PairI.H:165
void sort()
Sort so that first() is less-than second()
Definition: PairI.H:172
const T & other(const T &a) const
Return other element.
Definition: PairI.H:134
static int compare(const Pair< T > &a, const Pair< T > &b)
Compare Pairs.
Definition: PairI.H:31
const T & second() const noexcept
Return second element, which is also the last element.
Definition: PairI.H:120
const volScalarField & T
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
void Swap(DynamicList< T, SizeMinA > &a, DynamicList< T, SizeMinB > &b)
Definition: DynamicList.H:408
errorManip< error > abort(error &err)
Definition: errorManip.H:144
const direction noexcept
Definition: Scalar.H:223
error FatalError
labelList f(nPoints)
volScalarField & b
Definition: createFields.H:27