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 -------------------------------------------------------------------------------
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 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
29 
30 template<class T>
31 inline 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 
48 template<class T>
49 inline Foam::Pair<T>::Pair(const T& f, const T& s)
50 {
51  first() = f;
52  second() = s;
53 }
54 
55 
56 template<class T>
57 inline Foam::Pair<T>::Pair(T&& f, T&& s)
58 {
59  first() = std::move(f);
60  second() = std::move(s);
61 }
62 
63 
64 template<class T>
65 inline Foam::Pair<T>::Pair(const std::pair<T,T>& vals)
66 {
67  first() = vals.first;
68  second() = vals.second;
69 }
70 
71 
72 template<class T>
73 inline Foam::Pair<T>::Pair(std::pair<T,T>&& vals)
74 {
75  first() = std::move(vals.first);
76  second() = std::move(vals.second);
77 }
78 
79 
80 template<class T>
82 :
83  FixedList<T, 2>(list)
84 {}
85 
86 
87 template<class T>
88 inline 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 
103 template<class T>
104 inline 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 
110 template<class T>
111 inline Foam::Pair<T>::Pair(Istream& is)
112 :
113  FixedList<T, 2>(is)
114 {}
115 
116 
117 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
118 
119 template<class T>
120 inline 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);
137  }
138 
139  return first();
140 }
141 
142 
143 template<class T>
144 inline void Foam::Pair<T>::flip()
145 {
146  Foam::Swap(first(), second());
147 }
148 
149 
150 template<class T>
151 inline bool Foam::Pair<T>::is_sorted() const
152 {
153  return !(second() < first());
154 }
155 
156 
157 template<class T>
158 inline void Foam::Pair<T>::sort()
159 {
160  if (second() < first())
161  {
162  flip();
163  }
164 }
165 
166 
167 // ************************************************************************* //
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
bool is_sorted() const
True if first() is less-than-equal second()
Definition: PairI.H:144
const T & first() const noexcept
Access the first element.
Definition: Pair.H:137
void sort()
Sort so that first() is less-than second()
Definition: PairI.H:151
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
void flip()
Flip the Pair in-place.
Definition: PairI.H:137
const T & other(const T &a) const
Return other element.
Definition: PairI.H:113
Pair()=default
Default construct.
An ordered pair of two objects of type <T> with first() and second() elements.
Definition: instant.H:46
static int compare(const Pair< T > &a, const Pair< T > &b)
Compare Pairs.
Definition: PairI.H:24
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
errorManip< error > abort(error &err)
Definition: errorManip.H:139
labelList f(nPoints)
const volScalarField & T
void Swap(DynamicList< T, SizeMinA > &a, DynamicList< T, SizeMinB > &b)
Exchange contents of lists - see DynamicList::swap().
Definition: DynamicList.H:692
const T & second() const noexcept
Access the second element.
Definition: Pair.H:147
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))