libzypp  17.35.12
Filter.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_FILTER_H
13 #define ZYPP_FILTER_H
14 
15 #include <iosfwd>
16 #include <utility>
17 
18 #include <zypp/base/Functional.h>
19 #include <zypp/base/Function.h>
20 // #include <zypp/ResFilters.h> included at the end!
21 #include <zypp/sat/Pool.h>
22 #include <zypp/PoolItem.h>
23 
25 namespace zypp
26 {
27  namespace filter
29  {
30 
56 
58  //
59  // CLASS NAME : ByLocaleSupport
60  //
64  {
65  private:
66  using LS1 = bool (sat::Solvable::*)(const Locale &) const;
67  using LS2 = bool (sat::Solvable::*)(const LocaleSet &) const;
68 
69  public:
72  : _sel( std::mem_fn(&sat::Solvable::supportsLocales) )
73  {}
74 
76  explicit ByLocaleSupport( const Locale & locale_r )
77  : _sel( std::bind( std::mem_fn((LS1)&sat::Solvable::supportsLocale), _1, locale_r ) )
78  {}
79 
81  explicit ByLocaleSupport( const LocaleSet & locales_r )
82  : _sel( std::bind( std::mem_fn((LS2)&sat::Solvable::supportsLocale), _1, locales_r ) )
83  {}
84 
85  public:
87  bool operator()( const sat::Solvable & solv_r ) const
88  { return _sel && _sel( solv_r ); }
89 
91  template<class TSolv>
92  bool operator()( const TSolv & solv_r ) const
93  { return operator()( solv_r.satSolvable() ); }
94 
95  private:
96  function<bool(const sat::Solvable &)> _sel;
97  };
99 
101  //
102  // CLASS NAME : ByKind
103  //
106  class ByKind
107  {
108  public:
110  {}
111 
112  ByKind( ResKind kind_r )
113  : _kind(std::move( kind_r ))
114  {}
115 
116  public:
118  bool operator()( const sat::Solvable & solv_r ) const
119  { return solv_r.isKind( _kind ); }
120 
122  template<class TSolv>
123  bool operator()( const TSolv & solv_r ) const
124  { return operator()( solv_r.satSolvable() ); }
125 
126  private:
128  };
129 
131  template<class TRes>
132  inline ByKind byKind()
133  { return ByKind( ResTraits<TRes>::kind ); }
135 
137  //
138  // CLASS NAME : ByStatus
139  //
142  class ByStatus
143  {
144  public:
145  using Predicate = bool (ResStatus::*)() const;
146 
147  public:
148  ByStatus( Predicate pred_r = 0 )
149  : _pred( pred_r )
150  {}
151 
152  public:
154  bool operator()( const PoolItem & pi_r ) const
155  { return _pred && (pi_r.status().*_pred)(); }
156 
158  template<class TSolv>
159  bool operator()( const TSolv & solv_r ) const
160  { return operator()( PoolItem(solv_r) ); }
161 
162  private:
164  };
166 
167 
169  //
170  // CLASS NAME : SameItemAs
171  //
177  {
178  public:
179  SameItemAs( const sat::Solvable & solv_r )
180  : _item( solv_r )
181  {}
182 
184  template<class TSolv>
185  SameItemAs( const TSolv & solv_r )
186  : _item( solv_r.satSolvable() )
187  {}
188 
189  public:
191  bool operator()( const sat::Solvable & solv_r ) const
192  {
193  return solv_r.name() == _item.name()
194  && solv_r.edition() == _item.edition()
195  && solv_r.arch() == _item.arch()
196  && solv_r.vendor() == _item.vendor();
197  }
198 
200  template<class TSolv>
201  bool operator()( const TSolv & solv_r ) const
202  { return operator()( solv_r.satSolvable() ); }
203 
204  private:
206  };
208 
209 
211  } // namespace filter
214 } // namespace zypp
216 
217 #include <zypp/ResFilters.h>
218 
219 #endif // ZYPP_FILTER_H
std::string name() const
The name (without any ResKind prefix).
Definition: Solvable.cc:330
ByLocaleSupport(const LocaleSet &locales_r)
Solvables supporting at least one locale in locales_r.
Definition: Filter.h:81
A Solvable object within the sat Pool.
Definition: Solvable.h:53
IdString vendor() const
The vendor.
Definition: Solvable.cc:358
sat::Solvable _item
Definition: Filter.h:205
bool operator()(const sat::Solvable &solv_r) const
Filter on Solvable.
Definition: Filter.h:191
Filter solvables according to their status.
Definition: Filter.h:142
std::unordered_set< Locale > LocaleSet
Definition: Locale.h:29
bool operator()(const sat::Solvable &solv_r) const
Filter on Solvable.
Definition: Filter.h:87
ResStatus & status() const
Returns the current status.
Definition: PoolItem.cc:212
bool operator()(const TSolv &solv_r) const
Filter fitting PoolItem/ResObject.
Definition: Filter.h:92
bool isKind(const ResKind &kind_r) const
Test whether a Solvable is of a certain ResKind.
Definition: Solvable.cc:303
Definition: Arch.h:363
ResTraits.
Definition: ResTraits.h:79
ByStatus(Predicate pred_r=0)
Definition: Filter.h:148
function< bool(const sat::Solvable &)> _sel
Definition: Filter.h:96
ByKind byKind()
Definition: Filter.h:132
bool operator()(const PoolItem &pi_r) const
Filter on PoolItem.
Definition: Filter.h:154
SameItemAs(const sat::Solvable &solv_r)
Definition: Filter.h:179
Edition edition() const
The edition (version-release).
Definition: Solvable.cc:338
bool(ResStatus::*)() const Predicate
Definition: Filter.h:145
Filter solvables according to their locale support.
Definition: Filter.h:63
Arch arch() const
The architecture.
Definition: Solvable.cc:344
bool operator()(const TSolv &solv_r) const
Filter fitting PoolItem/ResObject.
Definition: Filter.h:123
bool(sat::Solvable::*)(const LocaleSet &) const LS2
Definition: Filter.h:67
Filter items with at least same NVRA, vendor.
Definition: Filter.h:176
&#39;Language[_Country]&#39; codes.
Definition: Locale.h:50
bool operator()(const TSolv &solv_r) const
Filter fitting PoolItem/ResObject.
Definition: Filter.h:201
ByKind(ResKind kind_r)
Definition: Filter.h:112
bool(sat::Solvable::*)(const Locale &) const LS1
Definition: Filter.h:66
Status bitfield.
Definition: ResStatus.h:54
Combining sat::Solvable and ResStatus.
Definition: PoolItem.h:50
ByLocaleSupport()
Solvables with locale support.
Definition: Filter.h:71
bool operator()(const TSolv &solv_r) const
Filter fitting sat::Solvable/ResObject.
Definition: Filter.h:159
SameItemAs(const TSolv &solv_r)
Fitting PoolItem/ResObject.
Definition: Filter.h:185
ByLocaleSupport(const Locale &locale_r)
Solvables supporting locale_r.
Definition: Filter.h:76
Resolvable kinds.
Definition: ResKind.h:32
Easy-to use interface to the ZYPP dependency resolver.
Definition: Application.cc:19
Filter solvables according to their kind.
Definition: Filter.h:106
bool operator()(const sat::Solvable &solv_r) const
Filter on Solvable.
Definition: Filter.h:118