labelBits.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::labelBits
26 
27 Description
28  A 29bits label and 3bits direction packed into single label
29 
30 SourceFiles
31 
32 \*---------------------------------------------------------------------------*/
33 
34 #ifndef labelBits_H
35 #define labelBits_H
36 
37 #include "label.H"
38 //#include "uLabel.H"
39 #include "direction.H"
40 #include "error.H"
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46 
47 
48 /*---------------------------------------------------------------------------*\
49  Class labelBits Declaration
50 \*---------------------------------------------------------------------------*/
51 
52 class labelBits
53 {
54  // Private Data
55 
56  label data_;
57 
58  inline static label pack(const label val, const direction bits)
59  {
60  #ifdef FULLDEBUG
61  if (bits > 7 || (((val<<3)>>3) != val))
62  {
64  << "Direction " << bits << " outside range 0..7"
65  << " or value " << val << " negative or larger than "
66  << label(8*sizeof(label)-3) << " bit representation"
67  << abort(FatalError);
68  }
69  #endif
70 
71  return (val<<3) | bits;
72  }
73 
74 public:
75 
76  // Constructors
77 
78  //- Construct null
79  inline labelBits()
80  {}
81 
82  //- Construct from components
83  inline labelBits(const label val, const direction bits)
84  :
85  data_(pack(val, bits))
86  {}
87 
88  //- Construct from Istream
89  inline labelBits(Istream& is)
90  {
91  is >> data_;
92  }
93 
94 
95 
96  // Member Functions
97 
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  }
117 
118 
119  // Member Operators
121  inline friend bool operator==(const labelBits& a, const labelBits& b)
122  {
123  return a.data_ == b.data_;
124  }
126  inline friend bool operator!=(const labelBits& a, const labelBits& b)
127  {
128  return !(a == b);
129  }
130 
131  // IOstream Operators
133  inline friend Istream& operator>>(Istream& is, labelBits& lb)
134  {
135  return is >> lb.data_;
136  }
138  inline friend Ostream& operator<<(Ostream& os, const labelBits& lb)
139  {
140  return os << lb.data_;
141  }
142 };
143 
144 
145 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
146 
147 } // End namespace Foam
148 
149 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
150 
151 #endif
152 
153 // ************************************************************************* //
FvWallInfoData< WallInfo, label > label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
error FatalError
friend Istream & operator>>(Istream &is, labelBits &lb)
Definition: labelBits.H:132
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
uint8_t direction
Definition: direction.H:45
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
const dimensionedScalar b
Wien displacement law constant: default SI units: [m K].
Definition: createFields.H:27
friend Ostream & operator<<(Ostream &os, const labelBits &lb)
Definition: labelBits.H:137
void setVal(const label val)
Definition: labelBits.H:107
labelBits()
Construct null.
Definition: labelBits.H:78
void setBits(const direction bits)
Definition: labelBits.H:112
direction bits() const
Definition: labelBits.H:102
errorManip< error > abort(error &err)
Definition: errorManip.H:131
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
friend bool operator==(const labelBits &a, const labelBits &b)
Definition: labelBits.H:120
friend bool operator!=(const labelBits &a, const labelBits &b)
Definition: labelBits.H:125
Direction is an 8-bit unsigned integer type used to represent the Cartesian directions etc...
A 29bits label and 3bits direction packed into single label.
Definition: labelBits.H:51
label val() const
Definition: labelBits.H:97
Namespace for OpenFOAM.