labelledPair.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | cfMesh: A library for mesh generation
4  \\ / O peration |
5  \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6  \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
8 License
9  This file is part of cfMesh.
10 
11  cfMesh is free software; you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by the
13  Free Software Foundation; either version 3 of the License, or (at your
14  option) any later version.
15 
16  cfMesh 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 cfMesh. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  labelledPair
26 
27 Description
28  A class containing point label and meshOctreeCubeCoordinates.
29  It is used for exchanging data over processors
30 
31 SourceFiles
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef labelledPair_H
36 #define labelledPair_H
37 
38 #include "labelPair.H"
39 #include "contiguous.H"
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 namespace Foam
44 {
45 
46 /*---------------------------------------------------------------------------*\
47  Class labelledPair Declaration
48 \*---------------------------------------------------------------------------*/
49 
50 class labelledPair
51 {
52  // Private data
53  //- label
54  label pLabel_;
55 
56  //- pair data
58 
59  public:
60 
61  // Constructors
62  //- Null construct
63  labelledPair()
64  :
65  pLabel_(-1),
66  pair_()
67  {}
68 
69  //- Construct from label and pair
71  (
72  const label pl,
73  const labelPair& lp
74  )
75  :
76  pLabel_(pl),
77  pair_(lp)
78  {}
79 
80  // Destructor
82  {}
83 
84  // Member functions
85  //- return pair label
86  inline label pairLabel() const
87  {
88  return pLabel_;
89  }
90 
91  //- return the pair
92  inline const labelPair& pair() const
93  {
94  return pair_;
95  }
96 
97  // Member operators
98 
99  inline void operator=(const labelledPair& lpp)
100  {
101  pLabel_ = lpp.pLabel_;
102  pair_ = lpp.pair_;
103  }
104 
105  inline bool operator==
106  (
107  const labelledPair& lpp
108  ) const
109  {
110  if( pLabel_ != lpp.pLabel_ )
111  return false;
112 
113  const labelPair& op = lpp.pair_;
114 
115  if( (pair_.first() == op.first()) && (pair_.second() == op.second()) )
116  return true;
117  if( (pair_.first() == op.second()) && (pair_.second() == op.first()) )
118  return true;
119 
120  return false;
121  }
122 
123  inline bool operator!=
124  (
125  const labelledPair& lcc
126  ) const
127  {
128  return !this->operator==(lcc);
129  }
130 
131  inline bool operator<(const labelledPair& lpp) const
132  {
133  if( pLabel_ < lpp.pLabel_ )
134  {
135  return true;
136  }
137  else if( pLabel_ > lpp.pLabel_ )
138  {
139  return false;
140  }
141 
142  if(
143  (pair_.first() + pair_.second()) <
144  (lpp.pair().first() + lpp.pair().second())
145  )
146  return true;
147 
148  if(
150  Foam::min(lpp.pair().first(), lpp.pair().second())
151  )
152  return true;
153 
154  return false;
155  }
156 
157  // Friend operators
158  friend Ostream& operator<<
159  (
160  Ostream& os,
161  const labelledPair& lpp
162  )
163  {
164  os << token::BEGIN_LIST;
165  os << lpp.pLabel_ << token::SPACE;
166  os << lpp.pair_ << token::END_LIST;
167 
168  // Check state of Ostream
169  os.check
170  (
171  "operator<<(Ostream&, const labelledPair&"
172  );
173 
174  return os;
175  }
176 
177  friend Istream& operator>>
178  (
179  Istream& is,
180  labelledPair& lpp
181  )
182  {
183  // Read beginning of labelledPair
184  is.readBegin("labelledPair");
185 
186  is >> lpp.pLabel_;
187  is >> lpp.pair_;
188 
189  // Read end of labelledPair
190  is.readEnd("labelledPair");
191 
192  // Check state of Istream
193  is.check("operator>>(Istream&, labelledPair");
194 
195  return is;
196  }
197 };
198 
199 //- Specify data associated with labelledPair
200 //- type is contiguous
201 template<>
202 inline bool contiguous<labelledPair>() {return true;}
203 
204 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
205 
206 } // End namespace Foam
207 
208 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
209 
210 #endif
211 
212 // ************************************************************************* //
Foam::Istream::readEnd
Istream & readEnd(const char *funcName)
Definition: Istream.C:105
Foam::labelledPair::pair
const labelPair & pair() const
return the pair
Definition: labelledPair.H:91
Foam::labelledPair::operator==
bool operator==(const labelledPair &lpp) const
Definition: labelledPair.H:105
Foam::Pair::first
const Type & first() const
Return first.
Definition: Pair.H:87
Foam::labelledPair
Definition: labelledPair.H:49
Foam::labelledPair::operator=
void operator=(const labelledPair &lpp)
Definition: labelledPair.H:98
Foam::label
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
Foam::contiguous< labelledPair >
bool contiguous< labelledPair >()
Definition: labelledPair.H:201
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::Pair::second
const Type & second() const
Return second.
Definition: Pair.H:99
Foam::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
Foam::labelledPair::~labelledPair
~labelledPair()
Definition: labelledPair.H:80
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::token::BEGIN_LIST
@ BEGIN_LIST
Definition: token.H:100
Foam::labelledPair::pairLabel
label pairLabel() const
return pair label
Definition: labelledPair.H:85
Foam::Pair
An ordered pair of two objects of type <T> with first() and second() elements.
Definition: contiguous.H:49
contiguous.H
Template function to specify if the data of a type are contiguous.
Foam::labelledPair::operator<
bool operator<(const labelledPair &lpp) const
Definition: labelledPair.H:130
Foam::labelledPair::pair_
labelPair pair_
pair data
Definition: labelledPair.H:56
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::Istream::readBegin
Istream & readBegin(const char *funcName)
Definition: Istream.C:88
Foam::labelledPair::pLabel_
label pLabel_
label
Definition: labelledPair.H:53
Foam::min
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::labelledPair::labelledPair
labelledPair()
Null construct.
Definition: labelledPair.H:62
Foam::token::END_LIST
@ END_LIST
Definition: token.H:101
labelPair.H
Foam::token::SPACE
@ SPACE
Definition: token.H:95