phasePairKey.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) 2014-2016 OpenFOAM Foundation
9  Copyright (C) 2017-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::phasePairKey
29 
30 Description
31  An ordered or unorder pair of phase names.
32  Typically specified as follows.
33  \verbatim
34  (phase1 and phase2) // unordered
35  (phase1 to phase2) // ordered
36  \endverbatim
37 
38 SourceFiles
39  phasePairKey.C
40 
41 \*---------------------------------------------------------------------------*/
42 
43 #ifndef phasePairKey_H
44 #define phasePairKey_H
45 
46 #include "Pair.H"
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 // Forward Declarations
54 class phasePairKey;
55 
56 bool operator==(const phasePairKey& a, const phasePairKey& b);
57 bool operator!=(const phasePairKey& a, const phasePairKey& b);
58 
59 Istream& operator>>(Istream& is, phasePairKey& key);
60 Ostream& operator<<(Ostream& os, const phasePairKey& key);
61 
62 /*---------------------------------------------------------------------------*\
63  Class phasePairKey Declaration
64 \*---------------------------------------------------------------------------*/
65 
66 class phasePairKey
67 :
68  public Pair<word>
69 {
70  // Private Data
71 
72  //- Flag to indicate whether ordering is important
73  bool ordered_;
74 
75 
76 public:
77 
78  // Constructors
79 
80  //- Default construct
81  phasePairKey() = default;
82 
83  //- Construct from names and (optional) ordering flag
85  (
86  const word& name1,
87  const word& name2,
88  const bool ordered = false
89  );
90 
91 
92  //- Destructor
93  virtual ~phasePairKey() = default;
94 
95 
96  // Member Functions
97 
98  //- Return the ordered flag
99  bool ordered() const noexcept
100  {
101  return ordered_;
102  }
103 
104 
105  // Friend Operators
106 
107  //- Test for equality
108  friend bool operator==(const phasePairKey& a, const phasePairKey& b);
109 
110  //- Test for inequality
111  friend bool operator!=(const phasePairKey& a, const phasePairKey& b);
112 
113  //- Read from Istream
114  friend Istream& operator>>(Istream& is, phasePairKey& key);
115 
116  //- Write to Ostream
117  friend Ostream& operator<<(Ostream& os, const phasePairKey& key);
118 
119 
120  // Hashing
121 
122  //- Hashing functor for phasePairKey
123  struct hasher
124  {
125  unsigned operator()(const phasePairKey& key) const
126  {
127  if (key.ordered())
128  {
129  return Pair<word>::hasher()(key);
130  }
131  else
132  {
133  return Pair<word>::symmHasher()(key);
134  }
135  }
136  };
137 
138  //- Alternative name for functor
139  using hash = phasePairKey::hasher;
140 };
141 
142 
143 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
144 
145 //- Hashing for phasePairKey
146 template<> struct Hash<phasePairKey> : phasePairKey::hasher {};
147 
148 
149 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
150 
151 } // End namespace Foam
152 
153 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
154 
155 #endif
156 
157 // ************************************************************************* //
Foam::phasePairKey::hasher
Hashing functor for phasePairKey.
Definition: phasePairKey.H:122
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::phasePairKey::~phasePairKey
virtual ~phasePairKey()=default
Destructor.
Foam::glTF::key
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
Definition: foamGltfBase.H:108
Foam::phasePairKey::operator>>
friend Istream & operator>>(Istream &is, phasePairKey &key)
Read from Istream.
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:230
Pair.H
Foam::phasePairKey::phasePairKey
phasePairKey()=default
Default construct.
Foam::operator!=
bool operator!=(const eddy &a, const eddy &b)
Definition: eddy.H:239
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::phasePairKey::operator<<
friend Ostream & operator<<(Ostream &os, const phasePairKey &key)
Write to Ostream.
Foam::phasePairKey::ordered
bool ordered() const noexcept
Return the ordered flag.
Definition: phasePairKey.H:98
Foam::Hash
Hash function class. The default definition is for primitives. Non-primitives used to hash entries on...
Definition: Hash.H:53
Foam::constant::physicoChemical::b
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
Foam::operator==
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::phasePairKey
An ordered or unorder pair of phase names. Typically specified as follows.
Definition: phasePairKey.H:65
os
OBJstream os(runTime.globalPath()/outputName)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::phasePairKey::operator==
friend bool operator==(const phasePairKey &a, const phasePairKey &b)
Test for equality.
Foam::Pair
An ordered pair of two objects of type <T> with first() and second() elements.
Definition: Pair.H:54
Foam::phasePairKey::operator!=
friend bool operator!=(const phasePairKey &a, const phasePairKey &b)
Test for inequality.
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::phasePairKey::hasher::operator()
unsigned operator()(const phasePairKey &key) const
Definition: phasePairKey.H:124