libzypp  10.5.0
SolvableSet.h
Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #ifndef ZYPP_SAT_SOLVABLESET_H
00013 #define ZYPP_SAT_SOLVABLESET_H
00014 
00015 #include <iosfwd>
00016 
00017 #include "zypp/base/PtrTypes.h"
00018 #include "zypp/base/Tr1hash.h"
00019 #include "zypp/sat/Solvable.h"
00020 #include "zypp/sat/SolvIterMixin.h"
00021 
00023 namespace zypp
00024 { 
00025 
00026   namespace sat
00027   { 
00028 
00030     //
00031     //  CLASS NAME : SolvableSet
00032     //
00035     class SolvableSet : public SolvIterMixin<SolvableSet,std::tr1::unordered_set<Solvable>::const_iterator>
00036     {
00037       friend std::ostream & operator<<( std::ostream & str, const SolvableSet & obj );
00038 
00039       public:
00040         typedef std::tr1::unordered_set<Solvable> Container;
00041         typedef Container::value_type             value_type;
00042         typedef Container::size_type              size_type;
00043         typedef Solvable_iterator                 const_iterator; // from SolvIterMixin
00044 
00045       public:
00047         SolvableSet()
00048         : _pimpl( new Container )
00049         {}
00050 
00052         template<class _InputIterator>
00053         SolvableSet( _InputIterator begin_r, _InputIterator end_r )
00054         : _pimpl( new Container( begin_r, end_r ) )
00055         {}
00056 
00057       public:
00059         bool empty() const
00060         { return _pimpl->empty(); }
00061 
00063         size_type size() const
00064         { return _pimpl->size(); }
00065 
00067         template<class _Solv>
00068         bool contains( const _Solv & solv_r ) const
00069         { return( get().find( asSolvable()( solv_r ) ) != end() ); }
00070 
00072         const_iterator begin() const
00073         { return _pimpl->begin(); }
00074 
00076         const_iterator end() const
00077         { return _pimpl->end(); }
00078 
00079       public:
00080 
00084         template<class _Solv>
00085         bool insert( const _Solv & solv_r )
00086         { return get().insert( asSolvable()( solv_r ) ).second; }
00087 
00088       public:
00090         Container & get()
00091         { return *_pimpl; }
00092 
00094         const Container & get() const
00095         { return *_pimpl; }
00096 
00097       private:
00099         RWCOW_pointer<Container> _pimpl;
00100     };
00102 
00104     std::ostream & operator<<( std::ostream & str, const SolvableSet & obj );
00105 
00107   } // namespace sat
00110 } // namespace zypp
00112 #endif // ZYPP_SAT_SOLVABLESET_H