libzypp: zypp/PoolItemBest.cc Source File

libzypp 17.38.11

PoolItemBest.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#include <iostream>
13#include <zypp-core/base/LogTools.h>
14
15#include <zypp/PoolItemBest.h>
16#include <zypp/ui/SelectableTraits.h>
17
18using std::endl;
19
21namespace zypp
22{
23
25 //
26 // CLASS NAME : PoolItemBest::Impl
27 //
29 struct PoolItemBest::Impl
30 {
31 Impl( bool preferNotLocked_r )
32 : _preferNotLocked { preferNotLocked_r }
33 {}
34
35 Container _container;
36 bool _preferNotLocked;
37
38 private:
39 friend Impl * rwcowClone<Impl>( const Impl * rhs );
41 Impl * clone() const
42 { return new Impl( *this ); }
43 };
44
45
47 //
48 // CLASS NAME : PoolItemBest
49 //
51
52 void PoolItemBest::_ctor_init( bool preferNotLocked_r )
53 { _dont_use_this_use_pimpl.reset( new RWCOW_pointer<Impl>(new Impl( preferNotLocked_r )) ); }
54
55 void PoolItemBest::_ctor_init()
56 { _ctor_init( /*preferNotLocked*/false ); }
57
58 const PoolItemBest::Container & PoolItemBest::container() const
59 { return pimpl()->_container; }
60
61 void PoolItemBest::add( const PoolItem & pi_r )
62 {
63 Container & container( pimpl()->_container );
64
65 PoolItem & ccand( container[pi_r.satSolvable().ident()] );
66 if ( ! ccand )
67 ccand = pi_r;
68 else if ( pimpl()->_preferNotLocked )
69 {
70 if ( ! pi_r.status().isLocked() )
71 {
72 if ( ccand.status().isLocked() || ui::SelectableTraits::AVOrder()( pi_r, ccand ) )
73 ccand = pi_r;
74 }
75 else if ( ccand.status().isLocked() )
76 {
77 if ( ui::SelectableTraits::AVOrder()( pi_r, ccand ) )
78 ccand = pi_r;
79 }
80 }
81 else if ( ui::SelectableTraits::AVOrder()( pi_r, ccand ) )
82 ccand = pi_r;
83 }
84
85 PoolItem PoolItemBest::find( IdString ident_r ) const
86 {
87 const Container & container( pimpl()->_container );
88 Container::const_iterator it( container.find( ident_r ) );
89 return it != container.end() ? it->second : PoolItem();
90 }
91
92 /******************************************************************
93 **
94 ** FUNCTION NAME : operator<<
95 ** FUNCTION TYPE : std::ostream &
96 */
97 std::ostream & operator<<( std::ostream & str, const PoolItemBest & obj )
98 {
99 return dumpRange( str << "(" << obj.size() << ") ", obj.begin(), obj.end() );
100 }
101
103} // namespace zypp
LogTools.h
PoolItemBest.h
SelectableTraits.h
zypp::IdString
Access to the sat-pools string space.
Definition IdString.h:55
zypp::PoolItemBest
Find the best candidates e.g.
Definition PoolItemBest.h:64
zypp::PoolItemBest::pimpl
RWCOW_pointer< Impl > & pimpl()
Pointer to implementation.
Definition PoolItemBest.h:149
zypp::PoolItemBest::size
size_type size() const
Number of PoolItems collected.
Definition PoolItemBest.h:119
zypp::PoolItemBest::_dont_use_this_use_pimpl
shared_ptr< void > _dont_use_this_use_pimpl
Avoid need to include Impl definition when inlined ctors (due to tepmlate) are provided.
Definition PoolItemBest.h:153
zypp::PoolItemBest::container
const Container & container() const
Definition PoolItemBest.cc:58
zypp::PoolItemBest::find
PoolItem find(IdString ident_r) const
Return the collected PoolItem with sat::Solvable::ident ident_r.
Definition PoolItemBest.cc:85
zypp::PoolItemBest::_ctor_init
void _ctor_init()
bin.compat legacy
Definition PoolItemBest.cc:55
zypp::PoolItemBest::begin
iterator begin() const
Pointer to the first PoolItem.
Definition PoolItemBest.h:121
zypp::PoolItemBest::end
iterator end() const
Pointer behind the last PoolItem.
Definition PoolItemBest.h:123
zypp::PoolItemBest::add
void add(sat::Solvable slv_r)
Feed one sat::Solvable.
Definition PoolItemBest.h:99
zypp::PoolItemBest::Container
std::unordered_map< IdString, PoolItem > Container
Definition PoolItemBest.h:65
zypp::PoolItem
Combining sat::Solvable and ResStatus.
Definition PoolItem.h:51
zypp::PoolItem::status
ResStatus & status() const
Returns the current status.
Definition PoolItem.cc:212
zypp::ResStatus::isLocked
bool isLocked() const
Definition ResStatus.h:270
zypp::sat::Solvable::ident
IdString ident() const
The identifier.
Definition Solvable.cc:273
str
String related utilities and Regular expression matching.
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
zypp::dumpRange
std::ostream & dumpRange(std::ostream &str, TIterator begin, TIterator end, const std::string &intro="{", const std::string &pfx="\n ", const std::string &sep="\n ", const std::string &sfx="\n", const std::string &extro="}")
Print range defined by iterators (multiline style).
Definition LogTools.h:419
zypp::operator<<
std::ostream & operator<<(std::ostream &str, const Capabilities &obj)
relates: Capabilities Stream output
Definition Capabilities.cc:65
zypp::PoolItemBest::Impl
PoolItemBest implementation.
Definition PoolItemBest.cc:30
zypp::PoolItemBest::Impl::Impl
Impl(bool preferNotLocked_r)
Definition PoolItemBest.cc:31
zypp::PoolItemBest::Impl::rwcowClone
friend Impl * rwcowClone(const Impl *rhs)
zypp::PoolItemBest::Impl::clone
Impl * clone() const
clone for RWCOW_pointer
Definition PoolItemBest.cc:41
zypp::PoolItemBest::Impl::_preferNotLocked
bool _preferNotLocked
Definition PoolItemBest.cc:36
zypp::PoolItemBest::Impl::_container
Container _container
Definition PoolItemBest.cc:35
zypp::RWCOW_pointer
RW_pointer supporting 'copy on write' functionality.
Definition PtrTypes.h:469
zypp::sat::SolvableType::satSolvable
Solvable satSolvable() const
Return the corresponding sat::Solvable.
Definition SolvableType.h:57
zypp::ui::SelectableTraits::AVOrder
Oder on AvailableItemSet.
Definition SelectableTraits.h:45