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 
00017 #include "zypp/base/Iterator.h"
00018 #include "zypp/PoolItem.h"
00019 #include "zypp/ResObject.h"
00020 
00022 namespace zypp
00023 { 
00024 
00025   namespace ui
00026   { 
00027 
00029     //
00030     //  CLASS NAME : SelectableTraits
00031     //
00033     struct SelectableTraits
00034     {
00040       struct AVOrder : public std::binary_function<PoolItem,PoolItem,bool>
00041       {
00042         // NOTE: operator() provides LESS semantics to order the set.
00043         // So LESS means 'prior in set'. We want 'better' archs and
00044         // 'better' editions at the beginning of the set. So we return
00045         // TRUE if (lhs > rhs)!
00046         //
00047         bool operator()( const PoolItem & lhs, const PoolItem & rhs ) const
00048         {
00049           int res = lhs->arch().compare( rhs->arch() );
00050           if ( res )
00051             return res > 0;
00052           res = lhs->edition().compare( rhs->edition() );
00053           if ( res )
00054             return res > 0;
00055 
00056           // no more criteria, still equal:
00057           // use the ResObject::constPtr (the poiner value)
00058           // (here it's arbitrary whether < or > )
00059           return lhs.resolvable() < rhs.resolvable();
00060         }
00061       };
00062 
00063       typedef std::set<PoolItem,AVOrder>       AvialableItemSet;
00064       typedef AvialableItemSet::iterator       availableItem_iterator;
00065       typedef AvialableItemSet::const_iterator availableItem_const_iterator;
00066       typedef AvialableItemSet::size_type      availableItem_size_type;
00067 
00069       struct TransformToResObjectPtr : public std::unary_function<PoolItem,ResObject::constPtr>
00070       {
00071         ResObject::constPtr operator()( const PoolItem & obj ) const
00072         { return obj; }
00073       };
00074 
00075       typedef transform_iterator<TransformToResObjectPtr, availableItem_const_iterator>
00076               available_iterator;
00077 
00078   };
00080 
00082   } // namespace ui
00085 } // namespace zypp
00087 #endif // ZYPP_UI_SELECTABLETRAITS_H

Generated on Thu Jul 6 00:07:28 2006 for zypp by  doxygen 1.4.6