libzypp  16.15.6
PoolQuery.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_POOLQUERY_H
13 #define ZYPP_POOLQUERY_H
14 
15 #include <iosfwd>
16 #include <set>
17 #include <map>
18 
19 #include "zypp/base/Regex.h"
20 #include "zypp/base/PtrTypes.h"
21 #include "zypp/base/Function.h"
22 
23 #include "zypp/sat/SolvIterMixin.h"
24 #include "zypp/sat/LookupAttr.h"
25 #include "zypp/base/StrMatcher.h"
26 #include "zypp/sat/Pool.h"
27 
29 namespace zypp
30 {
31 
32  namespace detail
33  {
34  class PoolQueryIterator;
35  }
36 
38  //
39  // CLASS NAME : PoolQuery
40  //
90  class PoolQuery : public sat::SolvIterMixin<PoolQuery, detail::PoolQueryIterator>
91  {
92  public:
93  typedef std::set<ResKind> Kinds;
94  typedef std::set<std::string> StrContainer;
95  typedef std::map<sat::SolvAttr, StrContainer> AttrRawStrMap;
96 
98  typedef unsigned int size_type;
99 
100  public:
101  typedef function<bool( const sat::Solvable & )> ProcessResolvable;
102 
103  PoolQuery();
104  ~PoolQuery();
105 
120  const_iterator begin() const;
121 
123  const_iterator end() const;
124 
126  bool empty() const;
127 
129  size_type size() const;
131 
136  void execute(ProcessResolvable fnc);
137 
153  void addKind(const ResKind & kind);
154 
161  void addRepo(const std::string &repoalias);
162 
165 
170  ALL = 0, // both install filter and uninstall filter bits are 0
171  INSTALLED_ONLY = 1,
172  UNINSTALLED_ONLY = 2
173  };
174 
176  void setInstalledOnly();
178  void setUninstalledOnly();
180  void setStatusFilterFlags( StatusFilter flags );
181 
183 
195  void addString(const std::string & value);
196 
224  void addAttribute( const sat::SolvAttr & attr, const std::string & value = "" );
225 
287  void addDependency( const sat::SolvAttr & attr, const std::string & name, const Rel & op, const Edition & edition );
289  void addDependency( const sat::SolvAttr & attr, const std::string & name, const Rel & op, const Edition & edition, const Arch & arch );
290 
292  void addDependency( const sat::SolvAttr & attr, const std::string & name, const Edition & edition )
293  { addDependency( attr, name, Rel::EQ, edition ); }
295  void addDependency( const sat::SolvAttr & attr, const std::string & name, const Edition & edition, const Arch & arch )
296  { addDependency( attr, name, Rel::EQ, edition, arch ); }
297 
299  void addDependency( const sat::SolvAttr & attr, const std::string & name )
300  { addDependency( attr, name, Rel::ANY, Edition() ); }
302  void addDependency( const sat::SolvAttr & attr, const std::string & name, const Arch & arch )
303  { addDependency( attr, name, Rel::ANY, Edition(), arch ); }
304 
306  void addDependency( const sat::SolvAttr & attr, const Rel & op, const Edition & edition )
307  { addDependency( attr, std::string(), op, edition ); }
309  void addDependency( const sat::SolvAttr & attr, const Rel & op, const Edition & edition, const Arch & arch )
310  { addDependency( attr, std::string(), op, edition, arch ); }
311 
313  void addDependency( const sat::SolvAttr & attr, const Edition & edition )
314  { addDependency( attr, std::string(), Rel::EQ, edition ); }
316  void addDependency( const sat::SolvAttr & attr, const Edition & edition, const Arch & arch )
317  { addDependency( attr, std::string(), Rel::EQ, edition, arch ); }
318 
321  { addDependency( attr, std::string(), Rel::ANY, Edition() ); }
323  void addDependency( const sat::SolvAttr & attr, const Arch & arch )
324  { addDependency( attr, std::string(), Rel::ANY, Edition(), arch ); }
325 
330  void addDependency( const sat::SolvAttr & attr, Capability cap_r );
332 
340  void setEdition(const Edition & edition, const Rel & op = Rel::EQ);
341 
355  void setCaseSensitive( bool value = true );
356 
362  void setFilesMatchFullPath( bool value = true );
364  void setFilesMatchBasename( bool value = true )
365  { setFilesMatchFullPath( !value ); }
366 
368  void setMatchExact();
370  void setMatchSubstring();
372  void setMatchGlob();
374  void setMatchRegex();
376  void setMatchWord();
377  //void setLocale(const Locale & locale);
379 
386  void setRequireAll( bool require_all = true );
387 
388 
391 
393  const StrContainer & strings() const;
397  const AttrRawStrMap & attributes() const;
398 
399  const StrContainer & attribute(const sat::SolvAttr & attr) const;
400 
401  const Kinds & kinds() const;
402 
403  const StrContainer & repos() const;
404 
405  const Edition edition() const;
406  const Rel editionRel() const;
407 
411  bool caseSensitive() const;
412 
414  bool filesMatchFullPath() const;
416  bool filesMatchBasename() const
417  { return !filesMatchFullPath(); }
418 
419  bool matchExact() const;
420  bool matchSubstring() const;
421  bool matchGlob() const;
422  bool matchRegex() const;
423  bool matchWord() const;
424 
429  { return flags().mode(); }
430 
435  bool requireAll() const;
436 
437  StatusFilter statusFilterFlags() const;
439 
450  bool recover( std::istream &str, char delim = '\n' );
451 
461  void serialize( std::ostream &str, char delim = '\n' ) const;
462 
464  std::string asString() const;
465 
466  bool operator==(const PoolQuery& b) const;
467  bool operator!=(const PoolQuery& b) const { return !(*this == b ); }
468 
469  // low level API
470 
477  Match flags() const;
478 
485  void setFlags( const Match & flags );
486 
487  public:
488  class Impl;
489  private:
492  };
494 
496  std::ostream & operator<<( std::ostream & str, const PoolQuery & obj );
497 
499  std::ostream & dumpOn( std::ostream & str, const PoolQuery & obj );
500 
502  namespace detail
503  {
504 
505  class PoolQueryMatcher;
506 
508  //
509  // CLASS NAME : PoolQuery::PoolQueryIterator
510  //
518  class PoolQueryIterator : public boost::iterator_adaptor<
519  PoolQueryIterator // Derived
520  , sat::LookupAttr::iterator // Base
521  , const sat::Solvable // Value
522  , boost::forward_traversal_tag // CategoryOrTraversal
523  , const sat::Solvable // Reference
524  >
525  {
526  typedef std::vector<sat::LookupAttr::iterator> Matches;
527  public:
529  typedef Matches::const_iterator matches_iterator;
530  public:
533  {}
534 
536  PoolQueryIterator( const shared_ptr<PoolQueryMatcher> & matcher_r )
537  : _matcher( matcher_r )
538  { increment(); }
539 
586  bool matchesEmpty() const { return ! _matcher; }
588  size_type matchesSize() const { return matches().size(); }
590  matches_iterator matchesBegin() const { return matches().begin(); }
592  matches_iterator matchesEnd() const { return matches().end(); }
594 
595  private:
596  friend class boost::iterator_core_access;
597 
599  { return base_reference().inSolvable(); }
600 
601  void increment();
602 
603  private:
604  const Matches & matches() const;
605 
606  private:
607  shared_ptr<PoolQueryMatcher> _matcher;
608  mutable shared_ptr<Matches> _matches;
609  };
611 
613  inline std::ostream & operator<<( std::ostream & str, const PoolQueryIterator & obj )
614  { return str << obj.base(); }
615 
617  std::ostream & dumpOn( std::ostream & str, const PoolQueryIterator & obj );
618 
620  } //namespace detail
622 
624  { return detail::PoolQueryIterator(); }
625 
627 } // namespace zypp
629 
630 #endif // ZYPP_POOLQUERY_H
PoolQueryIterator(const shared_ptr< PoolQueryMatcher > &matcher_r)
PoolQuery ctor.
Definition: PoolQuery.h:536
A Solvable object within the sat Pool.
Definition: Solvable.h:53
std::ostream & operator<<(std::ostream &str, const PoolQueryIterator &obj)
Definition: PoolQuery.h:613
StatusFilter
Installed status filter setters.
Definition: PoolQuery.h:169
matches_iterator matchesBegin() const
Begin of matches.
Definition: PoolQuery.h:590
bool filesMatchBasename() const
Definition: PoolQuery.h:416
void addDependency(const sat::SolvAttr &attr, const Rel &op, const Edition &edition, const Arch &arch)
Definition: PoolQuery.h:309
std::set< ResKind > Kinds
Definition: PoolQuery.h:93
std::string asString(const DefaultIntegral< Tp, TInitial > &obj)
String matching option flags as used e.g.
Definition: StrMatcher.h:32
void addDependency(const sat::SolvAttr &attr, const std::string &name)
Definition: PoolQuery.h:299
std::ostream & dumpOn(std::ostream &str, const PoolQueryIterator &obj)
Definition: PoolQuery.cc:1765
void addDependency(const sat::SolvAttr &attr, const std::string &name, const Arch &arch)
Definition: PoolQuery.h:302
Architecture.
Definition: Arch.h:36
PoolQuery iterator as returned by PoolQuery::begin.
Definition: PoolQuery.h:518
Relational operators.
Definition: Rel.h:43
void setFilesMatchBasename(bool value=true)
Definition: PoolQuery.h:364
static const Rel EQ
Definition: Rel.h:50
size_type matchesSize() const
Number of attribute matches.
Definition: PoolQuery.h:588
sat::SolvAttr attr
Definition: PoolQuery.cc:314
String related utilities and Regular expression matching.
detail::PoolQueryIterator const_iterator
Definition: PoolQuery.h:97
void addDependency(const sat::SolvAttr &attr, const std::string &name, const Edition &edition)
Definition: PoolQuery.h:292
Edition represents [epoch:]version[-release]
Definition: Edition.h:60
static const Rel ANY
Definition: Rel.h:56
bool operator==(const SetRelation::Enum &lhs, const SetCompare &rhs)
bool matchesEmpty() const
False unless this is the end iterator.
Definition: PoolQuery.h:586
void addDependency(const sat::SolvAttr &attr)
Definition: PoolQuery.h:320
matches_iterator matchesEnd() const
End of matches.
Definition: PoolQuery.h:592
Matches::size_type size_type
Definition: PoolQuery.h:528
std::ostream & operator<<(std::ostream &str, const Dump< Tp > &obj)
Definition: LogTools.h:428
std::vector< sat::LookupAttr::iterator > Matches
Definition: PoolQuery.h:526
bool operator!=(const PoolQuery &b) const
Definition: PoolQuery.h:467
Base class providing common iterator types based on a Solvable iterator.
sat::Solvable dereference() const
Definition: PoolQuery.h:598
Match::Mode matchMode() const
Returns string matching mode as enum.
Definition: PoolQuery.h:428
unsigned int size_type
Definition: PoolQuery.h:98
Solvable attribute keys.
Definition: SolvAttr.h:40
std::set< std::string > StrContainer
Definition: PoolQuery.h:94
RepoInfoList repos
Definition: RepoManager.cc:277
Mode
Mode flags (mutual exclusive).
Definition: StrMatcher.h:40
void addDependency(const sat::SolvAttr &attr, const std::string &name, const Edition &edition, const Arch &arch)
Definition: PoolQuery.h:295
SolvableIdType size_type
Definition: PoolMember.h:126
Matches::const_iterator matches_iterator
Definition: PoolQuery.h:529
std::map< sat::SolvAttr, StrContainer > AttrRawStrMap
Definition: PoolQuery.h:95
Meta-data query API.
Definition: PoolQuery.h:90
A sat capability.
Definition: Capability.h:59
shared_ptr< PoolQueryMatcher > _matcher
Definition: PoolQuery.h:607
shared_ptr< Matches > _matches
Definition: PoolQuery.h:608
void addDependency(const sat::SolvAttr &attr, const Edition &edition, const Arch &arch)
Definition: PoolQuery.h:316
RW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: PoolQuery.h:488
void addDependency(const sat::SolvAttr &attr, const Arch &arch)
Definition: PoolQuery.h:323
const_iterator end() const
An iterator pointing to the end of the query result.
Definition: PoolQuery.h:623
Resolvable kinds.
Definition: ResKind.h:32
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
function< bool(const sat::Solvable &)> ProcessResolvable
Definition: PoolQuery.h:101
void addDependency(const sat::SolvAttr &attr, const Rel &op, const Edition &edition)
Definition: PoolQuery.h:306
PoolQueryIterator()
Default ctor is also end.
Definition: PoolQuery.h:532
void addDependency(const sat::SolvAttr &attr, const Edition &edition)
Definition: PoolQuery.h:313