WhatProvides.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #ifndef ZYPP_SAT_WHATPROVIDES_H
00013 #define ZYPP_SAT_WHATPROVIDES_H
00014 
00015 #include <iosfwd>
00016 #include <vector>
00017 
00018 #include "zypp/base/PtrTypes.h"
00019 #include "zypp/sat/detail/PoolMember.h"
00020 #include "zypp/sat/Solvable.h"
00021 #include "zypp/sat/SolvIterMixin.h"
00022 
00024 namespace zypp
00025 { 
00026 
00027   namespace sat
00028   { 
00029 
00030     namespace detail
00031     {
00032       class WhatProvidesIterator;
00033     }
00034 
00036     //
00037     //  CLASS NAME : WhatProvides
00038     //
00087     class WhatProvides : public SolvIterMixin<WhatProvides,detail::WhatProvidesIterator>,
00088                          protected detail::PoolMember
00089     {
00090       public:
00091         typedef Solvable  value_type;
00092         typedef unsigned  size_type;
00093 
00094       public:
00096         WhatProvides();
00097 
00099         explicit
00100         WhatProvides( Capability cap_r );
00101 
00103         explicit
00104         WhatProvides( Capabilities caps_r );
00105 
00107         explicit
00108         WhatProvides( const CapabilitySet & caps_r );
00109 
00110      public:
00112         bool empty() const;
00113 
00115         size_type size() const;
00116 
00117       public:
00118         typedef detail::WhatProvidesIterator const_iterator;
00119 
00121         const_iterator begin() const;
00122 
00124         const_iterator end() const;
00125 
00126       private:
00127         struct Impl;
00128         RW_pointer<Impl> _pimpl;
00129     };
00131 
00133     std::ostream & operator<<( std::ostream & str, const WhatProvides & obj );
00134 
00135     namespace detail
00136     {
00138     //
00139     //  CLASS NAME : WhatProvides::const_iterator
00140     //
00146     class WhatProvidesIterator : public boost::iterator_adaptor<
00147           WhatProvidesIterator         // Derived
00148         , const detail::IdType *       // Base
00149         , const Solvable               // Value
00150         , boost::forward_traversal_tag // CategoryOrTraversal
00151         , const Solvable               // Reference
00152         >
00153     {
00154       friend std::ostream & operator<<( std::ostream & str, const WhatProvidesIterator & obj );
00155       public:
00156         WhatProvidesIterator()
00157         : iterator_adaptor_( 0 ), _baseRef( 0 ), _offset( 0 )
00158         {}
00159 
00163         explicit WhatProvidesIterator( const detail::IdType *const base_r, unsigned offset_r = 0 )
00164         : iterator_adaptor_( base_r ), _baseRef( base_r ? &base_reference() : 0 ), _offset( offset_r )
00165         {}
00166 
00170         explicit WhatProvidesIterator( const detail::IdType *const* baseRef_r, unsigned offset_r )
00171         : iterator_adaptor_( 0 ), _baseRef( baseRef_r ), _offset( offset_r )
00172         {}
00173 
00175         WhatProvidesIterator( const WhatProvidesIterator & rhs )
00176         : iterator_adaptor_( rhs.base_reference() )
00177         , _baseRef( base_reference() ? &base_reference() : rhs._baseRef )
00178         , _offset( rhs._offset )
00179         {}
00180 
00182         WhatProvidesIterator & operator=( const WhatProvidesIterator & rhs )
00183         {
00184           if ( this != &rhs ) // no self assign
00185           {
00186             base_reference() = rhs.base_reference();
00187             _baseRef = ( base_reference() ? &base_reference() : rhs._baseRef );
00188             _offset = rhs._offset;
00189           }
00190           return *this;
00191         }
00192 
00193       private:
00194         friend class boost::iterator_core_access;
00195 
00196         reference dereference() const
00197         { return Solvable( getId() ); }
00198 #if 0
00199         template <class OtherDerived, class OtherIterator, class V, class C, class R, class D>
00200         bool equal( const boost::iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> & rhs ) const
00201 #endif
00202         bool equal( const WhatProvidesIterator & rhs ) const
00203         {
00204           if ( ! ( getId() || rhs.getId() ) )
00205             return true; // both @end
00206           if ( _offset != rhs._offset )
00207             return false;
00208           if ( base_reference() )
00209             return( base_reference() == rhs.base_reference() );
00210           return( _baseRef == rhs._baseRef );
00211         }
00212 
00213         void increment()
00214         { ++_offset; }
00215 
00216         detail::IdType getId() const
00217         { return _baseRef ? (*_baseRef)[_offset] : detail::noId; }
00218 
00219       private:
00220         const detail::IdType *const* _baseRef;
00221         unsigned                     _offset;
00222     };
00224     }
00225 
00226     inline WhatProvides::const_iterator WhatProvides::end() const
00227     { return const_iterator(); }
00228 
00230   } // namespace sat
00233 } // namespace zypp
00235 #endif // ZYPP_SAT_WHATPROVIDES_H

doxygen