Pair.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2025 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::Pair
26 
27 Description
28  An ordered pair of two objects of type <Type> with first() and second()
29  elements.
30 
31 See also
32  Foam::Tuple2 for storing two objects of dissimilar types.
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef Pair_H
37 #define Pair_H
38 
39 #include "Hash.H"
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 namespace Foam
44 {
45 
46 // Forward declaration of friend functions and operators
47 
48 template<class Type>
49 class Pair;
50 
51 template<class Type>
52 void writeEntry(Ostream& os, const Pair<Type>&);
53 
54 template<class Type>
56 
57 template<class Type>
58 inline Ostream& operator<<(Ostream&, const Pair<Type>&);
59 
60 
61 /*---------------------------------------------------------------------------*\
62  Class Pair Declaration
63 \*---------------------------------------------------------------------------*/
64 
65 template<class Type>
66 class Pair
67 {
68  // Private Data
69 
70  //- First object
71  Type f_;
72 
73  //- Second object
74  Type s_;
75 
76 
77 public:
78 
79  // Public Sub-Classes
80 
81  //- Hashing function class
82  template<class HashT=Hash<Type>>
83  class Hash
84  {
85  public:
86 
87  // Constructors
88 
89  //- Null constructor
90  inline Hash();
91 
92 
93  // Member Operators
94 
95  //- Hash a pair
96  inline unsigned operator()
97  (
98  const Pair<Type>& p,
99  unsigned seed = 0
100  ) const;
101  };
102 
103 
104  // Static Member Functions
105 
106  //- Return a null pair
107  static inline const Pair<Type>& null();
108 
109  //- Return the size
110  static inline label size();
111 
112  //- Check index i is within valid range (0 ... 1)
113  static inline void checkIndex(const label i);
114 
115  //- Compare two pairs. Return 0 if they are different, +1 if they are
116  // identical, and -1 if the elements are the same but reversed.
117  static inline int compare(const Pair<Type>& a, const Pair<Type>& b);
118 
119 
120  // Constructors
121 
122  //- Null constructor
123  inline Pair();
124 
125  //- Construct from components
126  inline Pair(const Type& f, const Type& s);
127 
128  //- Construct from Istream
129  inline Pair(Istream& is);
130 
131 
132  // Member Functions
133 
134  //- Return first
135  inline const Type& first() const;
136 
137  //- Return first
138  inline Type& first();
139 
140  //- Return second
141  inline const Type& second() const;
142 
143  //- Return second
144  inline Type& second();
145 
146  //- Return other
147  inline const Type& other(const Type& a) const;
148 
149 
150  // Member Operators
151 
152  //- Access an element by index
153  inline Type& operator[](const label i);
154 
155  //- Const-access an element by index
156  inline const Type& operator[](const label i) const;
157 
158 
159  // STL type definitions
160 
161  //- Type of values the pair contains
162  typedef Type value_type;
163 
164  //- Type that can be used for storing into
165  // pair::value_type objects
166  typedef Type& reference;
167 
168  //- Type that can be used for storing into
169  // constant pair::value_type objects
170  typedef const Type& const_reference;
171 };
172 
173 
174 // Global Functions
175 
176 //- Reverse the elements in a pair
177 template<class Type>
178 inline Pair<Type> reverse(const Pair<Type>& p);
179 
180 //- Equality comparison
181 template<class Type>
182 inline bool operator==(const Pair<Type>& a, const Pair<Type>& b);
183 
184 //- Inequality comparison
185 template<class Type>
186 inline bool operator!=(const Pair<Type>& a, const Pair<Type>& b);
187 
188 //- Compare lexographic order
189 template<class Type>
190 inline bool operator<(const Pair<Type>& a, const Pair<Type>& b);
191 
192 //- Compare lexographic order
193 template<class Type>
194 inline bool operator<=(const Pair<Type>& a, const Pair<Type>& b);
195 
196 //- Compare lexographic order
197 template<class Type>
198 inline bool operator>(const Pair<Type>& a, const Pair<Type>& b);
199 
200 //- Compare lexographic order
201 template<class Type>
202 inline bool operator>=(const Pair<Type>& a, const Pair<Type>& b);
203 
204 //- Read a from a stream
205 template<class Type>
206 inline Istream& operator>>(Istream& is, Pair<Type>& p);
207 
208 //- Write to a stream
209 template<class Type>
210 inline Ostream& operator<<(Ostream& os, const Pair<Type>& p);
211 
212 //- Write as a dictionary entry
213 template<class Type>
214 inline void writeEntry(Ostream& os, const Pair<Type>& p);
215 
216 
217 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
218 
219 } // End namespace Foam
220 
221 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
222 
223 #include "PairI.H"
224 
225 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
226 
227 #endif
228 
229 // ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
Hashing function class.
Definition: Pair.H:83
Hash()
Null constructor.
Definition: PairI.H:100
An ordered pair of two objects of type <Type> with first() and second() elements.
Definition: Pair.H:66
Type & reference
Type that can be used for storing into.
Definition: Pair.H:165
Type & operator[](const label i)
Access an element by index.
Definition: PairI.H:164
static label size()
Return the size.
Definition: PairI.H:40
static int compare(const Pair< Type > &a, const Pair< Type > &b)
Compare two pairs. Return 0 if they are different, +1 if they are.
Definition: PairI.H:59
Type value_type
Type of values the pair contains.
Definition: Pair.H:161
static void checkIndex(const label i)
Check index i is within valid range (0 ... 1)
Definition: PairI.H:47
const Type & second() const
Return second.
Definition: PairI.H:121
const Type & other(const Type &a) const
Return other.
Definition: PairI.H:135
const Type & first() const
Return first.
Definition: PairI.H:107
Pair()
Null constructor.
Definition: PairI.H:79
const Type & const_reference
Type that can be used for storing into.
Definition: Pair.H:169
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(lagrangian::Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(lagrangian::Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(lagrangian::Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.name(), lagrangian::cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
volScalarField & b
Definition: createFields.H:27
Namespace for OpenFOAM.
bool operator!=(const particle &, const particle &)
Definition: particle.C:424
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
tmp< fvMatrix< Type > > operator==(const fvMatrix< Type > &, const fvMatrix< Type > &)
bool operator<(const instant &, const instant &)
Definition: instant.C:79
bool operator<=(const Pair< Type > &a, const Pair< Type > &b)
Compare lexographic order.
Definition: PairI.H:236
void reverse(UList< T > &, const label n)
Definition: UListI.H:334
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
Istream & operator>>(Istream &, pistonPointEdgeData &)
bool operator>(const instant &, const instant &)
Definition: instant.C:85
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
bool operator>=(const Pair< Type > &a, const Pair< Type > &b)
Compare lexographic order.
Definition: PairI.H:250
labelList f(nPoints)
volScalarField & p