libzypp  13.10.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 
146  void addKind(const ResKind & kind);
147 
154  void addRepo(const std::string &repoalias);
155 
158 
163  ALL = 0, // both install filter and uninstall filter bits are 0
166  };
167 
169  void setInstalledOnly();
171  void setUninstalledOnly();
174 
176 
188  void addString(const std::string & value);
189 
217  void addAttribute( const sat::SolvAttr & attr, const std::string & value = "" );
218 
280  void addDependency( const sat::SolvAttr & attr, const std::string & name, const Rel & op, const Edition & edition );
282  void addDependency( const sat::SolvAttr & attr, const std::string & name, const Rel & op, const Edition & edition, const Arch & arch );
283 
285  void addDependency( const sat::SolvAttr & attr, const std::string & name, const Edition & edition )
286  { addDependency( attr, name, Rel::EQ, edition ); }
288  void addDependency( const sat::SolvAttr & attr, const std::string & name, const Edition & edition, const Arch & arch )
289  { addDependency( attr, name, Rel::EQ, edition, arch ); }
290 
292  void addDependency( const sat::SolvAttr & attr, const std::string & name )
293  { addDependency( attr, name, Rel::ANY, Edition() ); }
295  void addDependency( const sat::SolvAttr & attr, const std::string & name, const Arch & arch )
296  { addDependency( attr, name, Rel::ANY, Edition(), arch ); }
297 
299  void addDependency( const sat::SolvAttr & attr, const Rel & op, const Edition & edition )
300  { addDependency( attr, std::string(), op, edition ); }
302  void addDependency( const sat::SolvAttr & attr, const Rel & op, const Edition & edition, const Arch & arch )
303  { addDependency( attr, std::string(), op, edition, arch ); }
304 
306  void addDependency( const sat::SolvAttr & attr, const Edition & edition )
307  { addDependency( attr, std::string(), Rel::EQ, edition ); }
309  void addDependency( const sat::SolvAttr & attr, const Edition & edition, const Arch & arch )
310  { addDependency( attr, std::string(), Rel::EQ, edition, arch ); }
311 
314  { addDependency( attr, std::string(), Rel::ANY, Edition() ); }
316  void addDependency( const sat::SolvAttr & attr, const Arch & arch )
317  { addDependency( attr, std::string(), Rel::ANY, Edition(), arch ); }
318 
323  void addDependency( const sat::SolvAttr & attr, Capability cap_r );
325 
333  void setEdition(const Edition & edition, const Rel & op = Rel::EQ);
334 
348  void setCaseSensitive( bool value = true );
349 
355  void setFilesMatchFullPath( bool value = true );
357  void setFilesMatchBasename( bool value = true )
358  { setFilesMatchFullPath( !value ); }
359 
361  void setMatchExact();
363  void setMatchSubstring();
365  void setMatchGlob();
367  void setMatchRegex();
369  void setMatchWord();
370  //void setLocale(const Locale & locale);
372 
379  void setRequireAll( bool require_all = true );
380 
381 
384 
386  const StrContainer & strings() const;
390  const AttrRawStrMap & attributes() const;
391 
392  const StrContainer & attribute(const sat::SolvAttr & attr) const;
393 
394  const Kinds & kinds() const;
395 
396  const StrContainer & repos() const;
397 
398  const Edition edition() const;
399  const Rel editionRel() const;
400 
404  bool caseSensitive() const;
405 
407  bool filesMatchFullPath() const;
409  bool filesMatchBasename() const
410  { return !filesMatchFullPath(); }
411 
412  bool matchExact() const;
413  bool matchSubstring() const;
414  bool matchGlob() const;
415  bool matchRegex() const;
416  bool matchWord() const;
417 
422  { return flags().mode(); }
423 
428  bool requireAll() const;
429 
432 
443  bool recover( std::istream &str, char delim = '\n' );
444 
454  void serialize( std::ostream &str, char delim = '\n' ) const;
455 
457  std::string asString() const;
458 
459  bool operator==(const PoolQuery& b) const;
460  bool operator!=(const PoolQuery& b) const { return !(*this == b ); }
461 
462  // low level API
463 
470  Match flags() const;
471 
478  void setFlags( const Match & flags );
479 
480  public:
481  class Impl;
482  private:
485  };
487 
489  std::ostream & operator<<( std::ostream & str, const PoolQuery & obj );
490 
492  std::ostream & dumpOn( std::ostream & str, const PoolQuery & obj );
493 
495  namespace detail
496  {
497 
498  class PoolQueryMatcher;
499 
501  //
502  // CLASS NAME : PoolQuery::PoolQueryIterator
503  //
511  class PoolQueryIterator : public boost::iterator_adaptor<
512  PoolQueryIterator // Derived
513  , sat::LookupAttr::iterator // Base
514  , const sat::Solvable // Value
515  , boost::forward_traversal_tag // CategoryOrTraversal
516  , const sat::Solvable // Reference
517  >
518  {
519  typedef std::vector<sat::LookupAttr::iterator> Matches;
520  public:
522  typedef Matches::const_iterator matches_iterator;
523  public:
526  {}
527 
529  PoolQueryIterator( const shared_ptr<PoolQueryMatcher> & matcher_r )
530  : _matcher( matcher_r )
531  { increment(); }
532 
579  bool matchesEmpty() const { return ! _matcher; }
581  size_type matchesSize() const { return matches().size(); }
583  matches_iterator matchesBegin() const { return matches().begin(); }
585  matches_iterator matchesEnd() const { return matches().end(); }
587 
588  private:
590 
592  { return base_reference().inSolvable(); }
593 
594  void increment();
595 
596  private:
597  const Matches & matches() const;
598 
599  private:
600  shared_ptr<PoolQueryMatcher> _matcher;
601  mutable shared_ptr<Matches> _matches;
602  };
604 
606  inline std::ostream & operator<<( std::ostream & str, const PoolQueryIterator & obj )
607  { return str << obj.base(); }
608 
610  std::ostream & dumpOn( std::ostream & str, const PoolQueryIterator & obj );
611 
613  } //namespace detail
615 
617  { return detail::PoolQueryIterator(); }
618 
620 } // namespace zypp
622 
623 #endif // ZYPP_POOLQUERY_H
PoolQueryIterator(const shared_ptr< PoolQueryMatcher > &matcher_r)
PoolQuery ctor.
Definition: PoolQuery.h:529
const Rel editionRel() const
Definition: PoolQuery.cc:960
A Solvable object within the sat Pool.
Definition: Solvable.h:55
std::ostream & operator<<(std::ostream &str, const PoolQueryIterator &obj)
Definition: PoolQuery.h:606
void setUninstalledOnly()
Return only packages from repos other than .
Definition: PoolQuery.cc:932
StatusFilter
Installed status filter setters.
Definition: PoolQuery.h:162
matches_iterator matchesBegin() const
Begin of matches.
Definition: PoolQuery.h:583
void addAttribute(const sat::SolvAttr &attr, const std::string &value="")
Filter by the value of the specified attr attribute.
Definition: PoolQuery.cc:854
bool filesMatchBasename() const
Definition: PoolQuery.h:409
void addDependency(const sat::SolvAttr &attr, const Rel &op, const Edition &edition, const Arch &arch)
Definition: PoolQuery.h:302
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:292
std::ostream & dumpOn(std::ostream &str, const PoolQueryIterator &obj)
Definition: PoolQuery.cc:1718
void addDependency(const sat::SolvAttr &attr, const std::string &name, const Arch &arch)
Definition: PoolQuery.h:295
Architecture.
Definition: Arch.h:36
const StrContainer & strings() const
Search strings added via addString()
Definition: PoolQuery.cc:943
const StrContainer & attribute(const sat::SolvAttr &attr) const
Definition: PoolQuery.cc:951
PoolQuery iterator as returned by PoolQuery::begin.
Definition: PoolQuery.h:511
void setFlags(const Match &flags)
Free function to set libsolv repo search flags.
Definition: PoolQuery.cc:926
Relational operators.
Definition: Rel.h:43
void execute(ProcessResolvable fnc)
Executes the query with the current settings.
Definition: PoolQuery.cc:1017
void addString(const std::string &value)
Add a global query string.
Definition: PoolQuery.cc:851
bool filesMatchFullPath() const
Whether searching in filelists looks at the full path or just at the basenames.
Definition: PoolQuery.cc:978
void setFilesMatchBasename(bool value=true)
Definition: PoolQuery.h:357
bool operator==(const PoolQuery &b) const
Definition: PoolQuery.cc:1409
static const Rel EQ
Definition: Rel.h:50
size_type matchesSize() const
Number of attribute matches.
Definition: PoolQuery.h:581
const Edition edition() const
Definition: PoolQuery.cc:958
sat::SolvAttr attr
Definition: PoolQuery.cc:303
void setMatchGlob()
Set to match globs.
Definition: PoolQuery.cc:917
void setMatchRegex()
Set to use the query strings as regexes.
Definition: PoolQuery.cc:916
bool recover(std::istream &str, char delim= '\n')
Reads from stream query.
Definition: PoolQuery.cc:1108
const Matches & matches() const
Definition: PoolQuery.cc:1701
detail::PoolQueryIterator const_iterator
Definition: PoolQuery.h:97
void addDependency(const sat::SolvAttr &attr, const std::string &name, const Rel &op, const Edition &edition)
Query &quot;name|global op edition&quot;.
Definition: PoolQuery.cc:857
void setCaseSensitive(bool value=true)
Turn case sentitivity on or off (unsets or sets SEARCH_NOCASE flag).
Definition: PoolQuery.cc:975
void addDependency(const sat::SolvAttr &attr, const std::string &name, const Edition &edition)
Definition: PoolQuery.h:285
void addKind(const ResKind &kind)
Filter by selectable kind.
Definition: PoolQuery.cc:848
Edition represents [epoch:]version[-release]
Definition: Edition.h:60
static const Rel ANY
Definition: Rel.h:56
bool caseSensitive() const
returns true if search is case sensitive
Definition: PoolQuery.cc:973
bool matchesEmpty() const
False unless this is the end iterator.
Definition: PoolQuery.h:579
void addDependency(const sat::SolvAttr &attr)
Definition: PoolQuery.h:313
matches_iterator matchesEnd() const
End of matches.
Definition: PoolQuery.h:585
const StrContainer & repos() const
Definition: PoolQuery.cc:969
Matches::size_type size_type
Definition: PoolQuery.h:521
bool requireAll() const
Whether all values added via addString() or addAttribute() are required to match the values of the re...
Definition: PoolQuery.cc:991
std::vector< sat::LookupAttr::iterator > Matches
Definition: PoolQuery.h:519
bool operator!=(const PoolQuery &b) const
Definition: PoolQuery.h:460
Base class providing common iterator types based on a Solvable iterator.
sat::Solvable dereference() const
Definition: PoolQuery.h:591
Match::Mode matchMode() const
Returns string matching mode as enum.
Definition: PoolQuery.h:421
unsigned int size_type
Definition: PoolQuery.h:98
Solvable attribute keys.
Definition: SolvAttr.h:40
std::set< std::string > StrContainer
Definition: PoolQuery.h:94
void setStatusFilterFlags(StatusFilter flags)
Set status filter directly.
Definition: PoolQuery.cc:934
std::ostream & operator<<(std::ostream &str, const Exception &obj)
Definition: Exception.cc:120
bool matchWord() const
Definition: PoolQuery.cc:988
void addRepo(const std::string &repoalias)
Filter by repo.
Definition: PoolQuery.cc:838
const AttrRawStrMap & attributes() const
Map (map&lt;SolvAttr, StrContainer&gt;) of attribute values added via addAttribute(), addDep in string form...
Definition: PoolQuery.cc:947
void setMatchWord()
Set to match words (uses regex)
Definition: PoolQuery.cc:918
friend class boost::iterator_core_access
Definition: PoolQuery.h:589
Match flags() const
Free function to get libsolv repo search flags.
Definition: PoolQuery.cc:924
bool matchExact() const
Definition: PoolQuery.cc:983
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
Definition: Capability.cc:435
void setInstalledOnly()
Return only repo packages.
Definition: PoolQuery.cc:930
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:288
SolvableIdType size_type
Definition: PoolMember.h:99
Matches::const_iterator matches_iterator
Definition: PoolQuery.h:522
bool matchGlob() const
Definition: PoolQuery.cc:985
void setMatchSubstring()
Set to substring (the default).
Definition: PoolQuery.cc:914
std::map< sat::SolvAttr, StrContainer > AttrRawStrMap
Definition: PoolQuery.h:95
bool matchSubstring() const
Definition: PoolQuery.cc:984
StatusFilter statusFilterFlags() const
Definition: PoolQuery.cc:994
Meta-data query API.
Definition: PoolQuery.h:90
const Kinds & kinds() const
Definition: PoolQuery.cc:965
bool empty() const
Whether the result is empty.
Definition: PoolQuery.cc:997
void setEdition(const Edition &edition, const Rel &op=Rel::EQ)
Set version condition.
Definition: PoolQuery.cc:908
void setMatchExact()
Set to match exact string instead of substring.
Definition: PoolQuery.cc:915
bool matchRegex() const
Definition: PoolQuery.cc:986
A sat capability.
Definition: Capability.h:59
shared_ptr< PoolQueryMatcher > _matcher
Definition: PoolQuery.h:600
Wrapper for const correct access via Smart pointer types.
Definition: PtrTypes.h:265
Mode mode() const
Return the mode part.
Definition: StrMatcher.cc:51
size_type size() const
Number of solvables in the query result.
Definition: PoolQuery.cc:1004
shared_ptr< Matches > _matches
Definition: PoolQuery.h:601
void addDependency(const sat::SolvAttr &attr, const Edition &edition, const Arch &arch)
Definition: PoolQuery.h:309
void serialize(std::ostream &str, char delim= '\n') const
Writes a machine-readable string representation of the query to stream.
Definition: PoolQuery.cc:1291
void setFilesMatchFullPath(bool value=true)
If set (default), look at the full path when searching in filelists.
Definition: PoolQuery.cc:980
RW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: PoolQuery.h:481
const_iterator begin() const
Query result accessers.
Definition: PoolQuery.cc:1735
void addDependency(const sat::SolvAttr &attr, const Arch &arch)
Definition: PoolQuery.h:316
const_iterator end() const
An iterator pointing to the end of the query result.
Definition: PoolQuery.h:616
std::string asString() const
Return a human-readable description of the query.
Definition: PoolQuery.cc:1400
Resolvable kinds.
Definition: ResKind.h:35
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:299
PoolQueryIterator()
Default ctor is also end.
Definition: PoolQuery.h:525
void addDependency(const sat::SolvAttr &attr, const Edition &edition)
Definition: PoolQuery.h:306
void setRequireAll(bool require_all=true)
Require that all of the values set by addString or addAttribute match the values of respective attrib...
Definition: PoolQuery.cc:938