libzypp  17.25.1
WhatProvides.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #include <iostream>
13 
14 #include <zypp/base/LogTools.h>
15 #include <zypp/sat/WhatProvides.h>
17 
18 using std::endl;
19 
21 namespace zypp
22 {
23  namespace sat
25  {
26 
28  //
29  // CLASS NAME : WhatProvides::Impl
30  //
42  {
43  public:
44  Impl()
45  : _offset( 0 ), _private( 0 )
46  {}
47 
48  Impl( unsigned offset_r )
49  : _offset( offset_r ), _private( 0 )
50  {}
51 
52  Impl( const std::unordered_set<detail::IdType> & ids_r )
53  : _offset( 0 ), _private( 0 )
54  {
55  // use private data to store the result (incl. trailing NULL)
56  _pdata.reserve( ids_r.size()+1 );
57  _pdata.insert( _pdata.begin(), ids_r.begin(), ids_r.end() );
58  _pdata.push_back( detail::noId );
59 
60  _private = &_pdata.front(); // ptr to 1st element
61  }
62 
63  public:
64  unsigned _offset;
66 
67  private:
68  std::vector<sat::detail::IdType> _pdata;
69  };
71 
73  namespace
74  {
75 
77  template <class Iterator>
78  void collectProviders( Iterator begin_r, Iterator end_r, std::unordered_set<detail::IdType> & collect_r )
79  {
80  for_( it, begin_r, end_r )
81  {
82  WhatProvides providers( *it );
83  for_( prv, providers.begin(), providers.end() )
84  {
85  collect_r.insert( prv->id() );
86  }
87  }
88  }
89 
91  } //namespace
93 
95  {}
96 
98  {
99  unsigned res( myPool().whatProvides( cap_r ) );
100  if ( myPool().whatProvidesData( res ) )
101  {
102  _pimpl.reset( new Impl( res ) );
103  }
104  // else: no Impl for empty result.
105  }
106 
108  {
109  std::unordered_set<detail::IdType> ids;
110  collectProviders( caps_r.begin(), caps_r.end(), ids );
111  if ( ! ids.empty() )
112  {
113  _pimpl.reset( new Impl( ids ) );
114  }
115  // else: no Impl for empty result.
116  }
117 
119  {
120  std::unordered_set<detail::IdType> ids;
121  collectProviders( caps_r.begin(), caps_r.end(), ids );
122  if ( ! ids.empty() )
123  {
124  _pimpl.reset( new Impl( ids ) );
125  }
126  // else: no Impl for empty result.
127  }
128 
129  bool WhatProvides::empty() const
130  {
131  return !_pimpl; // Ctor asserts no Impl for empty result.
132  }
133 
135  {
136  if ( !_pimpl )
137  return 0;
138 
139  size_type count = 0;
140  for_( it, begin(), end() )
141  ++count;
142  return count;
143  }
144 
146  {
147  if ( !_pimpl )
148  return const_iterator();
149 
150  if ( _pimpl->_private )
151  return const_iterator( _pimpl->_private );
152 
153  // for libsolvs index use one more indirection, as it might get relocated.
154  return const_iterator( &myPool().getPool()->whatprovidesdata, _pimpl->_offset );
155  }
156 
157  /******************************************************************
158  **
159  ** FUNCTION NAME : operator<<
160  ** FUNCTION TYPE : std::ostream &
161  */
162  std::ostream & operator<<( std::ostream & str, const WhatProvides & obj )
163  {
164  return dumpRange( str << "(" << obj.size() << ")", obj.begin(), obj.end() );
165  }
166 
168  namespace detail
169  {
170 
171  std::ostream & operator<<( std::ostream & str, const WhatProvidesIterator & obj )
172  {
173  str << str::form( "[%5u]", obj._offset );
174  str << str::form( "<%p(%p)>", obj.base_reference(), &obj.base_reference() );
175  str << str::form( "<%p(%p)>", obj._baseRef, (obj._baseRef ? *obj._baseRef : 0) );
176  return str;
177  }
178 
180  } //namespace detail
182 
184  } // namespace sat
187 } // namespace zypp
zypp::sat::WhatProvides::Impl::Impl
Impl(unsigned offset_r)
Definition: WhatProvides.cc:48
zypp::sat::WhatProvides
Container of Solvable providing a Capability (read only).
Definition: WhatProvides.h:87
zypp::sat::WhatProvides::Impl::_pdata
std::vector< sat::detail::IdType > _pdata
Definition: WhatProvides.cc:68
zypp::sat::WhatProvides::empty
bool empty() const
Whether the container is empty.
Definition: WhatProvides.cc:129
zypp::sat::WhatProvides::size
size_type size() const
Number of solvables inside.
Definition: WhatProvides.cc:134
zypp::sat::detail::noId
static const IdType noId(0)
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:91
zypp::Capabilities::begin
const_iterator begin() const
Iterator pointing to the first Capability.
Definition: Capabilities.h:169
zypp::sat::WhatProvides::Impl::Impl
Impl()
Definition: WhatProvides.cc:44
zypp::RW_pointer::reset
void reset()
Definition: PtrTypes.h:309
zypp::sat::WhatProvides::size_type
unsigned size_type
Definition: WhatProvides.h:92
zypp::sat::detail::operator<<
std::ostream & operator<<(std::ostream &str, const DIWrap &obj)
Definition: LookupAttr.cc:337
zypp::sat::detail::PoolMember::myPool
static PoolImpl & myPool()
Definition: PoolImpl.cc:178
zypp::sat::WhatProvides::end
const_iterator end() const
Iterator pointing behind the last Solvable.
Definition: WhatProvides.h:226
zypp::sat::detail::WhatProvidesIterator::_offset
unsigned _offset
Definition: WhatProvides.h:221
zypp::sat::WhatProvides::begin
const_iterator begin() const
Iterator pointing to the first Solvable.
Definition: WhatProvides.cc:145
zypp::sat::WhatProvides::Impl
WhatProvides implementation date.
Definition: WhatProvides.cc:41
zypp::sat::detail::WhatProvidesIterator::_baseRef
const detail::IdType *const * _baseRef
Definition: WhatProvides.h:220
WhatProvides.h
LogTools.h
zypp::CapabilitySet
std::unordered_set< Capability > CapabilitySet
Definition: Capability.h:33
PoolImpl.h
zypp::Capabilities::end
const_iterator end() const
Iterator pointing behind the last Capability.
Definition: Capabilities.h:172
zypp::sat::detail::IdType
int IdType
Generic Id type.
Definition: PoolMember.h:104
zypp::str::form
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Definition: String.cc:35
zypp::sat::operator<<
std::ostream & operator<<(std::ostream &str, const FileConflicts &obj)
Definition: FileConflicts.cc:109
zypp::sat::WhatProvides::_pimpl
RW_pointer< Impl > _pimpl
Definition: WhatProvides.h:127
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
zypp::Capability
A sat capability.
Definition: Capability.h:59
for_
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:28
zypp::sat::detail::WhatProvidesIterator
WhatProvides iterator.
Definition: WhatProvides.h:146
zypp::sat::WhatProvides::Impl::Impl
Impl(const std::unordered_set< detail::IdType > &ids_r)
Definition: WhatProvides.cc:52
zypp::sat::detail::PoolMember
Backlink to the associated PoolImpl.
Definition: PoolMember.h:88
str
String related utilities and Regular expression matching.
zypp::sat::WhatProvides::Impl::_offset
unsigned _offset
Definition: WhatProvides.cc:64
zypp::sat::WhatProvides::const_iterator
detail::WhatProvidesIterator const_iterator
Definition: WhatProvides.h:118
zypp::sat::WhatProvides::WhatProvides
WhatProvides()
Default ctor.
Definition: WhatProvides.cc:94
zypp::sat::WhatProvides::Impl::_private
const detail::IdType * _private
Definition: WhatProvides.cc:65
zypp::Capabilities
Container of Capability (currently read only).
Definition: Capabilities.h:35