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 -------------------------------------------------------------------------------
10 License
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 
26 Class
27  Foam::labelBits
28 
29 Description
30  A 29bits label and 3bits direction packed into single label
31 
32 SourceFiles
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 
46 namespace Foam
47 {
48 
49 
50 /*---------------------------------------------------------------------------*\
51  Class labelBits Declaration
52 \*---------------------------------------------------------------------------*/
53 
54 class 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 
76 public:
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
99 
100  inline label val() const
101  {
102  return data_ >> 3;
103  }
104 
105  inline direction bits() const
106  {
107  return data_ & 7;
108  }
109 
110  inline void setVal(const label val)
111  {
112  data_ = pack(val, bits());
113  }
114 
115  inline void setBits(const direction bits)
116  {
117  data_ = pack(val(), bits);
118  }
119 
120 
121  // Member Operators
122 
123  inline friend bool operator==(const labelBits& a, const labelBits& b)
124  {
125  return a.data_ == b.data_;
126  }
127 
128  inline friend bool operator!=(const labelBits& a, const labelBits& b)
129  {
130  return !(a == b);
131  }
132 
133  // IOstream Operators
134 
135  inline friend Istream& operator>>(Istream& is, labelBits& lb)
136  {
137  return is >> lb.data_;
138  }
139 
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 // ************************************************************************* //
Foam::labelBits::operator!=
friend bool operator!=(const labelBits &a, const labelBits &b)
Definition: labelBits.H:127
Foam::labelBits
A 29bits label and 3bits direction packed into single label.
Definition: labelBits.H:53
Foam::labelBits::labelBits
labelBits()
Construct null.
Definition: labelBits.H:80
Foam::labelBits::labelBits
labelBits(const label val, const direction bits)
Construct from components.
Definition: labelBits.H:84
Foam::labelBits::bits
direction bits() const
Definition: labelBits.H:104
Foam::labelBits::operator>>
friend Istream & operator>>(Istream &is, labelBits &lb)
Definition: labelBits.H:134
Foam::constant::physicoChemical::b
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
error.H
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::labelBits::operator==
friend bool operator==(const labelBits &a, const labelBits &b)
Definition: labelBits.H:122
Foam::labelBits::setBits
void setBits(const direction bits)
Definition: labelBits.H:114
Foam::labelBits::labelBits
labelBits(Istream &is)
Construct from Istream.
Definition: labelBits.H:90
Foam::labelBits::val
label val() const
Definition: labelBits.H:99
Foam::FatalError
error FatalError
os
OBJstream os(runTime.globalPath()/outputName)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
direction.H
Direction is an 8-bit unsigned integer type used to represent Cartesian directions,...
Foam::labelBits::setVal
void setVal(const label val)
Definition: labelBits.H:109
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
label.H
Foam::direction
uint8_t direction
Definition: direction.H:52
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::labelBits::operator<<
friend Ostream & operator<<(Ostream &os, const labelBits &lb)
Definition: labelBits.H:139