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-2026 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 #include "scaleable.H"
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46 
47 // Forward declaration of friend functions and operators
48 
49 template<class Type>
50 class Pair;
51 
52 template<class Type>
53 void writeEntry(Ostream& os, const Pair<Type>&);
54 
55 template<class Type>
57 
58 template<class Type>
59 inline Ostream& operator<<(Ostream&, const Pair<Type>&);
60 
61 
62 /*---------------------------------------------------------------------------*\
63  Class Pair Declaration
64 \*---------------------------------------------------------------------------*/
65 
66 template<class Type>
67 class Pair
68 {
69  // Private Data
70 
71  //- First object
72  Type f_;
73 
74  //- Second object
75  Type s_;
76 
77 
78 public:
79 
80  // Public Sub-Classes
81 
82  //- Hashing function class
83  template<class HashT=Hash<Type>>
84  class Hash
85  {
86  public:
87 
88  // Constructors
89 
90  //- Null constructor
91  inline Hash();
92 
93 
94  // Member Operators
95 
96  //- Hash a pair
97  inline unsigned operator()
98  (
99  const Pair<Type>& p,
100  unsigned seed = 0
101  ) const;
102  };
103 
104 
105  // Static Member Functions
106 
107  //- Return a null pair
108  static inline const Pair<Type>& null();
109 
110  //- Return the size
111  static inline label size();
112 
113  //- Check index i is within valid range (0 ... 1)
114  static inline void checkIndex(const label i);
115 
116  //- Compare two pairs. Return 0 if they are different, +1 if they are
117  // identical, and -1 if the elements are the same but reversed.
118  static inline int compare(const Pair<Type>& a, const Pair<Type>& b);
119 
120 
121  // Constructors
122 
123  //- Null constructor
124  inline Pair();
125 
126  //- Construct from components
127  inline Pair(const Type& f, const Type& s);
128 
129  //- Construct from Istream
130  inline Pair(Istream& is);
131 
132 
133  // Member Functions
134 
135  //- Return first
136  inline const Type& first() const;
137 
138  //- Return first
139  inline Type& first();
140 
141  //- Return second
142  inline const Type& second() const;
143 
144  //- Return second
145  inline Type& second();
146 
147  //- Return other
148  inline const Type& other(const Type& a) const;
149 
150 
151  // Member Operators
152 
153  //- Access an element by index
154  inline Type& operator[](const label i);
155 
156  //- Const-access an element by index
157  inline const Type& operator[](const label i) const;
158 
159 
160  // STL type definitions
161 
162  //- Type of values the pair contains
163  typedef Type value_type;
164 
165  //- Type that can be used for storing into
166  // pair::value_type objects
167  typedef Type& reference;
168 
169  //- Type that can be used for storing into
170  // constant pair::value_type objects
171  typedef const Type& const_reference;
172 };
173 
174 
175 // Global Functions
176 
177 //- Reverse the elements in a pair
178 template<class Type>
179 inline Pair<Type> reverse(const Pair<Type>& p);
180 
181 //- Equality comparison
182 template<class Type>
183 inline bool operator==(const Pair<Type>& a, const Pair<Type>& b);
184 
185 //- Inequality comparison
186 template<class Type>
187 inline bool operator!=(const Pair<Type>& a, const Pair<Type>& b);
188 
189 //- Compare lexographic order
190 template<class Type>
191 inline bool operator<(const Pair<Type>& a, const Pair<Type>& b);
192 
193 //- Compare lexographic order
194 template<class Type>
195 inline bool operator<=(const Pair<Type>& a, const Pair<Type>& b);
196 
197 //- Compare lexographic order
198 template<class Type>
199 inline bool operator>(const Pair<Type>& a, const Pair<Type>& b);
200 
201 //- Compare lexographic order
202 template<class Type>
203 inline bool operator>=(const Pair<Type>& a, const Pair<Type>& b);
204 
205 //- Read a from a stream
206 template<class Type>
207 inline Istream& operator>>(Istream& is, Pair<Type>& p);
208 
209 //- Write to a stream
210 template<class Type>
211 inline Ostream& operator<<(Ostream& os, const Pair<Type>& p);
212 
213 //- Write as a dictionary entry
214 template<class Type>
215 inline void writeEntry(Ostream& os, const Pair<Type>& p);
216 
217 
218 //- A pair is scaleable if its type is
219 template<class Type>
220 struct scaleable<Pair<Type>> : public scaleable<Type> {};
221 
222 //- Apply a conversion to a Pair by applying separately to first and second
223 template<class Type, class ... Args>
224 void convert(Pair<Type>& t, const Args& ... args)
225 {
226  convert(t.first(), args ...);
227  convert(t.second(), args ...);
228 }
229 
230 
231 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
232 
233 } // End namespace Foam
234 
235 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
236 
237 #include "PairI.H"
238 
239 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
240 
241 #endif
242 
243 // ************************************************************************* //
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:84
Hash()
Null constructor.
Definition: PairI.H:100
An ordered pair of two objects of type <Type> with first() and second() elements.
Definition: Pair.H:67
Type & reference
Type that can be used for storing into.
Definition: Pair.H:166
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:162
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:170
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:445
Istream & operator>>(Istream &, pointEdgeDist &)
Definition: pointEdgeDist.C:41
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
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
void writeEntry(Ostream &os, const word &key, const DimensionedFieldFunction< DimensionedFieldType > &f)
void convert(UList< Type > &l, const Args &... args)
Apply a conversion to a UList by applying to each element individually.
Definition: UList.H:421
labelList f(nPoints)
Trait to identify types which are "scaleable"; i.e., that can be multiply-equals-d with a scalar....
Foam::argList args(argc, argv)
volScalarField & p