libzypp  13.10.6
Pattern.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #include <iostream>
13 #include "zypp/base/LogTools.h"
14 
15 #include "zypp/ResPool.h"
16 #include "zypp/Pattern.h"
17 #include "zypp/Filter.h"
18 
19 using std::endl;
20 
22 namespace zypp
23 {
24 
26  namespace
27  {
28  //
30  // CLASS NAME : PatternExpander
31  //
38  class PatternExpander
39  {
40  public:
41  typedef std::map<Pattern::constPtr, DefaultIntegral<bool, false> > PatternMap;
43  typedef PatternMap::key_type value_type;
44  typedef MapKVIteratorTraits<PatternMap>::Key_const_iterator const_iterator;
45 
46  public:
47  PatternExpander()
48  {}
49 
51  size_type doExpand( Pattern::constPtr pat_r )
52  {
53  // INT << "+++ " << pat_r << " ++++++++++++++++++++++++++++++++++" << endl;
54  _patternMap.clear();
55  if ( pat_r )
56  {
57  _patternMap[pat_r];
58  Pattern::constPtr unprocessed( pat_r );
59  // MIL << _patternMap << endl;
60  do {
61  expandIncludes( unprocessed );
62  expandExtending( unprocessed );
63  _patternMap[unprocessed] = true;
64  // MIL << _patternMap << endl;
65  } while( (unprocessed = nextUnprocessed()) );
66  }
67  // SEC << "--- " << _patternMap.size() << " ----------------------------------" << endl;
68  return _patternMap.size();
69  }
70 
71  const_iterator begin() const
72  { return make_map_key_begin( _patternMap ); }
73 
74  const_iterator end() const
75  { return make_map_key_end( _patternMap ); }
76 
77  private:
79  Pattern::constPtr nextUnprocessed() const
80  {
81  for_( it, _patternMap.begin(), _patternMap.end() )
82  {
83  if ( ! it->second )
84  return it->first;
85  }
86  return NULL;
87  }
88 
89  private:
91  void expandIncludes( const Pattern::constPtr & pat_r )
92  {
93  Pattern::NameList c( pat_r->includes() );
94  for_( it, c.begin(), c.end() )
95  {
96  expandInclude( Capability( it->c_str()/*, *ResKind::pattern*/ ) );
97  }
98  }
99 
101  void expandInclude( const Capability & include_r )
102  {
103  sat::WhatProvides w( include_r );
104  for_( it, w.begin(), w.end() )
105  {
106  _patternMap[asKind<Pattern>(PoolItem(*it))];
107  }
108  }
109 
110  private:
112  void expandExtending( const Pattern::constPtr & pat_r )
113  {
114  ResPool pool( ResPool::instance() );
115  for_( it, pool.byKindBegin<Pattern>(), pool.byKindEnd<Pattern>() )
116  {
117  expandIfExtends( pat_r, *it );
118  }
119  }
120 
122  void expandIfExtends( const Pattern::constPtr & pat_r, const PoolItem & extending_r )
123  {
124  Pattern::constPtr extending( asKind<Pattern>(extending_r) );
125  Pattern::NameList c( extending->extends() );
126  for_( it, c.begin(), c.end() )
127  {
128  if ( providedBy( pat_r, Capability( it->c_str()/*, *ResKind::pattern*/ ) ) )
129  {
130  // an extends matches the Pattern
131  _patternMap[extending];
132  break;
133  }
134  }
135  }
136 
138  bool providedBy( const Pattern::constPtr & pat_r, const Capability & extends_r )
139  {
140  if ( !pat_r )
141  return false;
142 
143  sat::Solvable pat( pat_r->satSolvable() );
144  sat::WhatProvides w( extends_r );
145  for_( it, w.begin(), w.end() )
146  {
147  if ( pat == *it )
148  return true;
149  }
150  return false;
151  }
152 
153  private:
154  PatternMap _patternMap;
155  };
157  } // namespace
159  IMPL_PTR_TYPE(Pattern);
160 
162  //
163  // METHOD NAME : Pattern::Pattern
164  // METHOD TYPE : Ctor
165  //
166  Pattern::Pattern( const sat::Solvable & solvable_r )
167  : ResObject( solvable_r )
168  {}
169 
171  //
172  // METHOD NAME : Pattern::~Pattern
173  // METHOD TYPE : Dtor
174  //
176  {}
177 
179  //
180  // Pattern interface forwarded to implementation
181  //
183 
184  bool Pattern::isDefault() const
187  bool Pattern::userVisible() const
190  std::string Pattern::category( const Locale & lang_r ) const
191  { return lookupStrAttribute( sat::SolvAttr::category, lang_r ); }
193  Pathname Pattern::icon() const
196  Pathname Pattern::script() const
198 
199  std::string Pattern::order() const
201 
204 
207 
209  {
210  // get items providing the requirements
211  sat::WhatProvides prv( requires() );
212  // return packages only.
213  return Pattern::Contents( make_filter_begin( filter::byKind<Package>(), prv ),
214  make_filter_end( filter::byKind<Package>(), prv ) );
215  }
216 
218  {
219  // load requires, recommends, suggests
220  CapabilitySet caps;
221  {
222  Capabilities c( requires() );
223  caps.insert( c.begin(),c.end() );
224  c = recommends();
225  caps.insert( c.begin(),c.end() );
226  c = suggests();
227  caps.insert( c.begin(),c.end() );
228  }
229  // get items providing the above
230  sat::WhatProvides prv( caps );
231  // return packages only.
232  return Pattern::Contents( make_filter_begin( filter::byKind<Package>(), prv ),
233  make_filter_end( filter::byKind<Package>(), prv ) );
234  }
235 
237  {
238  PatternExpander expander;
239  if ( ! expander.doExpand( this ) )
240  return Contents(); // empty pattern set
241 
242  Contents result;
243  for_( it, expander.begin(), expander.end() )
244  {
245  Contents c( (*it)->depends() );
246  result.get().insert( c.begin(), c.end() );
247  }
248  return result;
249  }
250 
252 } // namespace zypp
std::string order() const
Definition: Pattern.cc:199
bool userVisible() const
Definition: Pattern.cc:187
Pathname icon() const
Definition: Pattern.cc:193
A Solvable object within the sat Pool.
Definition: Solvable.h:55
Container of Solvable providing a Capability (read only).
Definition: WhatProvides.h:87
static const SolvAttr order
Definition: SolvAttr.h:132
static const SolvAttr isvisible
Definition: SolvAttr.h:130
static const SolvAttr isdefault
Definition: SolvAttr.h:133
Container of Capability (currently read only).
Definition: Capabilities.h:35
sat::ArrayAttr< IdString, IdString > NameList
Definition: Pattern.h:39
std::string lookupStrAttribute(const SolvAttr &attr) const
returns the string attribute value for attr or an empty string if it does not exists.
Definition: Solvable.cc:171
Contents depends() const
Ui hint: Dependent packages.
Definition: Pattern.cc:217
Contents contents() const
The collection of packages associated with this pattern.
Definition: Pattern.cc:236
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:27
LookupAttr::transformIterator based container to retrieve list attributes.
Definition: LookupAttr.h:595
filter_iterator< _Filter, typename _Container::const_iterator > make_filter_begin(_Filter f, const _Container &c)
Convenience to create filter_iterator from container::begin().
Definition: Iterator.h:99
std::tr1::unordered_set< Capability > CapabilitySet
Definition: Capability.h:33
static const SolvAttr icon
Definition: SolvAttr.h:131
Pathname script() const
Definition: Pattern.cc:196
sat::SolvableSet Contents
Definition: Pattern.h:40
Capabilities requires() const
Definition: Resolvable.h:100
NameList extends() const
Ui hint: patterns this one extends.
Definition: Pattern.cc:205
bool lookupBoolAttribute(const SolvAttr &attr) const
returns the boolean attribute value for attr or false if it does not exists.
Definition: Solvable.cc:203
bool isDefault() const
Definition: Pattern.cc:184
const sat::Solvable & satSolvable() const
Access the corresponding ::Solvable.
Definition: Resolvable.h:133
static const SolvAttr category
Definition: SolvAttr.h:134
Contents core() const
Ui hint: Required Packages.
Definition: Pattern.cc:208
Interface base for resolvable objects (common data).
Definition: ResObject.h:44
Capabilities suggests() const
Definition: Resolvable.h:112
TraitsType::constPtrType constPtr
Definition: Pattern.h:36
Container & get()
The set.
Definition: SolvableSet.h:90
SolvableIdType size_type
Definition: PoolMember.h:99
static const SolvAttr includes
Definition: SolvAttr.h:136
MapKVIteratorTraits< _Map >::Key_const_iterator make_map_key_begin(const _Map &map_r)
Convenience to create the key iterator from container::begin()
Definition: Iterator.h:226
const_iterator end() const
Iterator pointing behind the last Capability.
Definition: Capabilities.h:165
virtual ~Pattern()
Dtor.
Definition: Pattern.cc:175
NameList includes() const
Ui hint: included patterns.
Definition: Pattern.cc:202
Pattern(const sat::Solvable &solvable_r)
Ctor.
Definition: Pattern.cc:166
Capabilities recommends() const
Definition: Resolvable.h:109
filter_iterator< _Filter, typename _Container::const_iterator > make_filter_end(_Filter f, const _Container &c)
Convenience to create filter_iterator from container::end().
Definition: Iterator.h:115
IMPL_PTR_TYPE(KeyRing)
std::string category(const Locale &lang_r=Locale()) const
Definition: Pattern.cc:190
MapKVIteratorTraits< _Map >::Key_const_iterator make_map_key_end(const _Map &map_r)
Convenience to create the key iterator from container::end()
Definition: Iterator.h:231
PatternMap _patternMap
Definition: Pattern.cc:154
static const SolvAttr extends
Definition: SolvAttr.h:137
const_iterator begin() const
Iterator pointing to the first Capability.
Definition: Capabilities.h:162
static const SolvAttr script
Definition: SolvAttr.h:135
static ResPool instance()
Singleton ctor.
Definition: ResPool.cc:33
Solvable set wrapper to allow adding additioanal convenience iterators.
Definition: SolvableSet.h:35