Loading...
Searching...
No Matches
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-2023 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)
51 first() = f;
52 second() = s;
53}
54
55
56template<class T>
57inline Foam::Pair<T>::Pair(T&& f, T&& s)
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)
67 first() = vals.first;
68 second() = vals.second;
69}
70
71
72template<class T>
73inline Foam::Pair<T>::Pair(std::pair<T,T>&& vals)
75 first() = std::move(vals.first);
76 second() = std::move(vals.second);
77}
78
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.template get<0>(), list.template get<1>(), doSort)
107{}
108
109
110template<class T>
112:
113 FixedList<T, 2>(is)
114{}
115
116
117// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
118
119template<class T>
120inline const T& Foam::Pair<T>::other(const T& val) const
121{
122 if (first() == second())
123 {
125 << "Call to other only valid for Pair with differing elements:"
126 << *this << abort(FatalError);
127 }
128 else if (val == first())
129 {
130 return second();
131 }
132 else if (val != second())
133 {
135 << "Pair " << *this
136 << " does not contain " << val << abort(FatalError);
138
139 return first();
140}
141
142
143template<class T>
145{
146 Foam::Swap(first(), second());
147}
148
149
150template<class T>
151inline bool Foam::Pair<T>::is_sorted() const
152{
153 return !(second() < first());
154}
155
156
157template<class T>
158inline void Foam::Pair<T>::sort()
159{
160 if (second() < first())
161 {
162 flip();
163 }
164}
166
167// ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
Pair()=default
Default construct.
void flip()
Flip the Pair in-place.
Definition PairI.H:137
bool is_sorted() const
True if first() is less-than-equal second().
Definition PairI.H:144
void sort()
Sort so that first() is less-than second().
Definition PairI.H:151
const T & other(const T &a) const
Return other element.
Definition PairI.H:113
static int compare(const Pair< T > &a, const Pair< T > &b)
Compare Pairs.
Definition PairI.H:24
const T & first() const noexcept
Access the first element.
Definition Pair.H:137
const T & second() const noexcept
Access the second element.
Definition Pair.H:147
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
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)
Exchange contents of lists - see DynamicList::swap().
errorManip< error > abort(error &err)
Definition errorManip.H:139
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
labelList f(nPoints)
volScalarField & b