#include <iosfwd>
#include <string>
-#include "zypp/base/SafeBool.h"
-
///////////////////////////////////////////////////////////////////
namespace zypp
{ /////////////////////////////////////////////////////////////////
/** Number of bits available in \a _IntT. */
template<class _IntT>
- struct MaxBitsT
+ struct MaxBits
{
typedef _IntT IntT;
static const unsigned value = (sizeof(IntT)*8);
template<class _IntT>
inline std::string asString( _IntT val, char zero = '0', char one = '1' )
{
- std::string s( MaxBitsT<_IntT>::value, zero );
- for( unsigned i = MaxBitsT<_IntT>::value; i; )
+ std::string s( MaxBits<_IntT>::value, zero );
+ for( unsigned i = MaxBits<_IntT>::value; i; )
{
--i;
if ( val & (_IntT)1 )
/** A bitmaks of \a _size 1-bits starting at bit \a _begin. */
template<class _IntT, unsigned _begin, unsigned _size>
- struct MaskT
+ struct Mask
{
typedef _IntT IntT;
static const IntT value = bit_detail::Gen1Bits<IntT,_size>::value << _begin;
struct Range
{
typedef _IntT IntT;
- typedef MaxBitsT<IntT> MaxBits;
- typedef MaskT<IntT,_begin,_size> Mask;
+ typedef zypp::bit::MaxBits<IntT> MaxBits;
+ typedef zypp::bit::Mask<IntT,_begin,_size> Mask;
static const unsigned begin = _begin;
static const unsigned size = _size;
* \endcode
*/
template<class _IntT>
- class BitField : public Range<_IntT, 0, MaxBitsT<_IntT>::value>
- , private base::SafeBool<BitField<_IntT> >
+ class BitField : public Range<_IntT, 0, MaxBits<_IntT>::value>
{
- typedef typename base::SafeBool<BitField<_IntT> >::bool_type bool_type;
-
public:
/** Default ctor: zero. */
BitField()
public:
/** Validate in a boolean context. */
- using base::SafeBool<BitField<_IntT> >::operator bool_type;
+ explicit operator bool() const
+ { return _value != (_IntT)0; }
public:
/** Return the value. */
{
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 )
{ return ~_value; }
private:
- friend base::SafeBool<BitField<_IntT> >::operator bool_type() const;
- /** \ref base::SafeBool test. */
- bool boolTest() const
- { return _value; }
-
- private:
_IntT _value;
};
///////////////////////////////////////////////////////////////////