public:
/** */
void insert( ResObject::constPtr ptr_r, bool installed = false )
- { inserter()( ptr_r, installed ); }
+ { inserter(installed)( ptr_r ); }
/** */
template <class _InputIterator>
void insert( _InputIterator first_r, _InputIterator last_r, bool installed = false )
- { while (first_r != last_r) { inserter()( *first_r, installed ); ++first_r; } }
+ { std::for_each( first_r, last_r, inserter(installed) ); }
/** */
void erase( ResObject::constPtr ptr_r )
/** Pointer to implementation */
RW_pointer<pool::PoolTraits::Impl> _pimpl;
/** */
- Inserter inserter()
- { return Inserter( *_pimpl ); }
+ Inserter inserter( bool installed )
+ { return Inserter( *_pimpl, installed ); }
/** */
Deleter deleter()
{ return Deleter( *_pimpl ); }
/** Dtor. */
~ResStatus();
- private:
+ public:
bool isInstalled() const
{ return fieldValueIs<StateField>( INSTALLED ); }
return false;
}
}
-
+
bool maySetNoTransact (TransactByValue causer)
{
bit::BitField<FieldType> savBitfield = _bitfield;
bool setTransact (bool val_r, TransactByValue causer)
{
- if (!isGreaterThan<TransactByField>( causer )) {
+ if (!isGreaterThan<TransactByField>( causer )) {
fieldValueAssign<TransactField>( val_r ? TRANSACT : KEEP_STATE );
if (val_r) fieldValueAssign<TransactByField>( causer ); // remember the causer on set
else fieldValueAssign<TransactByField>( SOLVER ); // clear it on reset
return true;
- } else if (fieldValueIs<TransactField>(val_r ? TRANSACT : KEEP_STATE)) {
+ } else if (fieldValueIs<TransactField>(val_r ? TRANSACT : KEEP_STATE)) {
return true; // is already set
} else {
return false;
- }
+ }
}
bool maySetTransact (bool val_r, TransactByValue causer)
bool ret = setToBeInstalled (causer);
_bitfield = savBitfield;
return ret;
- }
+ }
bool setToBeUninstalled (TransactByValue causer)
{
bool ret = setToBeUninstalled (causer);
_bitfield = savBitfield;
return ret;
- }
+ }
//------------------------------------------------------------------------
// *** These are only for the Resolver ***
fieldValueAssign<TransactDetailField>(SOFT_INSTALL);
return true;
}
-
+
bool setToBeUninstalledSoft ( )
{
if (!setToBeUninstalled(SOLVER)) return false;
bool isSoftInstall () {
return fieldValueIs<TransactDetailField> (SOFT_INSTALL);
- }
+ }
bool isSoftUninstall () {
return fieldValueIs<TransactDetailField> (SOFT_REMOVE);
- }
+ }
bool setSoftInstall (bool flag) {
fieldValueAssign<TransactDetailField>(flag?SOFT_INSTALL:0);
return true;
- }
+ }
bool setSoftUninstall (bool flag) {
fieldValueAssign<TransactDetailField>(flag?SOFT_REMOVE:0);
return true;
- }
+ }
bool setUndetermined ()
{
return str << "PoolImpl " << obj.size();
}
- void PoolImplInserter::operator()( ResObject::constPtr ptr_r, bool installed )
+ void PoolImplInserter::operator()( ResObject::constPtr ptr_r )
{
- PoolImpl::Item item ( ptr_r, ResStatus (installed) );
+ PoolImpl::Item item ( ptr_r, ResStatus (_installed) );
_poolImpl.store().insert( item );
_poolImpl.namestore().insert( PoolImpl::NameContainerT::value_type (item->name(), item ) );
CapSet provides = item->dep( Dep::PROVIDES );
/** */
struct PoolImplInserter
{
- void operator()( ResObject::constPtr ptr_r, bool installed = false );
+ void operator()( ResObject::constPtr ptr_r );
- PoolImplInserter( PoolImpl & poolImpl_r )
+ PoolImplInserter( PoolImpl & poolImpl_r, bool installed_r )
: _poolImpl( poolImpl_r )
+ , _installed( installed_r )
{}
PoolImpl & _poolImpl;
+ bool _installed;
};
/** */
uiinclude_HEADERS = \
Status.h \
Selectable.h \
- ResPoolProxy.h
+ ResPoolProxy.h \
+ \
+ SelectableImpl.h
noinst_LTLIBRARIES = lib@PACKAGE@_ui.la
lib@PACKAGE@_ui_la_SOURCES = \
Status.cc \
Selectable.cc \
- ResPoolProxy.cc
+ ResPoolProxy.cc \
+ \
+ SelectableImpl.cc
## ##################################################
#include <iostream>
#include "zypp/base/Logger.h"
+#include "zypp/base/Iterator.h"
+#include "zypp/base/Algorithm.h"
+#include "zypp/base/Functional.h"
+
#include "zypp/ui/ResPoolProxy.h"
+#include "zypp/ui/SelectableImpl.h"
using std::endl;
namespace ui
{ /////////////////////////////////////////////////////////////////
+ struct SelPoolHelper
+ {
+ typedef std::set<ResPool::Item> ItemC;
+ struct SelC
+ {
+ void add( ResPool::Item it )
+ {
+ if ( it.status().isInstalled() )
+ installed.insert( it );
+ else
+ available.insert( it );
+ }
+ ItemC installed;
+ ItemC available;
+ };
+ typedef std::map<std::string,SelC> NameC;
+ typedef std::map<ResObject::Kind,NameC> KindC;
+
+ KindC _kinds;
+
+ /** collect from a pool */
+ void operator()( ResPool::Item it )
+ {
+ _kinds[it->kind()][it->name()].add( it );
+ }
+
+
+ Selectable::Ptr buildSelectable( const ResObject::Kind & kind_r,
+ const std::string & name_r,
+ const PoolItem & installedItem_r,
+ const ItemC & available )
+ {
+ return Selectable::Ptr( new Selectable(
+ Selectable::Impl_Ptr( new Selectable::Impl( kind_r, name_r,
+ installedItem_r,
+ available.begin(),
+ available.end() ) )
+ ) );
+ }
+
+ /** Build Selectable::Ptr and feed them to some container. */
+ template<class _OutputIterator>
+ void feed( _OutputIterator result_r )
+ {
+ for ( KindC::const_iterator kindIt = _kinds.begin(); kindIt != _kinds.end(); ++kindIt )
+ {
+ for ( NameC::const_iterator nameIt = kindIt->second.begin(); nameIt != kindIt->second.end(); ++nameIt )
+ {
+ const ItemC & installed( nameIt->second.installed );
+ const ItemC & available( nameIt->second.available );
+
+ if ( installed.empty() )
+ {
+ if ( available.empty() )
+ continue;
+ *result_r = buildSelectable( kindIt->first, nameIt->first, PoolItem(), available );
+ ++result_r;
+ }
+ else
+ {
+ // ui want's one Selectable per installed item
+ for ( ItemC::const_iterator instIt = installed.begin(); instIt != installed.end(); ++instIt )
+ {
+ *result_r = buildSelectable( kindIt->first, nameIt->first, *instIt, available );
+ ++result_r;
+ }
+ }
+ }
+ }
+ }
+ };
+
///////////////////////////////////////////////////////////////////
//
// CLASS NAME : ResPoolProxy::Impl
struct ResPoolProxy::Impl
{
public:
+
+ typedef std::set<Selectable::Ptr> SelPool;
+
+ public:
Impl()
{}
Impl( ResPool_Ref pool_r )
: _pool( pool_r )
{
-#if 0
- ui::PP collect;
- for_each( query.begin(), query.end(),
- functorRef<void,ResPool::Item>( collect ) );
- collect.dumpOn();
-#endif
+ SelPoolHelper collect;
+ std::for_each( _pool.begin(), _pool.end(),
+ functor::functorRef<void,ResPool::Item>( collect ) );
+ collect.feed( std::inserter( _selectables, _selectables.end() ) );
}
-
-
private:
ResPool_Ref _pool;
+ SelPool _selectables;
public:
/** Offer default Impl. */
//#include "zypp/base/Logger.h"
#include "zypp/ui/Selectable.h"
+#include "zypp/ui/SelectableImpl.h"
#include "zypp/ResPool.h"
#include "zypp/PoolItem.h"
///////////////////////////////////////////////////////////////////
//
- // CLASS NAME : Selectable::Impl
- //
- /** Selectable implementation. */
- struct Selectable::Impl
- {
- typedef ResPool::Item PoolItem;
- typedef std::set<PoolItem> AvialableItemSet;
- typedef AvialableItemSet::const_iterator available_iterator;
- typedef AvialableItemSet::size_type size_type;
-
- public:
- Impl( const Object::Kind & kind_r,
- const std::string & name_r,
- const PoolItem & installedItem_r,
- available_iterator availableBegin_r,
- available_iterator availableEnd_r )
- : _kind( kind_r )
- , _name( name_r )
- , _installedItem( installedItem_r )
- , _availableItems( availableBegin_r, availableEnd_r )
- {}
-
- public:
- /** */
- Object::Kind kind() const
- { return _kind; }
- /** */
- const std::string & name() const
- { return _name; }
- /** */
- Status status() const
- { return S_Taboo; }
- /** */
- bool set_status( const Status state_r )
- { return false; }
-
- /** Installed object. */
- Object_Ptr installedObj() const
- { return _installedItem; }
-
- /** Best among available objects. */
- Object_Ptr candidateObj() const
- { return 0; }
-
- /** Best among all objects. */
- Object_Ptr theObj() const
- { return 0; }
-
- /** . */
- size_type availableObjs() const
- { return 0; }
-
- private:
- public:
- Object::Kind _kind;
- std::string _name;
- PoolItem _installedItem;
- AvialableItemSet _availableItems;
- };
- ///////////////////////////////////////////////////////////////////
-
- /** \relates Selectable::Impl Stream output */
- inline std::ostream & operator<<( std::ostream & str, const Selectable::Impl & obj )
- {
- return str << '[' << obj.kind() << ']' << obj.name() << ": " << obj.status()
- << " (I " << obj._installedItem << ")"
- << " (A " << obj._availableItems.size() << ")";
- }
-
- ///////////////////////////////////////////////////////////////////
- //
- // CLASS NAME : Selectable
- //
- ///////////////////////////////////////////////////////////////////
-
- ///////////////////////////////////////////////////////////////////
- //
// METHOD NAME : Selectable::Selectable
// METHOD TYPE : Ctor
//
//
///////////////////////////////////////////////////////////////////
- Selectable::Object::Kind Selectable::kind() const
+ ResObject::Kind Selectable::kind() const
{ return _pimpl->kind(); }
const std::string & Selectable::name() const
bool Selectable::set_status( const Status state_r )
{ return _pimpl->set_status( state_r ); }
- Selectable::Object_Ptr Selectable::installedObj() const
+ ResObject::constPtr Selectable::installedObj() const
{ return _pimpl->installedObj(); }
- Selectable::Object_Ptr Selectable::candidateObj() const
+ ResObject::constPtr Selectable::candidateObj() const
{ return _pimpl->candidateObj(); }
- Selectable::Object_Ptr Selectable::theObj() const
+ ResObject::constPtr Selectable::theObj() const
{ return _pimpl->theObj(); }
Selectable::size_type Selectable::availableObjs() const
typedef intrusive_ptr<const Selectable> constPtr;
typedef unsigned size_type;
- typedef ResObject Object;
- typedef Object::constPtr Object_Ptr;
-
public:
/** */
- Object::Kind kind() const;
+ ResObject::Kind kind() const;
/** */
const std::string & name() const;
bool set_status( const Status state_r );
/** Installed object. */
- Object_Ptr installedObj() const;
+ ResObject::constPtr installedObj() const;
/** Best among available objects. */
- Object_Ptr candidateObj() const;
+ ResObject::constPtr candidateObj() const;
/** Best among all objects. */
- Object_Ptr theObj() const;
+ ResObject::constPtr theObj() const;
/** Number of available objects. */
size_type availableObjs() const;
typedef shared_ptr<Impl> Impl_Ptr;
/** Default ctor */
Selectable( Impl_Ptr pimpl_r );
+ private:
/** Dtor */
~Selectable();
private:
--- /dev/null
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/ui/SelectableImpl.cc
+ *
+*/
+#include <iostream>
+//#include "zypp/base/Logger.h"
+
+#include "zypp/ui/SelectableImpl.h"
+
+using std::endl;
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ namespace ui
+ { /////////////////////////////////////////////////////////////////
+
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace ui
+ ///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
--- /dev/null
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/ui/SelectableImpl.h
+ *
+*/
+#ifndef ZYPP_UI_SELECTABLEIMPL_H
+#define ZYPP_UI_SELECTABLEIMPL_H
+
+#include <iosfwd>
+
+#include "zypp/base/PtrTypes.h"
+
+#include "zypp/ResPool.h"
+#include "zypp/ResObject.h"
+#include "zypp/ui/Selectable.h"
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ namespace ui
+ { /////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // CLASS NAME : Selectable::Impl
+ //
+ /** Selectable implementation. */
+ struct Selectable::Impl
+ {
+ friend std::ostream & operator<<( std::ostream & str, const Selectable::Impl & obj );
+
+ typedef ResPool::Item PoolItem;
+ typedef std::set<PoolItem> AvialableItemSet;
+ typedef AvialableItemSet::const_iterator available_iterator;
+ typedef AvialableItemSet::size_type size_type;
+
+ public:
+ Impl( const ResObject::Kind & kind_r,
+ const std::string & name_r,
+ const PoolItem & installedItem_r,
+ available_iterator availableBegin_r,
+ available_iterator availableEnd_r )
+ : _kind( kind_r )
+ , _name( name_r )
+ , _installedItem( installedItem_r )
+ , _availableItems( availableBegin_r, availableEnd_r )
+ {}
+
+ public:
+ /** */
+ ResObject::Kind kind() const
+ { return _kind; }
+ /** */
+ const std::string & name() const
+ { return _name; }
+ /** */
+ Status status() const
+ { return S_Taboo; }
+ /** */
+ bool set_status( const Status state_r )
+ { return false; }
+
+ /** Installed object. */
+ ResObject::constPtr installedObj() const
+ { return _installedItem; }
+
+ /** Best among available objects. */
+ ResObject::constPtr candidateObj() const
+ { return 0; }
+
+ /** Best among all objects. */
+ ResObject::constPtr theObj() const
+ { return 0; }
+
+ /** . */
+ size_type availableObjs() const
+ { return 0; }
+
+ private:
+ ResObject::Kind _kind;
+ std::string _name;
+ PoolItem _installedItem;
+ AvialableItemSet _availableItems;
+ };
+ ///////////////////////////////////////////////////////////////////
+
+ /** \relates Selectable::Impl Stream output */
+ inline std::ostream & operator<<( std::ostream & str, const Selectable::Impl & obj )
+ {
+ return str << '[' << obj.kind() << ']' << obj.name() << ": " << obj.status()
+ << " (I " << obj._installedItem << ")"
+ << " (A " << obj._availableItems.size() << ")";
+ }
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace ui
+ ///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+#endif // ZYPP_UI_SELECTABLEIMPL_H