1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/sat/Capabilities.h
12 #ifndef ZYPP_SAT_CAPABILITIES_H
13 #define ZYPP_SAT_CAPABILITIES_H
17 #include "zypp/sat/detail/PoolMember.h"
18 #include "zypp/Capability.h"
20 ///////////////////////////////////////////////////////////////////
22 { /////////////////////////////////////////////////////////////////
24 ///////////////////////////////////////////////////////////////////
26 // CLASS NAME : Capabilities
28 /** Container of \ref Capability (currently read only).
30 * \note satsolver dependency lists may include internal ids
31 * which must be skipped on iteration or size calculation
32 * (\see \ref detail::isDepMarkerId).
37 typedef Capability value_type;
38 typedef unsigned size_type;
40 enum Mode { SKIP_TO_INTERNAL };
48 /** Ctor from Id pointer (friend \ref Solvable). */
50 Capabilities( const sat::detail::IdType * base_r )
54 /** Ctor from Id pointer (friend \ref Solvable).
55 * Jump behind skip_r (e.g. behind prereqMarker).
57 Capabilities( const sat::detail::IdType * base_r, sat::detail::IdType skip_r );
60 /** Whether the container is empty. */
62 { return ! ( _begin && *_begin ); }
64 /** Number of capabilities inside. */
65 size_type size() const;
70 /** Iterator pointing to the first \ref Capability. */
71 const_iterator begin() const;
73 /** Iterator pointing bhind the last \ref Capability. */
74 const_iterator end() const;
77 const sat::detail::IdType * _begin;
79 ///////////////////////////////////////////////////////////////////
81 /** \relates Capabilities Stream output */
82 std::ostream & operator<<( std::ostream & str, const Capabilities & obj );
84 ///////////////////////////////////////////////////////////////////
86 // CLASS NAME : Capabilities::const_iterator
88 /** \ref Capabilities iterator.
90 class Capabilities::const_iterator : public boost::iterator_adaptor<
91 const_iterator // Derived
92 , const sat::detail::IdType * // Base
93 , const Capability // Value
94 , boost::forward_traversal_tag // CategoryOrTraversal
95 , const Capability & // Reference
100 : const_iterator::iterator_adaptor_( 0 )
103 explicit const_iterator( const sat::detail::IdType * _idx )
104 : const_iterator::iterator_adaptor_( _idx )
108 friend class boost::iterator_core_access;
110 reference dereference() const
113 template <class OtherDerived, class OtherIterator, class V, class C, class R, class D>
114 bool equal( const boost::iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> & rhs ) const
115 { // NULL pointer is eqal pointer to Id 0
116 return ( base() == rhs.base() // includes both NULL...
117 || ( !rhs.base() && !*base() )
118 || ( !base() && !*rhs.base() ) );
122 { // jump over satsolvers internal ids.
123 if ( sat::detail::isDepMarkerId( *(++base_reference()) ) ) ++base_reference();
129 { _val = ( base() ) ? Capability( *base() ) : Capability::Null; }
131 mutable Capability _val;
133 ///////////////////////////////////////////////////////////////////
135 inline Capabilities::const_iterator Capabilities::begin() const
136 { return const_iterator( _begin ); }
138 inline Capabilities::const_iterator Capabilities::end() const
139 { return const_iterator( 0 ); }
141 /////////////////////////////////////////////////////////////////
143 ///////////////////////////////////////////////////////////////////
144 #endif // ZYPP_SAT_CAPABILITIES_H