1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/sat/SolvableSet.h
12 #ifndef ZYPP_SAT_SOLVABLESET_H
13 #define ZYPP_SAT_SOLVABLESET_H
17 #include "zypp/base/PtrTypes.h"
18 #include "zypp/base/Hash.h"
19 #include "zypp/sat/Solvable.h"
20 #include "zypp/sat/SolvIterMixin.h"
22 ///////////////////////////////////////////////////////////////////
24 { /////////////////////////////////////////////////////////////////
25 ///////////////////////////////////////////////////////////////////
27 { /////////////////////////////////////////////////////////////////
29 ///////////////////////////////////////////////////////////////////
31 // CLASS NAME : SolvableSet
33 /** Solvable set wrapper to allow adding additional convenience iterators.
35 class SolvableSet : public SolvIterMixin<SolvableSet,std::unordered_set<Solvable>::const_iterator>
37 friend std::ostream & operator<<( std::ostream & str, const SolvableSet & obj );
40 typedef std::unordered_set<Solvable> Container;
41 typedef Container::value_type value_type;
42 typedef Container::size_type size_type;
43 typedef Solvable_iterator const_iterator; // from SolvIterMixin
48 : _pimpl( new Container )
51 /** Ctor building a set from a range. */
52 template<class TInputIterator>
53 SolvableSet( TInputIterator begin_r, TInputIterator end_r )
54 : _pimpl( new Container( begin_r, end_r ) )
58 /** Whether the set is epmty. */
60 { return _pimpl->empty(); }
62 /** Size of the set. */
63 size_type size() const
64 { return _pimpl->size(); }
68 bool contains( const TSolv & solv_r ) const
69 { return( get().count( asSolvable()( solv_r ) ) ); }
71 /** Iterator pointing to the first \ref Solvable. */
72 const_iterator begin() const
73 { return _pimpl->begin(); }
75 /** Iterator pointing behind the last \ref Solvable. */
76 const_iterator end() const
77 { return _pimpl->end(); }
80 /** Clear the container */
84 /** Insert a Solvable.
85 * \return \c true if it was actually inserted, or \c false if already present.
88 bool insert( const TSolv & solv_r )
89 { return get().insert( asSolvable()( solv_r ) ).second; }
91 /** Insert a range of Solvables. */
92 template<class TIterator>
93 void insert( TIterator begin_r, TIterator end_r )
94 { for_( it, begin_r, end_r ) insert( *it ); }
102 const Container & get() const
106 /** Pointer to implementation */
107 RWCOW_pointer<Container> _pimpl;
109 ///////////////////////////////////////////////////////////////////
111 /** \relates SolvableSet Stream output */
112 std::ostream & operator<<( std::ostream & str, const SolvableSet & obj );
114 /////////////////////////////////////////////////////////////////
116 ///////////////////////////////////////////////////////////////////
117 /////////////////////////////////////////////////////////////////
119 ///////////////////////////////////////////////////////////////////
120 #endif // ZYPP_SAT_SOLVABLESET_H