libzypp
10.5.0
|
00001 /*---------------------------------------------------------------------\ 00002 | ____ _ __ __ ___ | 00003 | |__ / \ / / . \ . \ | 00004 | / / \ V /| _/ _/ | 00005 | / /__ | | | | | | | 00006 | /_____||_| |_| |_| | 00007 | | 00008 \---------------------------------------------------------------------*/ 00012 #ifndef ZYPP_SAT_CAPABILITIES_H 00013 #define ZYPP_SAT_CAPABILITIES_H 00014 00015 #include <iosfwd> 00016 00017 #include "zypp/base/DefaultIntegral.h" 00018 #include "zypp/sat/detail/PoolMember.h" 00019 #include "zypp/Capability.h" 00020 00022 namespace zypp 00023 { 00024 00026 // 00027 // CLASS NAME : Capabilities 00028 // 00035 class Capabilities 00036 { 00037 public: 00038 typedef Capability value_type; 00039 typedef unsigned size_type; 00040 00041 enum Mode { SKIP_TO_INTERNAL }; 00042 00043 public: 00045 Capabilities() 00046 : _begin( 0 ) 00047 {} 00048 00050 explicit 00051 Capabilities( const sat::detail::IdType * base_r ) 00052 : _begin( base_r ) 00053 {} 00054 00058 Capabilities( const sat::detail::IdType * base_r, sat::detail::IdType skip_r ); 00059 00060 public: 00062 bool empty() const 00063 { return ! ( _begin && *_begin ); } 00064 00066 size_type size() const; 00067 00068 public: 00069 class const_iterator; 00070 00072 const_iterator begin() const; 00073 00075 const_iterator end() const; 00076 00077 private: 00078 const sat::detail::IdType * _begin; 00079 }; 00081 00083 std::ostream & operator<<( std::ostream & str, const Capabilities & obj ); 00084 00086 // 00087 // CLASS NAME : Capabilities::const_iterator 00088 // 00091 class Capabilities::const_iterator : public boost::iterator_adaptor< 00092 const_iterator // Derived 00093 , const sat::detail::IdType * // Base 00094 , const Capability // Value 00095 , boost::forward_traversal_tag // CategoryOrTraversal 00096 , const Capability // Reference 00097 > 00098 { 00099 public: 00100 const_iterator() 00101 : const_iterator::iterator_adaptor_( 0 ) 00102 {} 00103 00104 explicit const_iterator( const sat::detail::IdType * _idx ) 00105 : const_iterator::iterator_adaptor_( _idx ) 00106 { 00107 if ( base_reference() && sat::detail::isDepMarkerId( *base_reference() ) ) 00108 { 00109 _tagged = true; 00110 ++base_reference(); 00111 } 00112 } 00113 00114 public: 00132 bool tagged() const { return _tagged; } 00133 00134 private: 00135 friend class boost::iterator_core_access; 00136 00137 reference dereference() const 00138 { return ( base() ) ? Capability( *base() ) : Capability::Null; } 00139 00140 template <class OtherDerived, class OtherIterator, class V, class C, class R, class D> 00141 bool equal( const boost::iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> & rhs ) const 00142 { // NULL pointer is eqal pointer to Id 0 00143 return ( base() == rhs.base() // includes both NULL... 00144 || ( !rhs.base() && !*base() ) 00145 || ( !base() && !*rhs.base() ) ); 00146 } 00147 00148 void increment() 00149 { // jump over libsolvs internal ids. 00150 if ( sat::detail::isDepMarkerId( *(++base_reference()) ) ) 00151 { 00152 _tagged = true; 00153 ++base_reference(); 00154 } 00155 } 00156 00157 private: 00158 DefaultIntegral<bool,false> _tagged; 00159 }; 00161 00162 inline Capabilities::const_iterator Capabilities::begin() const 00163 { return const_iterator( _begin ); } 00164 00165 inline Capabilities::const_iterator Capabilities::end() const 00166 { return const_iterator( 0 ); } 00167 00169 } // namespace zypp 00171 #endif // ZYPP_SAT_CAPABILITIES_H