labelBits.H
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef labelBits_H
00036 #define labelBits_H
00037
00038 #include "label.H"
00039 #include "uLabel.H"
00040 #include "direction.H"
00041 #include "error.H"
00042
00043
00044
00045 namespace Foam
00046 {
00047
00048
00049
00050
00051
00052
00053 class labelBits
00054 {
00055
00056
00057 label data_;
00058
00059 inline static label pack(const label val, const direction bits)
00060 {
00061 # ifdef FULLDEBUG
00062 if (bits > 7 || (((val<<3)>>3) != val))
00063 {
00064 FatalErrorIn
00065 (
00066 "labelBits::pack(const label, const direction)"
00067 ) << "Direction " << bits << " outside range 0..7"
00068 << abort(FatalError);
00069 }
00070 # endif
00071
00072 return (val<<3) | bits;
00073 }
00074
00075 public:
00076
00077
00078
00079
00080 inline labelBits()
00081 {}
00082
00083
00084 inline labelBits(const label val, const direction bits)
00085 :
00086 data_(pack(val, bits))
00087 {}
00088
00089
00090 inline labelBits(Istream& is)
00091 {
00092 is >> data_;
00093 }
00094
00095
00096
00097
00098
00099 inline label val() const
00100 {
00101 return data_ >> 3;
00102 }
00103
00104 inline direction bits() const
00105 {
00106 return data_ & 7;
00107 }
00108
00109 inline void setVal(const label val)
00110 {
00111 data_ = pack(val, bits());
00112 }
00113
00114 inline void setBits(const direction bits)
00115 {
00116 data_ = pack(val(), bits);
00117 }
00118
00119
00120
00121
00122 friend inline bool operator==(const labelBits& a, const labelBits& b)
00123 {
00124 return a.data_ == b.data_;
00125 }
00126
00127 friend inline bool operator!=(const labelBits& a, const labelBits& b)
00128 {
00129 return !(a == b);
00130 }
00131
00132
00133
00134 friend inline Istream& operator>>(Istream& is, labelBits& lb)
00135 {
00136 return is >> lb.data_;
00137 }
00138
00139 friend inline Ostream& operator<<(Ostream& os, const labelBits& lb)
00140 {
00141 return os << lb.data_;
00142 }
00143 };
00144
00145
00146
00147
00148 }
00149
00150
00151
00152 #endif
00153
00154
Copyright © 2000-2009 OpenCFD Ltd