Loading...
Searching...
No Matches
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 Copyright (C) 2022 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Class
28 Foam::labelBits
29
30Description
31 A 29bits (or 61bits) integer label with 3bits direction
32 (eg, octant) packed into single label
33
34\*---------------------------------------------------------------------------*/
35
36#ifndef Foam_labelBits_H
37#define Foam_labelBits_H
38
39#include "label.H"
40#include "direction.H"
41#include "error.H"
42
43// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44
45namespace Foam
46{
47
48// Forward Declarations
49class labelBits;
50
51/*---------------------------------------------------------------------------*\
52 Class labelBits Declaration
53\*---------------------------------------------------------------------------*/
54
55class labelBits
56{
57 // Private Data
58
59 //- Integer value and (octant) direction
60 label data_;
61
62public:
63
64 // Static Functions
65
66 #ifdef FULLDEBUG
67
68 //- Pack integer value and bits (octant) into a label
69 inline static label pack
70 (
71 const label val,
72 const direction bits
73 )
74 {
75 if (bits > 7 || (((val<<3)>>3) != val))
76 {
78 << "Direction " << bits << " outside range 0..7"
79 << " or value " << val << " negative or larger than "
80 << label(8*sizeof(label)-3) << " bit representation"
81 << abort(FatalError);
82 }
83 return (val<<3) | bits;
84 }
85
86 #else
87
88 //- Pack integer value and bits (octant) into a label
89 static constexpr label pack
90 (
91 const label val,
92 const direction bits
93 ) noexcept
94 {
95 return (val<<3) | bits;
96 }
97
98 #endif
99
100
101 // Constructors
102
103 //- Default construct as zero initialized
104 constexpr labelBits() noexcept
106 data_(0)
107 {}
108
109 //- Construct from components
110 labelBits(const label val, const direction bits)
111 :
112 data_(pack(val, bits))
113 {}
114
115 //- Read construct from Istream
116 explicit labelBits(Istream& is)
117 {
118 is >> data_;
119 }
120
122 // Member Functions
123
124 //- The raw data value
125 label data() const noexcept { return data_; }
126
127 //- Return the integer value
128 label val() const noexcept { return (data_ >> 3); }
129
130 //- Return the octant direction
131 direction bits() const noexcept { return (data_ & 7); }
133 //- Set the integer value
134 void setVal(const label val)
135 {
136 data_ = pack(val, bits());
138
139 //- Set the octant direction
140 void setBits(const direction bits)
141 {
142 data_ = pack(val(), bits);
143 }
144
145
146 // Member Operators
148 inline friend
149 bool operator==(const labelBits& a, const labelBits& b)
150 {
151 return a.data_ == b.data_;
152 }
153
154 inline friend
155 bool operator!=(const labelBits& a, const labelBits& b)
156 {
157 return !(a == b);
158 }
159
160
161 // IOstream Operators
162
163 inline friend
165 {
166 return is >> rhs.data_;
167 }
168
169 inline friend
171 {
172 return os << rhs.data_;
173 }
174};
175
176
177// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
178
179} // End namespace Foam
180
181// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
182
183#endif
184
185// ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
A 29bits (or 61bits) integer label with 3bits direction (eg, octant) packed into single label.
Definition labelBits.H:49
void setBits(const direction bits)
Set the octant direction.
Definition labelBits.H:155
labelBits(Istream &is)
Read construct from Istream.
Definition labelBits.H:121
friend bool operator!=(const labelBits &a, const labelBits &b)
Definition labelBits.H:170
labelBits(const label val, const direction bits)
Construct from components.
Definition labelBits.H:113
direction bits() const noexcept
Return the octant direction.
Definition labelBits.H:142
static constexpr label pack(const label val, const direction bits) noexcept
Pack integer value and bits (octant) into a label.
Definition labelBits.H:89
constexpr labelBits() noexcept
Default construct as zero initialized.
Definition labelBits.H:105
label data() const noexcept
The raw data value.
Definition labelBits.H:132
label val() const noexcept
Return the integer value.
Definition labelBits.H:137
friend Istream & operator>>(Istream &is, labelBits &rhs)
Definition labelBits.H:179
friend Ostream & operator<<(Ostream &os, const labelBits &rhs)
Definition labelBits.H:185
friend bool operator==(const labelBits &a, const labelBits &b)
Definition labelBits.H:164
void setVal(const label val)
Set the integer value.
Definition labelBits.H:147
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:600
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
errorManip< error > abort(error &err)
Definition errorManip.H:139
uint8_t direction
Definition direction.H:49
void rhs(fvMatrix< typename Expr::value_type > &m, const Expr &expression)
const direction noexcept
Definition scalarImpl.H:265
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
volScalarField & b