1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/sat/Capabilities.h
12 #ifndef ZYPP_SAT_CAPABILITIES_H
13 #define ZYPP_SAT_CAPABILITIES_H
17 #include <zypp/base/DefaultIntegral.h>
18 #include <zypp/sat/detail/PoolMember.h>
19 #include <zypp/Capability.h>
21 ///////////////////////////////////////////////////////////////////
23 { /////////////////////////////////////////////////////////////////
25 ///////////////////////////////////////////////////////////////////
27 // CLASS NAME : Capabilities
29 /** Container of \ref Capability (currently read only).
31 * \note libsolv dependency lists may include internal ids
32 * which must be skipped on iteration or size calculation
33 * (\see \ref detail::isDepMarkerId).
38 typedef Capability value_type;
39 typedef unsigned size_type;
41 enum Mode { SKIP_TO_INTERNAL };
49 /** Ctor from Id pointer (friend \ref Solvable). */
51 Capabilities( const sat::detail::IdType * base_r )
55 /** Ctor from Id pointer (friend \ref Solvable).
56 * Jump behind skip_r (e.g. behind prereqMarker).
58 Capabilities( const sat::detail::IdType * base_r, sat::detail::IdType skip_r );
61 /** Whether the container is empty. */
63 { return ! ( _begin && *_begin ); }
65 /** Number of capabilities inside. */
66 size_type size() const;
71 /** Iterator pointing to the first \ref Capability. */
72 const_iterator begin() const;
74 /** Iterator pointing behind the last \ref Capability. */
75 const_iterator end() const;
78 /** Return whether the set contains \a lhs (the Id)*/
79 bool contains( const Capability & lhs ) const;
81 /** Return whether \a lhs matches at least one capability in set. */
82 bool matches( const Capability & lhs ) const;
85 const sat::detail::IdType * _begin;
87 ///////////////////////////////////////////////////////////////////
89 /** \relates Capabilities Stream output */
90 std::ostream & operator<<( std::ostream & str, const Capabilities & obj );
92 ///////////////////////////////////////////////////////////////////
94 // CLASS NAME : Capabilities::const_iterator
96 /** \ref Capabilities iterator.
98 class Capabilities::const_iterator : public boost::iterator_adaptor<
99 const_iterator // Derived
100 , const sat::detail::IdType * // Base
101 , const Capability // Value
102 , boost::forward_traversal_tag // CategoryOrTraversal
103 , const Capability // Reference
108 : const_iterator::iterator_adaptor_( 0 )
111 explicit const_iterator( const sat::detail::IdType * _idx )
112 : const_iterator::iterator_adaptor_( _idx )
114 if ( base_reference() && sat::detail::isDepMarkerId( *base_reference() ) )
122 /** Return \c true if the \ref Capability is \c tagged.
123 * The meaning of \c tagged depends on the kind of dependency you
124 * are processing. It is a hint that the iteratir skipped some
125 * internal marker, indicating that subsequent cabailities have
126 * a special property. Within a \ref Solvables requirements e.g.
127 * the pre-requirements are tagged.
129 * Capabilities req( solvable.requires() );
130 * for_( it, req.begin(), req.end() )
133 * cout << *it << " (is prereq)" << endl;
135 * cout << *it << endl;
139 bool tagged() const { return _tagged; }
142 friend class boost::iterator_core_access;
144 reference dereference() const
145 { return ( base() ) ? Capability( *base() ) : Capability::Null; }
147 template <class OtherDerived, class OtherIterator, class V, class C, class R, class D>
148 bool equal( const boost::iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> & rhs ) const
149 { // NULL pointer is eqal pointer to Id 0
150 return ( base() == rhs.base() // includes both NULL...
151 || ( !rhs.base() && !*base() )
152 || ( !base() && !*rhs.base() ) );
156 { // jump over libsolvs internal ids.
157 if ( sat::detail::isDepMarkerId( *(++base_reference()) ) )
165 DefaultIntegral<bool,false> _tagged;
167 ///////////////////////////////////////////////////////////////////
169 inline Capabilities::const_iterator Capabilities::begin() const
170 { return const_iterator( _begin ); }
172 inline Capabilities::const_iterator Capabilities::end() const
173 { return const_iterator( 0 ); }
175 inline bool Capabilities::contains( const Capability & lhs ) const
177 for ( const Capability & rhs : *this )
183 inline bool Capabilities::matches( const Capability & lhs ) const
185 for ( const Capability & rhs : *this )
186 if ( lhs.matches( rhs ) == CapMatch::yes )
190 /////////////////////////////////////////////////////////////////
192 ///////////////////////////////////////////////////////////////////
193 #endif // ZYPP_SAT_CAPABILITIES_H