1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 A 29bits label and 3bits direction packed into single label
33 \*---------------------------------------------------------------------------*/
40 #include "direction.H"
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 /*---------------------------------------------------------------------------*\
50 Class labelBits Declaration
51 \*---------------------------------------------------------------------------*/
59 inline static label pack(const label val, const direction bits)
62 if (bits > 7 || (((val<<3)>>3) != val))
66 "labelBits::pack(const label, const direction)"
67 ) << "Direction " << bits << " outside range 0..7"
72 return (val<<3) | bits;
83 //- Construct from components
84 inline labelBits(const label val, const direction bits)
86 data_(pack(val, bits))
89 //- Construct from Istream
90 inline labelBits(Istream& is)
99 inline label val() const
104 inline direction bits() const
109 inline void setVal(const label val)
111 data_ = pack(val, bits());
114 inline void setBits(const direction bits)
116 data_ = pack(val(), bits);
122 friend inline bool operator==(const labelBits& a, const labelBits& b)
124 return a.data_ == b.data_;
127 friend inline bool operator!=(const labelBits& a, const labelBits& b)
132 // IOstream Operators
134 friend inline Istream& operator>>(Istream& is, labelBits& lb)
136 return is >> lb.data_;
139 friend inline Ostream& operator<<(Ostream& os, const labelBits& lb)
141 return os << lb.data_;
146 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
148 } // End namespace Foam
150 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
154 // ************************************************************************* //