libzypp  10.5.0
SelectableTraits.h
Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #ifndef ZYPP_UI_SELECTABLETRAITS_H
00013 #define ZYPP_UI_SELECTABLETRAITS_H
00014 
00015 #include <set>
00016 #include <vector>
00017 
00018 #include "zypp/base/Iterator.h"
00019 #include "zypp/PoolItem.h"
00020 #include "zypp/pool/ByIdent.h"
00021 
00023 namespace zypp
00024 { 
00025 
00026   namespace ui
00027   { 
00028 
00030     //
00031     //  CLASS NAME : SelectableTraits
00032     //
00034     struct SelectableTraits
00035     {
00042       struct AVOrder : public std::binary_function<PoolItem,PoolItem,bool>
00043       {
00044         // NOTE: operator() provides LESS semantics to order the set.
00045         // So LESS means 'prior in set'. We want 'better' archs and
00046         // 'better' editions at the beginning of the set. So we return
00047         // TRUE if (lhs > rhs)!
00048         //
00049         bool operator()( const PoolItem & lhs, const PoolItem & rhs ) const
00050         {
00051           int lprio = lhs->satSolvable().repository().satInternalPriority();
00052           int rprio = rhs->satSolvable().repository().satInternalPriority();
00053           if ( lprio != rprio )
00054             return( lprio > rprio );
00055 
00056           // arch/noarch changes are ok.
00057           if ( lhs->arch() != Arch_noarch && rhs->arch() != Arch_noarch )
00058           {
00059             int res = lhs->arch().compare( rhs->arch() );
00060             if ( res )
00061               return res > 0;
00062           }
00063 
00064           int res = lhs->edition().compare( rhs->edition() );
00065           if ( res )
00066             return res > 0;
00067 
00068           lprio = lhs->satSolvable().repository().satInternalSubPriority();
00069           rprio = rhs->satSolvable().repository().satInternalSubPriority();
00070           if ( lprio != rprio )
00071             return( lprio > rprio );
00072 
00073           // no more criteria, still equal: sort by id
00074           return lhs.satSolvable().id() < rhs.satSolvable().id();
00075         }
00076       };
00077 
00084       struct IOrder : public std::binary_function<PoolItem,PoolItem,bool>
00085       {
00086         // NOTE: operator() provides LESS semantics to order the set.
00087         // So LESS means 'prior in set'. We want 'newer' install time
00088         // at the beginning of the set.
00089         //
00090         bool operator()( const PoolItem & lhs, const PoolItem & rhs ) const
00091         {
00092           int res = lhs->arch().compare( rhs->arch() );
00093           if ( res )
00094             return res > 0;
00095           res = lhs->edition().compare( rhs->edition() );
00096           if ( res )
00097             return res > 0;
00098           Date ldate = lhs->installtime();
00099           Date rdate = rhs->installtime();
00100           if ( ldate != rdate )
00101             return( ldate > rdate );
00102 
00103           // no more criteria, still equal: sort by id
00104           return lhs.satSolvable().id() < rhs.satSolvable().id();
00105         }
00106       };
00107 
00108       typedef std::set<PoolItem,AVOrder>       AvailableItemSet;
00109       typedef AvailableItemSet::iterator       available_iterator;
00110       typedef AvailableItemSet::const_iterator available_const_iterator;
00111       typedef AvailableItemSet::size_type      available_size_type;
00112 
00113       typedef std::set<PoolItem,IOrder>        InstalledItemSet;
00114       typedef AvailableItemSet::iterator       installed_iterator;
00115       typedef AvailableItemSet::const_iterator installed_const_iterator;
00116       typedef AvailableItemSet::size_type      installed_size_type;
00117 
00118       typedef std::vector<PoolItem>             PickList;
00119       typedef PickList::const_iterator          picklist_iterator;
00120       typedef PickList::size_type               picklist_size_type;
00121     };
00123 
00125   } // namespace ui
00128 } // namespace zypp
00130 #endif // ZYPP_UI_SELECTABLETRAITS_H