labelBits.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) 2011-2016 OpenFOAM Foundation
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26Class
27 Foam::labelBits
28
29Description
30 A 29bits label and 3bits direction packed into single label
31
32SourceFiles
33
34\*---------------------------------------------------------------------------*/
35
36#ifndef labelBits_H
37#define labelBits_H
38
39#include "label.H"
40//#include "uLabel.H"
41#include "direction.H"
42#include "error.H"
43
44// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45
46namespace Foam
47{
48
49
50/*---------------------------------------------------------------------------*\
51 Class labelBits Declaration
52\*---------------------------------------------------------------------------*/
54class labelBits
55{
56 // Private data
57
58 label data_;
59
60 inline static label pack(const label val, const direction bits)
61 {
62 #ifdef FULLDEBUG
63 if (bits > 7 || (((val<<3)>>3) != val))
64 {
66 << "Direction " << bits << " outside range 0..7"
67 << " or value " << val << " negative or larger than "
68 << label(8*sizeof(label)-3) << " bit representation"
69 << abort(FatalError);
70 }
71 #endif
72
73 return (val<<3) | bits;
74 }
75
76public:
77
78 // Constructors
79
80 //- Construct null
81 inline labelBits()
82 {}
83
84 //- Construct from components
85 inline labelBits(const label val, const direction bits)
86 :
87 data_(pack(val, bits))
88 {}
89
90 //- Construct from Istream
91 inline labelBits(Istream& is)
92 {
93 is >> data_;
94 }
95
96
97
98 // Member Functions
100 inline label val() const
101 {
102 return data_ >> 3;
103 }
105 inline direction bits() const
106 {
107 return data_ & 7;
108 }
110 inline void setVal(const label val)
111 {
112 data_ = pack(val, bits());
113 }
115 inline void setBits(const direction bits)
116 {
117 data_ = pack(val(), bits);
118 }
119
120
121 // Member Operators
123 inline friend bool operator==(const labelBits& a, const labelBits& b)
124 {
125 return a.data_ == b.data_;
126 }
128 inline friend bool operator!=(const labelBits& a, const labelBits& b)
129 {
130 return !(a == b);
131 }
132
133 // IOstream Operators
135 inline friend Istream& operator>>(Istream& is, labelBits& lb)
136 {
137 return is >> lb.data_;
138 }
140 inline friend Ostream& operator<<(Ostream& os, const labelBits& lb)
141 {
142 return os << lb.data_;
143 }
144};
145
146
147// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
148
149} // End namespace Foam
150
151// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
152
153#endif
154
155// ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
A 29bits label and 3bits direction packed into single label.
Definition: labelBits.H:54
void setBits(const direction bits)
Definition: labelBits.H:114
labelBits(Istream &is)
Construct from Istream.
Definition: labelBits.H:90
friend bool operator!=(const labelBits &a, const labelBits &b)
Definition: labelBits.H:127
labelBits(const label val, const direction bits)
Construct from components.
Definition: labelBits.H:84
label val() const
Definition: labelBits.H:99
friend Ostream & operator<<(Ostream &os, const labelBits &lb)
Definition: labelBits.H:139
direction bits() const
Definition: labelBits.H:104
labelBits()
Construct null.
Definition: labelBits.H:80
friend Istream & operator>>(Istream &is, labelBits &lb)
Definition: labelBits.H:134
friend bool operator==(const labelBits &a, const labelBits &b)
Definition: labelBits.H:122
void setVal(const label val)
Definition: labelBits.H:109
Direction is an 8-bit unsigned integer type used to represent Cartesian directions,...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
errorManip< error > abort(error &err)
Definition: errorManip.H:144
uint8_t direction
Definition: direction.H:56
error FatalError
volScalarField & b
Definition: createFields.H:27