porting changes
[OpenFOAM-1.5.x.git] / src / meshTools / indexedOctree / labelBits.H
blob934ecbef4a129bea399bc976df941f14d41be3af
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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
25 Class
26     Foam::labelBits
28 Description
29     A 29bits label and 3bits packed into single label
31 SourceFiles
33 \*---------------------------------------------------------------------------*/
35 #ifndef labelBits_H
36 #define labelBits_H
38 #include "label.H"
39 #include "direction.H"
40 #include "error.H"
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 namespace Foam
48 /*---------------------------------------------------------------------------*\
49                          Class labelBits Declaration
50 \*---------------------------------------------------------------------------*/
52 class labelBits
54     // Private data
56         label data_;
58         inline static label pack(const label val, const direction bits)
59         {
60 #           ifdef FULLDEBUG
61             if (bits > 7 || (((val<<3)>>3) != val))
62             {
63                 FatalErrorIn
64                 (
65                     "labelBits::pack(const label, const direction)"
66                 )   << "Direction " << bits << " outside range 0..7"
67                     << abort(FatalError);
68             }
69 #           endif
71             return (val<<3) | bits;
72         }
74 public:
76     // Constructors
78         //- Construct null
79         inline labelBits()
80         {}
82         //- Construct from components
83         inline labelBits(const label val, const direction bits)
84         :
85              data_(pack(val, bits))
86         {}
88         //- Construct from Istream
89         inline labelBits(Istream& is)
90         {
91             is >> data_;
92         }
96     // Member Functions
98         inline label val() const
99         {
100             return data_ >> 3;
101         }
103         inline direction bits() const
104         {
105             return data_ & 7;
106         }
108         inline void setVal(const label val)
109         {
110             data_ = pack(val, bits());
111         }
113         inline void setBits(const direction bits)
114         {
115             data_ = pack(val(), bits);
116         }
119     // Member Operators
121         friend inline bool operator==(const labelBits& a, const labelBits& b)
122         {
123             return a.data_ == b.data_;
124         }
126         friend inline bool operator!=(const labelBits& a, const labelBits& b)
127         {
128             return !(a == b);
129         }
131     // IOstream Operators
133         friend inline Istream& operator>>(Istream& is, labelBits& lb)
134         {
135             return is >> lb.data_;
136         }
137         
138         friend inline Ostream& operator<<(Ostream& os, const labelBits& lb)
139         {
140             return os << lb.data_;
141         }
145 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
147 } // End namespace Foam
149 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
151 #endif
153 // ************************************************************************* //