/usr/include/x86_64-linux-gnu/zypp/Bit.h is in libzypp-dev 15.3.0-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 | /*---------------------------------------------------------------------\
| ____ _ __ __ ___ |
| |__ / \ / / . \ . \ |
| / / \ V /| _/ _/ |
| / /__ | | | | | | |
| /_____||_| |_| |_| |
| |
\---------------------------------------------------------------------*/
/** \file zypp/Bit.h
*
*/
#ifndef ZYPP_BIT_H
#define ZYPP_BIT_H
#include <iosfwd>
#include <string>
///////////////////////////////////////////////////////////////////
namespace zypp
{ /////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
/**
* \todo Use boost::mpl library to assert constraints
* at compiletime! There various like (_IntT is an integral type)
* (begin+size < maxbits) or ( field dependent
* constants must be within the range defined by size ).
*/
namespace bit
{ /////////////////////////////////////////////////////////////////
namespace bit_detail
{
/** Generate constants with \a _size trailing '1'-bits */
template<class _IntT, unsigned _size>
struct Gen1Bits
{
static const _IntT value = (Gen1Bits<_IntT,_size-1>::value << 1)+1;
};
/** Specialization for \a _length 0 */
template<class _IntT>
struct Gen1Bits<_IntT, 0>
{
static const _IntT value = 0;
};
}
/** Number of bits available in \a _IntT. */
template<class _IntT>
struct MaxBits
{
typedef _IntT IntT;
static const unsigned value = (sizeof(IntT)*8);
};
/** For printing bits. */
template<class _IntT>
inline std::string asString( _IntT val, char zero = '0', char one = '1' )
{
std::string s( MaxBits<_IntT>::value, zero );
for( unsigned i = MaxBits<_IntT>::value; i; )
{
--i;
if ( val & (_IntT)1 )
s[i] = one;
val = val >> 1;
};
return s;
}
/** A bitmaks of \a _size 1-bits starting at bit \a _begin. */
template<class _IntT, unsigned _begin, unsigned _size>
struct Mask
{
typedef _IntT IntT;
static const IntT value = bit_detail::Gen1Bits<IntT,_size>::value << _begin;
static const IntT inverted = ~value;
};
/** Range of bits starting at bit \a _begin with length \a _size. */
template<class _IntT, unsigned _begin, unsigned _size>
struct Range
{
typedef _IntT IntT;
typedef zypp::bit::MaxBits<IntT> MaxBits;
typedef zypp::bit::Mask<IntT,_begin,_size> Mask;
static const unsigned begin = _begin;
static const unsigned size = _size;
static const unsigned end = _begin + _size;
};
/** Range specialisation for (illegal) zero \a _size.
* Force error at compiletime. Currently because types
* and values are undefined
*/
template<class _IntT, unsigned _begin>
struct Range<_IntT, _begin, 0>
{};
/** A value with in a Range.
* \code
* typedef Range<char,2,3> SubField; // bits 2,3,4 in a char field
* SubField::Mask::value; // 00011100
* RangeValue<SubField,0>::value; // 00000000
* RangeValue<SubField,1>::value; // 00000100
* RangeValue<SubField,2>::value; // 00001000
* RangeValue<SubField,3>::value; // 00001100
* \endcode
*/
template<class _Range, typename _Range::IntT _value>
struct RangeValue
{
typedef _Range RangeT;
typedef typename _Range::IntT IntT;
static const IntT value = _value << RangeT::begin;
};
/** A single 1-bit within a Range.
* \code
* typedef Range<char,2,3> SubField; // bits 2,3,4 in a char field
* SubField::Mask::value; // 00011100
* RangeBit<SubField,0>::value; // 00000100
* RangeBit<SubField,1>::value; // 00001000
* RangeBit<SubField,2>::value; // 00010000
* \endcode
*/
template<class _Range, unsigned _pos>
struct RangeBit
{
typedef _Range RangeT;
typedef typename _Range::IntT IntT;
static const IntT value = IntT(1) << (RangeT::begin + _pos);
};
///////////////////////////////////////////////////////////////////
//
// CLASS NAME : BitField
//
/** An integral type used as BitField.
*
* Most methods exist as templated and nontemplated
* version. The nontemplated operates on the complete
* BitField, while the tamplated ones are restricted
* to the given Range.
* \code
* BitField<char> bf; // 00000000
* typedef Range<char,2,3> SubField; // bits 2,3,4 in a char field
*
* bf<SubField>.assign( -1 ); // assign SubField in -1
* // to SubField in bf.
* // 00011100
* bf.assign( -1 ); // assign -1 to bf
* // 11111111
* bf<SubField>.assign( 0 ); // 11100011
* \endcode
*/
template<class _IntT>
class BitField : public Range<_IntT, 0, MaxBits<_IntT>::value>
{
public:
/** Default ctor: zero. */
BitField()
: _value( (_IntT)0 )
{}
/** Ctor taking an \a _IntT. */
BitField( const _IntT & value_r )
: _value( value_r )
{}
public:
/** Validate in a boolean context. */
explicit operator bool() const
{ return _value != (_IntT)0; }
public:
/** Return the value. */
template<class _Range>
_IntT value() const
{
return _value & _Range::Mask::value;
}
_IntT value() const
{
return _value;
}
/** Value as bit string. */
template<class _Range>
std::string asString() const
{
return bit::asString( _value & _Range::Mask::value, '_' );
}
std::string asString() const
{
return bit::asString( _value, '_' );
}
/** Assign Range in \a rhs to \c this. */
template<class _Range>
BitField & assign( _IntT rhs )
{
_value = (_value & _Range::Mask::inverted)
| (rhs & _Range::Mask::value);
return *this;
}
BitField & assign( _IntT rhs )
{
_value = rhs;
return *this;
}
/** Test for equal value within a Range. */
template<class _Range>
bool isEqual( _IntT rhs ) const
{
return (_value & _Range::Mask::value)
== (rhs & _Range::Mask::value);
}
bool isEqual( _IntT rhs ) const
{
return _value == rhs;
}
public:
/** Set or unset bits of \a rhs. */
template<class _Range>
BitField & set( _IntT rhs, bool doset_r )
{ return set( (rhs & _Range::Mask::value), doset_r ); }
BitField & set( _IntT rhs, bool doset_r )
{ return doset_r ? set( rhs ) : unset( rhs ); }
/** Set bits of \a rhs. */
template<class _Range>
BitField & set( _IntT rhs )
{ return set( rhs & _Range::Mask::value ); }
BitField & set( _IntT rhs )
{ _value |= rhs; return *this; }
/** Unset bits of \a rhs. */
template<class _Range>
BitField & unset( _IntT rhs )
{ return unset( rhs & _Range::Mask::value ); }
BitField & unset( _IntT rhs )
{ _value &= ~rhs; return *this; }
/** Test whether \b all bits of \a rhs are set. */
template<class _Range>
bool test( _IntT rhs )
{ return test( rhs & _Range::Mask::value ); }
bool test( _IntT rhs ) const
{ return (_value & rhs) == rhs; }
/** Test whether \b at \b least \b one bit of \a rhs is set. */
template<class _Range>
bool testAnyOf( _IntT rhs )
{ return testAnyOf( rhs & _Range::Mask::value ); }
bool testAnyOf( _IntT rhs ) const
{ return (_value & rhs); }
public:
BitField & operator=( const BitField & rhs )
{ _value = rhs._value; return *this; }
BitField & operator&=( const BitField & rhs )
{ _value &= rhs._value; return *this; }
BitField & operator|=( const BitField & rhs )
{ _value |= rhs._value; return *this; }
BitField & operator^=( const BitField & rhs )
{ _value ^= rhs._value; return *this; }
BitField & operator<<=( unsigned num )
{ _value <<= num; return *this; }
BitField & operator>>=( unsigned num )
{ _value >>= num; return *this; }
BitField operator~() const
{ return ~_value; }
private:
_IntT _value;
};
///////////////////////////////////////////////////////////////////
/** \relates BitField Stream output */
template<class _IntT>
std::ostream & operator<<( std::ostream & str, const BitField<_IntT> & obj )
{
return str << obj.asString();
}
/** \relates BitField */
template<class _IntT>
inline bool operator==( const BitField<_IntT> & lhs, const BitField<_IntT> & rhs )
{ return lhs.value() == rhs.value(); }
/** \relates BitField */
template<class _IntT>
inline bool operator!=( const BitField<_IntT> & lhs, const BitField<_IntT> & rhs )
{ return ! (lhs == rhs); }
/** \relates BitField */
template<class _IntT>
inline BitField<_IntT> operator&( const BitField<_IntT> & lhs, const BitField<_IntT> & rhs )
{ return BitField<_IntT>(lhs) &= rhs; }
/** \relates BitField */
template<class _IntT>
inline BitField<_IntT> operator|( const BitField<_IntT> & lhs, const BitField<_IntT> & rhs )
{ return BitField<_IntT>(lhs) |= rhs; }
/** \relates BitField */
template<class _IntT>
inline BitField<_IntT> operator^( const BitField<_IntT> & lhs, const BitField<_IntT> & rhs )
{ return BitField<_IntT>(lhs) ^= rhs; }
/** \relates BitField */
template<class _IntT>
inline BitField<_IntT> operator<<( const BitField<_IntT> & lhs, unsigned num )
{ return BitField<_IntT>(lhs) <<= num; }
/** \relates BitField */
template<class _IntT>
inline BitField<_IntT> operator>>( const BitField<_IntT> & lhs, unsigned num )
{ return BitField<_IntT>(lhs) >>= num; }
/////////////////////////////////////////////////////////////////
} // namespace bit
///////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
} // namespace zypp
///////////////////////////////////////////////////////////////////
#endif // ZYPP_BIT_H
|