libzypp  17.16.0
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
173  };
174 
176  void setInstalledOnly();
178  void setUninstalledOnly();
181 
183 
194  void addString(const std::string & value);
195 
221  void addAttribute( const sat::SolvAttr & attr, const std::string & value = "" );
222 
284  void addDependency( const sat::SolvAttr & attr, const std::string & name, const Rel & op, const Edition & edition );
286  void addDependency( const sat::SolvAttr & attr, const std::string & name, const Rel & op, const Edition & edition, const Arch & arch );
288  void addDependency( const sat::SolvAttr & attr, const std::string & name, const Rel & op, const Edition & edition, const Arch & arch, Match::Mode mode );
289 
291  void addDependency( const sat::SolvAttr & attr, const std::string & name, const Edition & edition )
292  { addDependency( attr, name, Rel::EQ, edition ); }
294  void addDependency( const sat::SolvAttr & attr, const std::string & name, const Edition & edition, const Arch & arch )
295  { addDependency( attr, name, Rel::EQ, edition, arch ); }
296 
298  void addDependency( const sat::SolvAttr & attr, const std::string & name )
299  { addDependency( attr, name, Rel::ANY, Edition() ); }
301  void addDependency( const sat::SolvAttr & attr, const std::string & name, const Arch & arch )
302  { addDependency( attr, name, Rel::ANY, Edition(), arch ); }
303 
305  void addDependency( const sat::SolvAttr & attr, const Rel & op, const Edition & edition )
306  { addDependency( attr, std::string(), op, edition ); }
308  void addDependency( const sat::SolvAttr & attr, const Rel & op, const Edition & edition, const Arch & arch )
309  { addDependency( attr, std::string(), op, edition, arch ); }
310 
312  void addDependency( const sat::SolvAttr & attr, const Edition & edition )
313  { addDependency( attr, std::string(), Rel::EQ, edition ); }
315  void addDependency( const sat::SolvAttr & attr, const Edition & edition, const Arch & arch )
316  { addDependency( attr, std::string(), Rel::EQ, edition, arch ); }
317 
320  { addDependency( attr, std::string(), Rel::ANY, Edition() ); }
322  void addDependency( const sat::SolvAttr & attr, const Arch & arch )
323  { addDependency( attr, std::string(), Rel::ANY, Edition(), arch ); }
324 
329  void addDependency( const sat::SolvAttr & attr, Capability cap_r );
331 
339  void setEdition(const Edition & edition, const Rel & op = Rel::EQ);
340 
354  void setCaseSensitive( bool value = true );
355 
361  void setFilesMatchFullPath( bool value = true );
363  void setFilesMatchBasename( bool value = true )
364  { setFilesMatchFullPath( !value ); }
365 
367  void setMatchExact();
369  void setMatchSubstring();
371  void setMatchGlob();
373  void setMatchRegex();
375  void setMatchWord();
376  //void setLocale(const Locale & locale);
378 
381 
383  const StrContainer & strings() const;
387  const AttrRawStrMap & attributes() const;
388 
389  const StrContainer & attribute(const sat::SolvAttr & attr) const;
390 
391  const Kinds & kinds() const;
392 
393  const StrContainer & repos() const;
394 
395  const Edition edition() const;
396  const Rel editionRel() const;
397 
401  bool caseSensitive() const;
402 
404  bool filesMatchFullPath() const;
406  bool filesMatchBasename() const
407  { return !filesMatchFullPath(); }
408 
409  bool matchExact() const;
410  bool matchSubstring() const;
411  bool matchGlob() const;
412  bool matchRegex() const;
413  bool matchWord() const;
414 
419  { return flags().mode(); }
420 
423 
434  bool recover( std::istream &str, char delim = '\n' );
435 
445  void serialize( std::ostream &str, char delim = '\n' ) const;
446 
448  std::string asString() const;
449 
450  bool operator<(const PoolQuery& b) const;
451  bool operator==(const PoolQuery& b) const;
452  bool operator!=(const PoolQuery& b) const { return !(*this == b ); }
453 
454  // low level API
455 
462  Match flags() const;
463 
470  void setFlags( const Match & flags );
471 
472  public:
474  void setRequireAll( bool require_all = true ) ZYPP_DEPRECATED;
476  bool requireAll() const ZYPP_DEPRECATED;
477 
478  public:
479  class Impl;
480  private:
483  };
485 
487  std::ostream & operator<<( std::ostream & str, const PoolQuery & obj );
488 
490  std::ostream & dumpOn( std::ostream & str, const PoolQuery & obj );
491 
493  namespace detail
494  {
495 
496  class PoolQueryMatcher;
497 
499  //
500  // CLASS NAME : PoolQuery::PoolQueryIterator
501  //
509  class PoolQueryIterator : public boost::iterator_adaptor<
510  PoolQueryIterator // Derived
511  , sat::LookupAttr::iterator // Base
512  , const sat::Solvable // Value
513  , boost::forward_traversal_tag // CategoryOrTraversal
514  , const sat::Solvable // Reference
515  >
516  {
517  typedef std::vector<sat::LookupAttr::iterator> Matches;
518  public:
520  typedef Matches::const_iterator matches_iterator;
521  public:
524  {}
525 
527  PoolQueryIterator( const shared_ptr<PoolQueryMatcher> & matcher_r )
528  : _matcher( matcher_r )
529  { increment(); }
530 
577  bool matchesEmpty() const { return ! _matcher; }
579  size_type matchesSize() const { return matches().size(); }
581  matches_iterator matchesBegin() const { return matches().begin(); }
583  matches_iterator matchesEnd() const { return matches().end(); }
585 
586  private:
587  friend class boost::iterator_core_access;
588 
590  { return base_reference().inSolvable(); }
591 
592  void increment();
593 
594  private:
595  const Matches & matches() const;
596 
597  private:
598  shared_ptr<PoolQueryMatcher> _matcher;
599  mutable shared_ptr<Matches> _matches;
600  };
602 
604  inline std::ostream & operator<<( std::ostream & str, const PoolQueryIterator & obj )
605  { return str << obj.base(); }
606 
608  std::ostream & dumpOn( std::ostream & str, const PoolQueryIterator & obj );
609 
611  } //namespace detail
613 
615  { return detail::PoolQueryIterator(); }
616 
618 } // namespace zypp
620 
621 #endif // ZYPP_POOLQUERY_H
PoolQueryIterator(const shared_ptr< PoolQueryMatcher > &matcher_r)
\Ref PoolQuery ctor.
Definition: PoolQuery.h:527
bool matchExact() const
Definition: PoolQuery.cc:1012
A Solvable object within the sat Pool.
Definition: Solvable.h:53
std::ostream & operator<<(std::ostream &str, const PoolQueryIterator &obj)
Definition: PoolQuery.h:604
void setUninstalledOnly()
Return only packages from repos other than @System.
Definition: PoolQuery.cc:965
StatusFilter
Installed status filter setters.
Definition: PoolQuery.h:169
const AttrRawStrMap & attributes() const
Map (map<SolvAttr, StrContainer>) of attribute values added via addAttribute(), addDep in string form...
Definition: PoolQuery.cc:976
void addAttribute(const sat::SolvAttr &attr, const std::string &value="")
Filter by the value of the specified attr attribute.
Definition: PoolQuery.cc:873
void addDependency(const sat::SolvAttr &attr, const Rel &op, const Edition &edition, const Arch &arch)
Definition: PoolQuery.h:308
std::set< ResKind > Kinds
Definition: PoolQuery.h:93
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:298
void addDependency(const sat::SolvAttr &attr, const std::string &name, const Arch &arch)
Definition: PoolQuery.h:301
Architecture.
Definition: Arch.h:36
PoolQuery iterator as returned by PoolQuery::begin.
Definition: PoolQuery.h:509
void setFlags(const Match &flags)
Free function to set libsolv repo search flags.
Definition: PoolQuery.cc:959
Relational operators.
Definition: Rel.h:43
bool requireAll() const ZYPP_DEPRECATED
Definition: PoolQuery.cc:1046
void execute(ProcessResolvable fnc)
Executes the query with the current settings.
Definition: PoolQuery.cc:1041
void addString(const std::string &value)
Add a global query string.
Definition: PoolQuery.cc:870
void setFilesMatchBasename(bool value=true)
Definition: PoolQuery.h:363
static const Rel EQ
Definition: Rel.h:50
const StrContainer & strings() const
Search strings added via addString()
Definition: PoolQuery.cc:972
sat::SolvAttr attr
Definition: PoolQuery.cc:311
Match::Mode matchMode() const
Returns string matching mode as enum.
Definition: PoolQuery.h:418
void setMatchGlob()
Set to match globs.
Definition: PoolQuery.cc:954
void setMatchRegex()
Set to use the query strings as regexes.
Definition: PoolQuery.cc:953
String related utilities and Regular expression matching.
detail::PoolQueryIterator const_iterator
Definition: PoolQuery.h:97
bool operator<(const PoolQuery &b) const
Definition: PoolQuery.cc:1480
Definition: Arch.h:347
bool matchesEmpty() const
False unless this is the end iterator.
Definition: PoolQuery.h:577
void addDependency(const sat::SolvAttr &attr, const std::string &name, const Rel &op, const Edition &edition)
Query "name|global op edition".
Definition: PoolQuery.cc:876
void setCaseSensitive(bool value=true)
Turn case sentitivity on or off (unsets or sets SEARCH_NOCASE flag).
Definition: PoolQuery.cc:1004
void addDependency(const sat::SolvAttr &attr, const std::string &name, const Edition &edition)
Definition: PoolQuery.h:291
void addKind(const ResKind &kind)
Filter by selectable kind.
Definition: PoolQuery.cc:867
Edition represents [epoch:]version[-release]
Definition: Edition.h:60
static const Rel ANY
Definition: Rel.h:56
Mode mode() const
Return the mode part.
Definition: StrMatcher.cc:52
bool operator!=(const PoolQuery &b) const
Definition: PoolQuery.h:452
const Kinds & kinds() const
Definition: PoolQuery.cc:994
void addDependency(const sat::SolvAttr &attr)
Definition: PoolQuery.h:319
Matches::size_type size_type
Definition: PoolQuery.h:519
size_type size() const
Number of solvables in the query result.
Definition: PoolQuery.cc:1028
bool operator==(const PoolQuery &b) const
Definition: PoolQuery.cc:1477
void serialize(std::ostream &str, char delim='\n') const
Writes a machine-readable string representation of the query to stream.
Definition: PoolQuery.cc:1372
const StrContainer & attribute(const sat::SolvAttr &attr) const
Definition: PoolQuery.cc:980
std::vector< sat::LookupAttr::iterator > Matches
Definition: PoolQuery.h:517
Base class providing common iterator types based on a Solvable iterator.
bool caseSensitive() const
returns true if search is case sensitive
Definition: PoolQuery.cc:1002
unsigned int size_type
Definition: PoolQuery.h:98
void setRequireAll(bool require_all=true) ZYPP_DEPRECATED
Definition: PoolQuery.cc:1045
Solvable attribute keys.
Definition: SolvAttr.h:40
bool filesMatchFullPath() const
Whether searching in filelists looks at the full path or just at the basenames.
Definition: PoolQuery.cc:1007
std::set< std::string > StrContainer
Definition: PoolQuery.h:94
void setStatusFilterFlags(StatusFilter flags)
Set status filter directly.
Definition: PoolQuery.cc:967
const StrContainer & repos() const
Definition: PoolQuery.cc:998
void addRepo(const std::string &repoalias)
Filter by repo.
Definition: PoolQuery.cc:857
void setMatchWord()
Set substring to match words.
Definition: PoolQuery.cc:955
const_iterator begin() const
Query result accessers.
Definition: PoolQuery.cc:1826
std::ostream & dumpOn(std::ostream &str, const PoolQuery &obj)
Definition: PoolQuery.cc:1474
matches_iterator matchesEnd() const
End of matches.
Definition: PoolQuery.h:583
const Rel editionRel() const
Definition: PoolQuery.cc:989
void setInstalledOnly()
Return only @System repo packages.
Definition: PoolQuery.cc:963
bool recover(std::istream &str, char delim='\n')
Reads from stream query.
Definition: PoolQuery.cc:1135
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:294
const_iterator end() const
An iterator pointing to the end of the query result.
Definition: PoolQuery.h:614
SolvableIdType size_type
Definition: PoolMember.h:126
const Edition edition() const
Definition: PoolQuery.cc:987
Matches::const_iterator matches_iterator
Definition: PoolQuery.h:520
void setMatchSubstring()
Set to substring (the default).
Definition: PoolQuery.cc:951
std::map< sat::SolvAttr, StrContainer > AttrRawStrMap
Definition: PoolQuery.h:95
Meta-data query API.
Definition: PoolQuery.h:90
bool matchWord() const
Definition: PoolQuery.cc:1016
void setEdition(const Edition &edition, const Rel &op=Rel::EQ)
Set version condition.
Definition: PoolQuery.cc:945
void setMatchExact()
Set to match exact string instead of substring.
Definition: PoolQuery.cc:952
A sat capability.
Definition: Capability.h:59
shared_ptr< PoolQueryMatcher > _matcher
Definition: PoolQuery.h:598
StatusFilter statusFilterFlags() const
Definition: PoolQuery.cc:1018
bool matchSubstring() const
Definition: PoolQuery.cc:1013
Wrapper for const correct access via Smart pointer types.
Definition: PtrTypes.h:285
matches_iterator matchesBegin() const
Begin of matches.
Definition: PoolQuery.h:581
bool empty() const
Whether the result is empty.
Definition: PoolQuery.cc:1021
shared_ptr< Matches > _matches
Definition: PoolQuery.h:599
void addDependency(const sat::SolvAttr &attr, const Edition &edition, const Arch &arch)
Definition: PoolQuery.h:315
sat::Solvable dereference() const
Definition: PoolQuery.h:589
Match flags() const
Free function to get libsolv repo search flags.
Definition: PoolQuery.cc:957
void setFilesMatchFullPath(bool value=true)
If set (default), look at the full path when searching in filelists.
Definition: PoolQuery.cc:1009
RW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: PoolQuery.h:479
void addDependency(const sat::SolvAttr &attr, const Arch &arch)
Definition: PoolQuery.h:322
std::string asString() const
Return a human-readable description of the query.
Definition: PoolQuery.cc:1468
#define ZYPP_DEPRECATED
The ZYPP_DEPRECATED macro can be used to trigger compile-time warnings with gcc >= 3....
Definition: APIConfig.h:88
Resolvable kinds.
Definition: ResKind.h:32
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
size_type matchesSize() const
Number of attribute matches.
Definition: PoolQuery.h:579
function< bool(const sat::Solvable &)> ProcessResolvable
Definition: PoolQuery.h:101
bool matchGlob() const
Definition: PoolQuery.cc:1014
void addDependency(const sat::SolvAttr &attr, const Rel &op, const Edition &edition)
Definition: PoolQuery.h:305
PoolQueryIterator()
Default ctor is also end.
Definition: PoolQuery.h:523
bool matchRegex() const
Definition: PoolQuery.cc:1015
bool filesMatchBasename() const
Definition: PoolQuery.h:406
void addDependency(const sat::SolvAttr &attr, const Edition &edition)
Definition: PoolQuery.h:312