///////////////////////////////////////////////////////////////////
/**
* \todo Use boost::mpl library to assert constraints
- * at compiletime! There various like (_IntT is an integral type)
+ * at compiletime! There various like (TInt is an integral type)
* (begin+size < maxbits) or ( field dependent
* constants must be within the range defined by size ).
*/
namespace bit_detail
{
/** Generate constants with \a _size trailing '1'-bits */
- template<class _IntT, unsigned _size>
+ template<class TInt, unsigned _size>
struct Gen1Bits
{
- static const _IntT value = (Gen1Bits<_IntT,_size-1>::value << 1)+1;
+ static const TInt value = (Gen1Bits<TInt,_size-1>::value << 1)+1;
};
/** Specialization for \a _length 0 */
- template<class _IntT>
- struct Gen1Bits<_IntT, 0>
+ template<class TInt>
+ struct Gen1Bits<TInt, 0>
{
- static const _IntT value = 0;
+ static const TInt value = 0;
};
}
- /** Number of bits available in \a _IntT. */
- template<class _IntT>
+ /** Number of bits available in \a TInt. */
+ template<class TInt>
struct MaxBits
{
- typedef _IntT IntT;
+ typedef TInt 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' )
+ template<class TInt>
+ inline std::string asString( TInt val, char zero = '0', char one = '1' )
{
- std::string s( MaxBits<_IntT>::value, zero );
- for( unsigned i = MaxBits<_IntT>::value; i; )
+ std::string s( MaxBits<TInt>::value, zero );
+ for( unsigned i = MaxBits<TInt>::value; i; )
{
--i;
- if ( val & (_IntT)1 )
+ if ( val & (TInt)1 )
s[i] = one;
val = val >> 1;
};
}
/** A bitmaks of \a _size 1-bits starting at bit \a _begin. */
- template<class _IntT, unsigned _begin, unsigned _size>
+ template<class TInt, unsigned _begin, unsigned _size>
struct Mask
{
- typedef _IntT IntT;
+ typedef TInt 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>
+ template<class TInt, unsigned _begin, unsigned _size>
struct Range
{
- typedef _IntT IntT;
+ typedef TInt IntT;
typedef zypp::bit::MaxBits<IntT> MaxBits;
typedef zypp::bit::Mask<IntT,_begin,_size> Mask;
* Force error at compiletime. Currently because types
* and values are undefined
*/
- template<class _IntT, unsigned _begin>
- struct Range<_IntT, _begin, 0>
+ template<class TInt, unsigned _begin>
+ struct Range<TInt, _begin, 0>
{};
/** A value with in a Range.
* RangeValue<SubField,3>::value; // 00001100
* \endcode
*/
- template<class _Range, typename _Range::IntT _value>
+ template<class TRange, typename TRange::IntT _value>
struct RangeValue
{
- typedef _Range RangeT;
- typedef typename _Range::IntT IntT;
+ typedef TRange RangeT;
+ typedef typename TRange::IntT IntT;
static const IntT value = _value << RangeT::begin;
};
* RangeBit<SubField,2>::value; // 00010000
* \endcode
*/
- template<class _Range, unsigned _pos>
+ template<class TRange, unsigned _pos>
struct RangeBit
{
- typedef _Range RangeT;
- typedef typename _Range::IntT IntT;
+ typedef TRange RangeT;
+ typedef typename TRange::IntT IntT;
static const IntT value = IntT(1) << (RangeT::begin + _pos);
};
* bf<SubField>.assign( 0 ); // 11100011
* \endcode
*/
- template<class _IntT>
- class BitField : public Range<_IntT, 0, MaxBits<_IntT>::value>
+ template<class TInt>
+ class BitField : public Range<TInt, 0, MaxBits<TInt>::value>
{
public:
/** Default ctor: zero. */
BitField()
- : _value( (_IntT)0 )
+ : _value( (TInt)0 )
{}
- /** Ctor taking an \a _IntT. */
- BitField( const _IntT & value_r )
+ /** Ctor taking an \a TInt. */
+ BitField( const TInt & value_r )
: _value( value_r )
{}
public:
/** Validate in a boolean context. */
explicit operator bool() const
- { return _value != (_IntT)0; }
+ { return _value != (TInt)0; }
public:
/** Return the value. */
- template<class _Range>
- _IntT value() const
+ template<class TRange>
+ TInt value() const
{
- return _value & _Range::Mask::value;
+ return _value & TRange::Mask::value;
}
- _IntT value() const
+ TInt value() const
{
return _value;
}
/** Value as bit string. */
- template<class _Range>
+ template<class TRange>
std::string asString() const
{
- return bit::asString( _value & _Range::Mask::value, '_' );
+ return bit::asString( _value & TRange::Mask::value, '_' );
}
std::string asString() const
{
}
/** Assign Range in \a rhs to \c this. */
- template<class _Range>
- BitField & assign( _IntT rhs )
+ template<class TRange>
+ BitField & assign( TInt rhs )
{
- _value = (_value & _Range::Mask::inverted)
- | (rhs & _Range::Mask::value);
+ _value = (_value & TRange::Mask::inverted)
+ | (rhs & TRange::Mask::value);
return *this;
}
- BitField & assign( _IntT rhs )
+ BitField & assign( TInt rhs )
{
_value = rhs;
return *this;
}
/** Test for equal value within a Range. */
- template<class _Range>
- bool isEqual( _IntT rhs ) const
+ template<class TRange>
+ bool isEqual( TInt rhs ) const
{
- return (_value & _Range::Mask::value)
- == (rhs & _Range::Mask::value);
+ return (_value & TRange::Mask::value)
+ == (rhs & TRange::Mask::value);
}
- bool isEqual( _IntT rhs ) const
+ bool isEqual( TInt 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 ); }
+ template<class TRange>
+ BitField & set( TInt rhs, bool doset_r )
+ { return set( (rhs & TRange::Mask::value), doset_r ); }
- BitField & set( _IntT rhs, bool doset_r )
+ BitField & set( TInt 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 ); }
+ template<class TRange>
+ BitField & set( TInt rhs )
+ { return set( rhs & TRange::Mask::value ); }
- BitField & set( _IntT rhs )
+ BitField & set( TInt rhs )
{ _value |= rhs; return *this; }
/** Unset bits of \a rhs. */
- template<class _Range>
- BitField & unset( _IntT rhs )
- { return unset( rhs & _Range::Mask::value ); }
+ template<class TRange>
+ BitField & unset( TInt rhs )
+ { return unset( rhs & TRange::Mask::value ); }
- BitField & unset( _IntT rhs )
+ BitField & unset( TInt 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 ); }
+ template<class TRange>
+ bool test( TInt rhs )
+ { return test( rhs & TRange::Mask::value ); }
- bool test( _IntT rhs ) const
+ bool test( TInt 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 ); }
+ template<class TRange>
+ bool testAnyOf( TInt rhs )
+ { return testAnyOf( rhs & TRange::Mask::value ); }
- bool testAnyOf( _IntT rhs ) const
+ bool testAnyOf( TInt rhs ) const
{ return (_value & rhs); }
public:
{ return ~_value; }
private:
- _IntT _value;
+ TInt _value;
};
///////////////////////////////////////////////////////////////////
/** \relates BitField Stream output */
- template<class _IntT>
- std::ostream & operator<<( std::ostream & str, const BitField<_IntT> & obj )
+ template<class TInt>
+ std::ostream & operator<<( std::ostream & str, const BitField<TInt> & obj )
{
return str << obj.asString();
}
/** \relates BitField */
- template<class _IntT>
- inline bool operator==( const BitField<_IntT> & lhs, const BitField<_IntT> & rhs )
+ template<class TInt>
+ inline bool operator==( const BitField<TInt> & lhs, const BitField<TInt> & rhs )
{ return lhs.value() == rhs.value(); }
/** \relates BitField */
- template<class _IntT>
- inline bool operator!=( const BitField<_IntT> & lhs, const BitField<_IntT> & rhs )
+ template<class TInt>
+ inline bool operator!=( const BitField<TInt> & lhs, const BitField<TInt> & 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; }
+ template<class TInt>
+ inline BitField<TInt> operator&( const BitField<TInt> & lhs, const BitField<TInt> & rhs )
+ { return BitField<TInt>(lhs) &= rhs; }
/** \relates BitField */
- template<class _IntT>
- inline BitField<_IntT> operator|( const BitField<_IntT> & lhs, const BitField<_IntT> & rhs )
- { return BitField<_IntT>(lhs) |= rhs; }
+ template<class TInt>
+ inline BitField<TInt> operator|( const BitField<TInt> & lhs, const BitField<TInt> & rhs )
+ { return BitField<TInt>(lhs) |= rhs; }
/** \relates BitField */
- template<class _IntT>
- inline BitField<_IntT> operator^( const BitField<_IntT> & lhs, const BitField<_IntT> & rhs )
- { return BitField<_IntT>(lhs) ^= rhs; }
+ template<class TInt>
+ inline BitField<TInt> operator^( const BitField<TInt> & lhs, const BitField<TInt> & rhs )
+ { return BitField<TInt>(lhs) ^= rhs; }
/** \relates BitField */
- template<class _IntT>
- inline BitField<_IntT> operator<<( const BitField<_IntT> & lhs, unsigned num )
- { return BitField<_IntT>(lhs) <<= num; }
+ template<class TInt>
+ inline BitField<TInt> operator<<( const BitField<TInt> & lhs, unsigned num )
+ { return BitField<TInt>(lhs) <<= num; }
/** \relates BitField */
- template<class _IntT>
- inline BitField<_IntT> operator>>( const BitField<_IntT> & lhs, unsigned num )
- { return BitField<_IntT>(lhs) >>= num; }
+ template<class TInt>
+ inline BitField<TInt> operator>>( const BitField<TInt> & lhs, unsigned num )
+ { return BitField<TInt>(lhs) >>= num; }
/////////////////////////////////////////////////////////////////
} // namespace bit