#include <list>
#include <map>
#include <set>
+#include <vector>
+
+#include "Printing.h"
#include <zypp/base/Logger.h>
#include <zypp/base/String.h>
///////////////////////////////////////////////////////////////////
namespace zypp
{
+ ///////////////////////////////////////////////////////////////////
+ //
+ // CLASS NAME : NumImpl
+ //
+ /** Num implementation. */
+ struct NumImpl
+ {
+ NumImpl()
+ : _i( -1 )
+ { SEC << "NumImpl(" << _i << ")" << std::endl; }
+
+ NumImpl( int i_r )
+ : _i( i_r )
+ { INT << "NumImpl(" << _i << ")" << std::endl; }
+
+ ~NumImpl()
+ { ERR << "---NumImpl(" << _i << ")" << std::endl; }
+
+ int i() const { return _i; }
+
+ int _i;
+
+ public:
+ /** Offer default Impl. */
+ static shared_ptr<NumImpl> nullimpl()
+ {
+ static shared_ptr<NumImpl> _nullimpl( new NumImpl );
+ return _nullimpl;
+ }
+ };
+ ///////////////////////////////////////////////////////////////////
+
+ /** \relates Num::Impl Stream output */
+ inline std::ostream & operator<<( std::ostream & str, const NumImpl & obj )
+ {
+ return str << "Num(" << obj._i << ")";
+ }
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // CLASS NAME : Num
+ //
+ /** */
+ class Num
+ {
+ friend std::ostream & operator<<( std::ostream & str, const Num & obj );
+
+ public:
+ /** Implementation */
+ typedef NumImpl Impl;
+
+ public:
+ /** Default ctor */
+ Num()
+ : _pimpl( Impl::nullimpl() )
+ {}
+ /** Dtor */
+ ~Num()
+ {}
+
+ public:
+ Num( const shared_ptr<Impl> & pimpl_r )
+ : _pimpl( pimpl_r ? pimpl_r : Impl::nullimpl() )
+ {}
+
+ int i() const { return _pimpl->i(); }
+
+ private:
+ /** Pointer to implementation */
+ RWCOW_pointer<Impl> _pimpl;
+ };
+ ///////////////////////////////////////////////////////////////////
+
+ /** \relates Num Stream output */
+ std::ostream & operator<<( std::ostream & str, const Num & obj )
+ { return str << *obj._pimpl; }
+
+ ///////////////////////////////////////////////////////////////////
+
+
+ struct NumPool
+ {
+ NumPool()
+ : _pool(10)
+ {}
+
+ Num get( int i )
+ {
+ Num r( _get( i ) );
+ MIL << i << " -> " << r << std::endl;
+ return r;
+ }
+ Num _get( int i )
+ {
+ if ( i < 0 || i >= 10 )
+ return Num();
+ if ( ! _pool[i] )
+ _pool[i] = shared_ptr<NumImpl>( new NumImpl( i ) );
+ return _pool[i];
+ }
+
+ vector<shared_ptr<NumImpl> > _pool;
+ };
+
+ std::ostream & operator<<( std::ostream & str, const NumPool & obj )
+ {
+ pprint( obj._pool );
+ return str;
+ }
}
///////////////////////////////////////////////////////////////////
-namespace zypp
-{
- struct Foo : public callback::ReportBase
- {
- virtual void ping( int i )
- {}
- virtual int pong()
- { return -1; }
- };
-
- struct FooRec : public callback::ReceiveReport<Foo>
- {
- FooRec() : _i( -1 ) {}
- virtual void ping( int i )
- { _i = i; }
- virtual int pong()
- { return _i; }
- int _i;
- };
-
- struct FooRec2 : public callback::ReceiveReport<Foo>
- {
- FooRec2() : _i( -1 ) {}
- virtual void ping( int i )
- { _i = i; }
- virtual int pong()
- { return 2*_i; }
- int _i;
- };
-}
-///////////////////////////////////////////////////////////////////
-
-
-using namespace zypp;
-
-void ping()
-{
- callback::SendReport<Foo> r;
- r->ping( 13 );
- int res = r->pong();
- MIL << "PingPong: 13 -> " << res << endl;
-}
-
-namespace zypp { namespace callback
-{
-
-
-}}
-
/******************************************************************
**
** FUNCTION NAME : main
{
INT << "===[START]==========================================" << endl;
+ NumPool a;
+ DBG << a << endl;
+ DBG << a.get( -2 ) << endl;
+ DBG << a.get( 3 ) << endl;
+ DBG << a.get( 13 ) << endl;
+ DBG << a << endl;
- FooRec r;
- FooRec2 r2;
- r2.connect();
- ping();
- {
- callback::TempConnect<Foo> temp( r );
- ping();
- }
-
- ping();
INT << "===[END]============================================" << endl << endl;
return 0;
--- /dev/null
+#ifndef MA_MEASURE_H
+#define MA_MEASURE_H
+
+#include <iostream>
+#include <string>
+
+#include "zypp/base/Logger.h"
+#include "zypp/base/PtrTypes.h"
+
+///////////////////////////////////////////////////////////////////
+// Just for the stats
+struct Measure
+{
+ struct Run
+ {
+ Run( const std::string & msg_r )
+ : _msg( msg_r )
+ , _begin( time(NULL) )
+ {
+ USR << "START MEASURE..." << _msg << std::endl;
+ }
+ ~Run()
+ {
+ USR << "DURATION: " << (time(NULL)-_begin) << " sec. " << _msg << std::endl;
+ }
+ std::string _msg;
+ time_t _begin;
+ };
+
+ Measure( const std::string & msg_r = std::string() )
+ : _run( new Run( msg_r ) )
+ {}
+
+ void stop()
+ { _run.reset(); }
+
+ void start( const std::string & msg_r = std::string() )
+ { _run.reset(); _run.reset( new Run( msg_r ) ); }
+
+ private:
+ zypp::shared_ptr<Run> _run;
+};
+
+///////////////////////////////////////////////////////////////////
+#endif // MA_MEASURE_H
#include <map>
#include <set>
+#include "Measure.h"
+#include "Printing.h"
+
#include <zypp/base/Logger.h>
+#include <zypp/base/LogControl.h>
#include <zypp/base/String.h>
#include <zypp/base/Exception.h>
#include <zypp/base/PtrTypes.h>
#include <zypp/base/Algorithm.h>
#include <zypp/base/Functional.h>
+#include "zypp/NVRAD.h"
#include "zypp/ResPool.h"
#include "zypp/ResFilters.h"
#include "zypp/CapFilters.h"
#include <zypp/source/susetags/SuseTagsImpl.h>
#include "zypp/ResPoolManager.h"
-#include "zypp/ui/Selectable.h"
+#include "zypp/ResPoolProxy.h"
using namespace std;
using namespace zypp;
+using namespace zypp::ui;
using namespace zypp::functor;
-using namespace zypp::resfilter;
///////////////////////////////////////////////////////////////////
-struct Print : public std::unary_function<ResObject::constPtr, bool>
-{
- bool operator()( ResObject::constPtr ptr )
- {
- USR << *ptr << endl;
- return true;
- }
-};
-
///////////////////////////////////////////////////////////////////
template<class _IntT>
: _value( _IntT( value_r ) )
{}
+
operator _IntT &()
{ return _value; }
///////////////////////////////////////////////////////////////////
-namespace zypp { namespace ui
+struct XByInstalled : public std::unary_function<ui::Selectable::constPtr,bool>
{
-
- struct PP
+ bool operator()( const ui::Selectable::constPtr & obj ) const
{
- typedef std::set<ResPool::Item> ItemC;
- struct SelC
- {
- void add( ResPool::Item it )
- { available.insert( it ); }
- ItemC installed;
- ItemC available;
- };
- typedef std::map<std::string,SelC> NameC;
- typedef std::map<ResObject::Kind,NameC> KindC;
-
- KindC _kinds;
-
- void operator()( ResPool::Item it )
- {
- _kinds[it->kind()][it->name()].add( it );
- }
-
- void dumpOn() const
- {
- for ( KindC::const_iterator it = _kinds.begin(); it != _kinds.end(); ++it )
- {
- ERR << it->first << endl;
- for ( NameC::const_iterator nit = it->second.begin(); nit != it->second.end(); ++nit )
- {
- WAR << nit->first << endl;
- MIL << "i " << nit->second.installed.size()
- << " a " << nit->second.available.size() << endl;
- }
- }
- }
- };
+ return obj->hasInstalledObj();
+ }
+};
- class ResPoolProxy
+template<class FT>
+ void fieldInfo()
{
- public:
-
- };
-
+ MIL << bit::asString(FT::Mask::value) << '|' << FT::begin << '-' << FT::end << '|' << FT::size << endl;
+ MIL << bit::asString(FT::Mask::inverted) << endl;
+ }
-}}
+void testr()
+{
+ fieldInfo<ResStatus::StateField>();
+ DBG << bit::asString((ResStatus::FieldType)ResStatus::UNINSTALLED) << endl;
+ DBG << bit::asString((ResStatus::FieldType)ResStatus::INSTALLED) << endl;
+ fieldInfo<ResStatus::EstablishField>();
+ DBG << bit::asString((ResStatus::FieldType)ResStatus::UNDETERMINED) << endl;
+ DBG << bit::asString((ResStatus::FieldType)ResStatus::UNNEEDED) << endl;
+ DBG << bit::asString((ResStatus::FieldType)ResStatus::SATISFIED) << endl;
+ DBG << bit::asString((ResStatus::FieldType)ResStatus::INCOMPLETE) << endl;
+ fieldInfo<ResStatus::TransactField>();
+ DBG << bit::asString((ResStatus::FieldType)ResStatus::KEEP_STATE) << endl;
+ DBG << bit::asString((ResStatus::FieldType)ResStatus::TRANSACT) << endl;
+ fieldInfo<ResStatus::TransactByField>();
+ DBG << bit::asString((ResStatus::FieldType)ResStatus::SOLVER) << endl;
+ DBG << bit::asString((ResStatus::FieldType)ResStatus::APPL_LOW) << endl;
+ DBG << bit::asString((ResStatus::FieldType)ResStatus::APPL_HIGH) << endl;
+ DBG << bit::asString((ResStatus::FieldType)ResStatus::USER) << endl;
+ fieldInfo<ResStatus::TransactDetailField>();
+ DBG << bit::asString((ResStatus::FieldType)ResStatus::EXPLICIT_INSTALL) << endl;
+ DBG << bit::asString((ResStatus::FieldType)ResStatus::SOFT_INSTALL) << endl;
+ DBG << endl;
+ DBG << bit::asString((ResStatus::FieldType)ResStatus::EXPLICIT_REMOVE) << endl;
+ DBG << bit::asString((ResStatus::FieldType)ResStatus::SOFT_REMOVE) << endl;
+ DBG << bit::asString((ResStatus::FieldType)ResStatus::DUE_TO_OBSOLETE) << endl;
+ DBG << bit::asString((ResStatus::FieldType)ResStatus::DUE_TO_UNLINK) << endl;
+ fieldInfo<ResStatus::SolverStateField>();
+ DBG << bit::asString((ResStatus::FieldType)ResStatus::NORMAL) << endl;
+ DBG << bit::asString((ResStatus::FieldType)ResStatus::SEEN) << endl;
+ DBG << bit::asString((ResStatus::FieldType)ResStatus::IMPOSSIBLE) << endl;
+}
*/
int main( int argc, char * argv[] )
{
+ INT << "===[START]==========================================" << endl;
+
string infile( "p" );
if (argc >= 2 )
infile = argv[1];
- Source_Ref src( SourceFactory().createFrom( new source::susetags::SuseTagsImpl(infile) ) );
- MIL << src.resolvables().size() << endl;
+ MIL << ResStatus::toBeUninstalledDueToUnlink << endl;
+ MIL << ResStatus::toBeUninstalledDueToObsolete << endl;
+ testr();
+ return 0;
+
+ NVRAD a( "foo", Edition("1.1") );
+ NVRAD b( "foo", Edition("1.0") );
+ SEC << (a==b) << endl;
+ SEC << (a!=b) << endl;
+ SEC << (a<b) << endl;
+ set<NVRAD> s;
+ s.insert(a);
+ s.insert(b);
+ SEC << s.size() << endl;
+ return 0;
+
+ Url url("dir:/Local/ma/zypp/libzypp/devel/devel.ma/CD1");
+ Measure x( "SourceFactory.create" );
+ Source_Ref src( SourceFactory().createFrom( url ) );
+ x.stop();
+ Source_Ref trg( SourceFactory().createFrom( url ) );
+
+ //Source_Ref src( SourceFactory().createFrom( new source::susetags::SuseTagsImpl(infile) ) );
+ //MIL << src.resolvables().size() << endl;
ResPoolManager pool;
+ x.start( "pool.insert" );
pool.insert( src.resolvables().begin(), src.resolvables().end() );
+ x.stop();
MIL << pool << endl;
ResPool query( pool.accessor() );
rstats( query.begin(), query.end() );
- ui::PP collect;
- for_each( query.begin(), query.end(),
- functorRef<void,ResPool::Item>( collect ) );
- collect.dumpOn();
-
-
+ ResPoolProxy y2pm( query );
+ pool.insert( trg.resolvables().begin(), trg.resolvables().end(), true );
+ y2pm = ResPoolProxy( query );
+ SEC << "----------" << endl;
+ XXX << "----------" << endl;
+ SEC << "----------" << endl;
+ INT << "===[END]============================================" << endl << endl;
return 0;
}
--- /dev/null
+#ifndef MA_PRINTING_H
+#define MA_PRINTING_H
+
+#include <iostream>
+#include <string>
+
+#include "zypp/base/Logger.h"
+#include "zypp/base/PtrTypes.h"
+#include <zypp/base/String.h>
+#include <zypp/base/Iterator.h>
+#include <zypp/base/Algorithm.h>
+#include <zypp/base/Functional.h>
+
+///////////////////////////////////////////////////////////////////
+
+template<class _Tp>
+ struct Print : public std::unary_function<_Tp, bool>
+ {
+ bool operator()( const _Tp & obj )
+ {
+ USR << obj << std::endl;
+ return true;
+ }
+ };
+
+template<class _Tp>
+ struct PPrint : public std::unary_function<_Tp, bool>
+ {
+ bool operator()( const _Tp & obj )
+ {
+ if ( obj )
+ USR << *obj << std::endl;
+ else
+ USR << "(NULL)" << std::endl;
+ return true;
+ }
+ };
+
+template<class _Container>
+ void print( const _Container & c )
+ {
+ std::for_each( c.begin(), c.end(),
+ Print<typename _Container::value_type>() );
+ }
+
+template<class _Container>
+ void pprint( const _Container & c )
+ {
+ std::for_each( c.begin(), c.end(),
+ PPrint<typename _Container::value_type>() );
+ }
+
+///////////////////////////////////////////////////////////////////
+#endif // MA_PRINTING_H
template<class _IntT>
struct MaxBits
{
- static const unsigned value = (sizeof(_IntT)*8);
+ typedef _IntT IntT;
+ static const unsigned value = (sizeof(IntT)*8);
};
/** For printing bits. */
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;
+ 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 \_begin with length \a _size. */
template<class _IntT, unsigned _begin, unsigned _size>
struct Range
{
- typedef MaxBits<_IntT> MaxBits;
- typedef Mask<_IntT,_begin,_size> Mask;
+ typedef _IntT IntT;
+ 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
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;
+ };
+
///////////////////////////////////////////////////////////////////
//
// CLASS NAME : BitField
mutable ResStatus _status;
ResObject::constPtr _resolvable;
+ /** \name Poor man's save/restore state.
+ * \todo There may be better save/restore state strategies.
+ */
+ //@{
+ public:
+ void saveState() const
+ { _savedStatus = _status; }
+ void restoreState() const
+ { _status = _savedStatus; }
+ private:
+ mutable ResStatus _savedStatus;
+ //@}
+
public:
/** Offer default Impl. */
static shared_ptr<Impl> nullimpl()
* \todo make it work.
*/
//@{
- void SaveState()
- {}
- void RestoreState()
- {}
+ void SaveState();
+ void RestoreState();
//@}
private:
friend std::ostream & operator<<( std::ostream & str, const ResStatus & obj );
friend bool operator==( const ResStatus & lhs, const ResStatus & rhs );
+ public:
/** \name BitField range definitions.
*
* \note Enlarge FieldType if more bit's needed. It's not yet
*/
//@{
typedef short FieldType;
+ typedef bit::BitField<FieldType> BitFieldType;
// Bit Ranges within FieldType defined by 1st bit and size:
typedef bit::Range<FieldType,0, 1> StateField;
typedef bit::Range<FieldType,StateField::end, 2> EstablishField;
//@{
enum StateValue
{
- UNINSTALLED = 0,
- INSTALLED = StateField::minval
+ UNINSTALLED = bit::RangeValue<StateField,0>::value,
+ INSTALLED = bit::RangeValue<StateField,1>::value
};
enum EstablishValue
{
- UNDETERMINED = 0,
- UNNEEDED = EstablishField::minval, // has freshens, none trigger
- SATISFIED, // has none or triggered freshens, all requirements fulfilled
- INCOMPLETE // installed: has none or triggered freshens, requirements unfulfilled
+ UNDETERMINED = bit::RangeValue<EstablishField,0>::value,
+ UNNEEDED = bit::RangeValue<EstablishField,1>::value, // has freshens, none trigger
+ SATISFIED = bit::RangeValue<EstablishField,2>::value, // has none or triggered freshens, all requirements fulfilled
+ INCOMPLETE = bit::RangeValue<EstablishField,3>::value // installed: has none or triggered freshens, requirements unfulfilled
};
enum TransactValue
{
- KEEP_STATE = 0,
- TRANSACT = TransactField::minval // change state installed <-> uninstalled
+ KEEP_STATE = bit::RangeValue<TransactField,0>::value,
+ TRANSACT = bit::RangeValue<TransactField,1>::value // change state installed <-> uninstalled
};
enum TransactByValue
{
- SOLVER = 0,
- APPL_LOW = TransactByField::minval,
- APPL_HIGH,
- USER
+ SOLVER = bit::RangeValue<TransactByField,0>::value,
+ APPL_LOW = bit::RangeValue<TransactByField,1>::value,
+ APPL_HIGH = bit::RangeValue<TransactByField,2>::value,
+ USER = bit::RangeValue<TransactByField,3>::value
};
enum InstallDetailValue
{
- EXPLICIT_INSTALL = 0,
- SOFT_INSTALL = TransactDetailField::minval
+ EXPLICIT_INSTALL = bit::RangeValue<TransactDetailField,0>::value,
+ SOFT_INSTALL = bit::RangeValue<TransactDetailField,1>::value
};
enum RemoveDetailValue
{
- EXPLICIT_REMOVE = 0,
- SOFT_REMOVE = TransactDetailField::minval,
- DUE_TO_OBSOLETE,
- DUE_TO_UNLINK
+ EXPLICIT_REMOVE = bit::RangeValue<TransactDetailField,0>::value,
+ SOFT_REMOVE = bit::RangeValue<TransactDetailField,1>::value,
+ DUE_TO_OBSOLETE = bit::RangeValue<TransactDetailField,2>::value,
+ DUE_TO_UNLINK = bit::RangeValue<TransactDetailField,3>::value
};
enum SolverStateValue
{
- NORMAL = 0, // default, notthing special
- SEEN = SolverStateField::minval, // already seen during ResolverUpgrade
- IMPOSSIBLE // impossible to install
+ NORMAL = bit::RangeValue<SolverStateField,0>::value, // default, notthing special
+ SEEN = bit::RangeValue<SolverStateField,1>::value, // already seen during ResolverUpgrade
+ IMPOSSIBLE = bit::RangeValue<SolverStateField,2>::value // impossible to install
};
//@}
/** Dtor. */
~ResStatus();
+ /** Debug helper returning the bitfield.
+ * It's save to expose the bitfield, as it can't be used to
+ * recreate a ResStatus. So it is not possible to bypass
+ * transition rules.
+ */
+ BitFieldType bitfield() const
+ { return _bitfield; }
+
public:
bool isInstalled() const
{ return _bitfield.value<_Field>() > val_r; }
private:
- bit::BitField<FieldType> _bitfield;
+ BitFieldType _bitfield;
};
///////////////////////////////////////////////////////////////////