#include <zypp/source/susetags/SuseTagsImpl.h>
#include <zypp/ResFilters.h>
+#include <zypp/ResStatus.h>
+#include <zypp/Bit.h>
using namespace std;
using namespace zypp;
///////////////////////////////////////////////////////////////////
-
-bool all( const ResObject::Ptr & )
-{ return true; }
-
-bool doPrintM( const ResObject::Ptr & p )
+namespace zypp
{
- MIL << *p << endl;
- return true;
-}
-bool doPrint( const ResObject::Ptr & p )
-{
- DBG << *p << endl;
- return true;
}
+///////////////////////////////////////////////////////////////////
-struct Print
+namespace zypp
{
- Print( const std::string & name_r )
- : _name( name_r )
- {}
- std::string _name;
- bool operator()( ResObject::Ptr p ) const
+ /** Status bitfield.
+ *
+ * \li \c StateField Whether the resolvable is installed
+ * or uninstalled (available).
+ * \li \c FreshenField Freshen status computed by the solver.
+ * \li \c TransactField Wheter to transact this resolvable
+ * (delete if installed install if uninstalled).
+ * \li \c TransactByField Who triggered the transaction. Transaction
+ * bit may be reset by higer levels only.
+ * \li \c TransactDetailField Reason why the Resolvable transacts.
+ * Splitted into \c InstallDetailValue and \c RemoveDetailValue
+ * dependent on the kind of transaction.
+ */
+ class ResStatus
{
- DBG << _name << endl;
- return true;
- }
-};
+ typedef char FieldType;
+ // Bit Ranges within FieldType defined by 1st bit and size:
+ typedef bit::Range<FieldType,0, 1> StateField;
+ typedef bit::Range<FieldType,StateField::end, 2> FreshenField;
+ typedef bit::Range<FieldType,FreshenField::end, 1> TransactField;
+ typedef bit::Range<FieldType,TransactField::end, 2> TransactByField;
+ typedef bit::Range<FieldType,TransactByField::end, 2> TransactDetailField;
+ // enlarge FieldType if more bit's needed. It's not yet
+ // checked by the compiler.
+ public:
+
+ enum StateValue
+ {
+ UNINSTALLED = 0,
+ INSTALLED = StateField::minval
+ };
+ enum FreshenValue
+ {
+ UNDETERMINED = 0,
+ NO_TRIGGER = FreshenField::minval,
+ TRIGGER_OK,
+ TRIGGER_FAILED
+ };
+ enum TransactValue
+ {
+ KEEP_STATE = 0,
+ TRANSACT = TransactField::minval
+ };
+ enum TransactByValue
+ {
+ SOLVER = 0,
+ APPL_LOW = TransactByField::minval,
+ APPL_HIGH,
+ USER
+ };
+
+ enum InstallDetailValue
+ {
+ EXPLICIT_INSTALL = 0,
+ SOFT_REQUIRES = TransactDetailField::minval
+ };
+ enum RemoveDetailValue
+ {
+ EXPLICIT_REMOVE = 0,
+ DUE_TO_OBSOLETE = TransactDetailField::minval,
+ DUE_TO_UNLINK
+ };
+
+ public:
+
+ ResStatus()
+ {}
+
+ // get/set functions, returnig \c true if requested status change
+ // was successfull (i.e. leading to the desired transaction).
+ // If a lower level (e.g.SOLVER) wants to transact, but it's
+ // already set by a higher level, \c true should be returned.
+ // Removing a higher levels transaction bit should fail.
+
+ private:
+ bit::BitField<FieldType> _bitfield;
+ };
+}
/******************************************************************
**
{
INT << "===[START]==========================================" << endl;
- Pathname f( "./p" );
- Source src( SourceFactory().createFrom( new source::SuseTagsImpl( f ) ) );
- INT << src.resolvables().size() << endl;
-
- src.resolvables().forEach( chain( resfilter::ByKind( ResTraits<Package>::kind ),
- resfilter::ByName( "rpm" )
- ),
- resfilter::chain( Print("1"),
- chain( resfilter::chain( Print("A"), resfilter::chain( Print("B"), Print("C") ) ),
- Print("2")
- )
- )
- );
-
-
INT << "===[END]============================================" << endl;
return 0;
--- /dev/null
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/Bit.h
+ *
+*/
+#ifndef ZYPP_BIT_H
+#define ZYPP_BIT_H
+
+#include <iosfwd>
+
+#include "zypp/base/PtrTypes.h"
+
+///////////////////////////////////////////////////////////////////
+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
+ {
+ 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
+ {
+ static const _IntT value = bit_detail::Gen1Bits<_IntT,_size>::value << _begin;
+ static const _IntT inverted = ~value;
+ };
+
+ /** Range of bits starting at bit \_begin with length \a _size. */
+ template<class _IntT, unsigned _begin, unsigned _size>
+ struct Range
+ {
+ typedef MaxBits<_IntT> MaxBits;
+ typedef Mask<_IntT,_begin,_size> Mask;
+
+ static const unsigned begin = _begin;
+ static const unsigned size = _size;
+ static const unsigned end = _begin + _size;
+
+ static const unsigned minval = 1 << _begin;
+ };
+ /** Range specialisation for (illegal) zero \a _size.
+ * Fore error at compiletime. Currently because types
+ * and values are undefined
+ */
+ template<class _IntT, unsigned _begin>
+ struct Range<_IntT, _begin, 0>
+ {};
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // CLASS NAME : BitField
+ //
+ /** An integral type used as BitField.
+ *
+ * Most methods exist as templated and nontemplated
+ * version. The nontemplated operates on the complete
+ * FitField, 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 )
+ {}
+
+ /** 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 )
+ {
+ return (_value & _Range::Mask::value)
+ == (rhs & _Range::Mask::value);
+ }
+ bool isEqual( _IntT rhs )
+ {
+ return _value == rhs;
+ }
+
+ private:
+ _IntT _value;
+ };
+ ///////////////////////////////////////////////////////////////////
+
+ /** \relates BitField Stream output */
+ template<class _IntT>
+ std::ostream & operator<<( std::ostream & str, const BitField<_IntT> & obj )
+ {
+ return str << obj.asString();
+ }
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace bit
+ ///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+#endif // ZYPP_BIT_H
pkginclude_HEADERS = NeedAType.h \
Arch.h \
+ Bit.h \
ByteCount.h \
Capability.h \
CapFactory.h \
ResObject.h \
Resolvable.h \
ResTraits.h \
+ ResStatus.h \
ResStore.h \
ResFilters.h \
Package.h \
ResObject.cc \
Resolvable.cc \
ResTraits.cc \
+ ResStatus.cc \
ResStore.cc \
Package.cc \
Pathname.cc \
--- /dev/null
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/ResStatus.cc
+ *
+*/
+#include <iostream>
+//#include "zypp/base/Logger.h"
+
+#include "zypp/ResStatus.h"
+
+using std::endl;
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // METHOD NAME : ResStatus::ResStatus
+ // METHOD TYPE : Ctor
+ //
+ ResStatus::ResStatus()
+ {}
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // METHOD NAME : ResStatus::~ResStatus
+ // METHOD TYPE : Dtor
+ //
+ ResStatus::~ResStatus()
+ {}
+
+ /******************************************************************
+ **
+ ** FUNCTION NAME : operator<<
+ ** FUNCTION TYPE : std::ostream &
+ */
+ std::ostream & operator<<( std::ostream & str, const ResStatus & obj )
+ {
+ return str << obj._bitfield.asString();
+ }
+
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
--- /dev/null
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/ResStatus.h
+ *
+*/
+#ifndef ZYPP_RESSTATUS_H
+#define ZYPP_RESSTATUS_H
+
+#include <iosfwd>
+
+#include "zypp/Bit.h"
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // CLASS NAME : ResStatus
+ //
+ /** Status bitfield.
+ *
+ * \li \c StateField Whether the resolvable is installed
+ * or uninstalled (available).
+ * \li \c FreshenField Freshen status computed by the solver.
+ * \li \c TransactField Wheter to transact this resolvable
+ * (delete if installed install if uninstalled).
+ * \li \c TransactByField Who triggered the transaction. Transaction
+ * bit may be reset by higer levels only.
+ * \li \c TransactDetailField Reason why the Resolvable transacts.
+ * Splitted into \c InstallDetailValue and \c RemoveDetailValue
+ * dependent on the kind of transaction.
+ */
+ class ResStatus
+ {
+ friend std::ostream & operator<<( std::ostream & str, const ResStatus & obj );
+
+ typedef char FieldType;
+ // Bit Ranges within FieldType defined by 1st bit and size:
+ typedef bit::Range<FieldType,0, 1> StateField;
+ typedef bit::Range<FieldType,StateField::end, 2> FreshenField;
+ typedef bit::Range<FieldType,FreshenField::end, 1> TransactField;
+ typedef bit::Range<FieldType,TransactField::end, 2> TransactByField;
+ typedef bit::Range<FieldType,TransactByField::end, 2> TransactDetailField;
+ // enlarge FieldType if more bit's needed. It's not yet
+ // checked by the compiler.
+ public:
+
+ enum StateValue
+ {
+ UNINSTALLED = 0,
+ INSTALLED = StateField::minval
+ };
+ enum FreshenValue
+ {
+ UNDETERMINED = 0,
+ NO_TRIGGER = FreshenField::minval,
+ TRIGGER_OK,
+ TRIGGER_FAILED
+ };
+ enum TransactValue
+ {
+ KEEP_STATE = 0,
+ TRANSACT = TransactField::minval
+ };
+ enum TransactByValue
+ {
+ SOLVER = 0,
+ APPL_LOW = TransactByField::minval,
+ APPL_HIGH,
+ USER
+ };
+
+ enum InstallDetailValue
+ {
+ EXPLICIT_INSTALL = 0,
+ SOFT_REQUIRES = TransactDetailField::minval
+ };
+ enum RemoveDetailValue
+ {
+ EXPLICIT_REMOVE = 0,
+ DUE_TO_OBSOLETE = TransactDetailField::minval,
+ DUE_TO_UNLINK
+ };
+
+ public:
+
+ /** Default ctor. */
+ ResStatus();
+ /** Dtor. */
+ ~ResStatus();
+
+ // get/set functions, returnig \c true if requested status change
+ // was successfull (i.e. leading to the desired transaction).
+ // If a lower level (e.g.SOLVER) wants to transact, but it's
+ // already set by a higher level, \c true should be returned.
+ // Removing a higher levels transaction bit should fail.
+
+ private:
+ bit::BitField<FieldType> _bitfield;
+ };
+ ///////////////////////////////////////////////////////////////////
+
+ /** \relates ResStatus Stream output */
+ std::ostream & operator<<( std::ostream & str, const ResStatus & obj );
+
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+#endif // ZYPP_RESSTATUS_H