libzypp  17.14.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:
482  RW_pointer<Impl> _pimpl;
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 
589  sat::Solvable dereference() const
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