initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / meshTools / indexedOctree / labelBits.H
blob28847b6baa364aba305bf36e800a0c16d48a99ab
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 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 direction packed into single label
31 SourceFiles
33 \*---------------------------------------------------------------------------*/
35 #ifndef labelBits_H
36 #define labelBits_H
38 #include "label.H"
39 #include "uLabel.H"
40 #include "direction.H"
41 #include "error.H"
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 namespace Foam
49 /*---------------------------------------------------------------------------*\
50                          Class labelBits Declaration
51 \*---------------------------------------------------------------------------*/
53 class labelBits
55     // Private data
57         label data_;
59         inline static label pack(const label val, const direction bits)
60         {
61 #           ifdef FULLDEBUG
62             if (bits > 7 || (((val<<3)>>3) != val))
63             {
64                 FatalErrorIn
65                 (
66                     "labelBits::pack(const label, const direction)"
67                 )   << "Direction " << bits << " outside range 0..7"
68                     << abort(FatalError);
69             }
70 #           endif
72             return (val<<3) | bits;
73         }
75 public:
77     // Constructors
79         //- Construct null
80         inline labelBits()
81         {}
83         //- Construct from components
84         inline labelBits(const label val, const direction bits)
85         :
86              data_(pack(val, bits))
87         {}
89         //- Construct from Istream
90         inline labelBits(Istream& is)
91         {
92             is >> data_;
93         }
97     // Member Functions
99         inline label val() const
100         {
101             return data_ >> 3;
102         }
104         inline direction bits() const
105         {
106             return data_ & 7;
107         }
109         inline void setVal(const label val)
110         {
111             data_ = pack(val, bits());
112         }
114         inline void setBits(const direction bits)
115         {
116             data_ = pack(val(), bits);
117         }
120     // Member Operators
122         friend inline bool operator==(const labelBits& a, const labelBits& b)
123         {
124             return a.data_ == b.data_;
125         }
127         friend inline bool operator!=(const labelBits& a, const labelBits& b)
128         {
129             return !(a == b);
130         }
132     // IOstream Operators
134         friend inline Istream& operator>>(Istream& is, labelBits& lb)
135         {
136             return is >> lb.data_;
137         }
139         friend inline Ostream& operator<<(Ostream& os, const labelBits& lb)
140         {
141             return os << lb.data_;
142         }
146 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
148 } // End namespace Foam
150 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
152 #endif
154 // ************************************************************************* //