libzypp  11.13.5
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