00001
00002
00003
00004
00005
00006
00007
00008
00012 #ifndef ZYPP_POOLQUERY_H
00013 #define ZYPP_POOLQUERY_H
00014
00015 #include <iosfwd>
00016 #include <set>
00017 #include <map>
00018
00019 #include "zypp/base/Regex.h"
00020 #include "zypp/base/PtrTypes.h"
00021 #include "zypp/base/Function.h"
00022
00023 #include "zypp/sat/SolvIterMixin.h"
00024 #include "zypp/sat/LookupAttr.h"
00025 #include "zypp/sat/AttrMatcher.h"
00026 #include "zypp/sat/Pool.h"
00027
00029 namespace zypp
00030 {
00031
00032 namespace detail
00033 {
00034 class PoolQueryIterator;
00035 }
00036
00038
00039
00040
00090 class PoolQuery : public sat::SolvIterMixin<PoolQuery, detail::PoolQueryIterator>
00091 {
00092 public:
00093 typedef std::set<ResKind> Kinds;
00094 typedef std::set<std::string> StrContainer;
00095 typedef std::map<sat::SolvAttr, StrContainer> AttrRawStrMap;
00096
00097 typedef detail::PoolQueryIterator const_iterator;
00098 typedef unsigned int size_type;
00099
00100 public:
00101 typedef function<bool( const sat::Solvable & )> ProcessResolvable;
00102
00103 PoolQuery();
00104 ~PoolQuery();
00105
00120 const_iterator begin() const;
00121
00123 const_iterator end() const;
00124
00126 bool empty() const;
00127
00129 size_type size() const;
00131
00136 void execute(ProcessResolvable fnc);
00137
00146 void addKind(const ResKind & kind);
00147
00154 void addRepo(const std::string &repoalias);
00155
00158
00162 enum StatusFilter {
00163 ALL = 0,
00164 INSTALLED_ONLY = 1,
00165 UNINSTALLED_ONLY = 2
00166 };
00167
00169 void setInstalledOnly();
00171 void setUninstalledOnly();
00173 void setStatusFilterFlags( StatusFilter flags );
00174
00176
00188 void addString(const std::string & value);
00189
00217 void addAttribute( const sat::SolvAttr & attr, const std::string & value = "" );
00218
00280 void addDependency( const sat::SolvAttr & attr, const std::string & name, const Rel & op, const Edition & edition );
00282 void addDependency( const sat::SolvAttr & attr, const std::string & name, const Rel & op, const Edition & edition, const Arch & arch );
00283
00285 void addDependency( const sat::SolvAttr & attr, const std::string & name, const Edition & edition )
00286 { addDependency( attr, name, Rel::EQ, edition ); }
00288 void addDependency( const sat::SolvAttr & attr, const std::string & name, const Edition & edition, const Arch & arch )
00289 { addDependency( attr, name, Rel::EQ, edition, arch ); }
00290
00292 void addDependency( const sat::SolvAttr & attr, const std::string & name )
00293 { addDependency( attr, name, Rel::ANY, Edition() ); }
00295 void addDependency( const sat::SolvAttr & attr, const std::string & name, const Arch & arch )
00296 { addDependency( attr, name, Rel::ANY, Edition(), arch ); }
00297
00299 void addDependency( const sat::SolvAttr & attr, const Rel & op, const Edition & edition )
00300 { addDependency( attr, std::string(), op, edition ); }
00302 void addDependency( const sat::SolvAttr & attr, const Rel & op, const Edition & edition, const Arch & arch )
00303 { addDependency( attr, std::string(), op, edition, arch ); }
00304
00306 void addDependency( const sat::SolvAttr & attr, const Edition & edition )
00307 { addDependency( attr, std::string(), Rel::EQ, edition ); }
00309 void addDependency( const sat::SolvAttr & attr, const Edition & edition, const Arch & arch )
00310 { addDependency( attr, std::string(), Rel::EQ, edition, arch ); }
00311
00313 void addDependency( const sat::SolvAttr & attr )
00314 { addDependency( attr, std::string(), Rel::ANY, Edition() ); }
00316 void addDependency( const sat::SolvAttr & attr, const Arch & arch )
00317 { addDependency( attr, std::string(), Rel::ANY, Edition(), arch ); }
00318
00323 void addDependency( const sat::SolvAttr & attr, Capability cap_r );
00325
00333 void setEdition(const Edition & edition, const Rel & op = Rel::EQ);
00334
00348 void setCaseSensitive( bool value = true );
00349
00355 void setFilesMatchFullPath( bool value = true );
00357 void setFilesMatchBasename( bool value = true )
00358 { setFilesMatchFullPath( !value ); }
00359
00361 void setMatchExact();
00363 void setMatchSubstring();
00365 void setMatchGlob();
00367 void setMatchRegex();
00369 void setMatchWord();
00370
00372
00379 void setRequireAll( bool require_all = true );
00380
00381
00384
00386 const StrContainer & strings() const;
00390 const AttrRawStrMap & attributes() const;
00391
00392 const StrContainer & attribute(const sat::SolvAttr & attr) const;
00393
00394 const Kinds & kinds() const;
00395
00396 const StrContainer & repos() const;
00397
00398 const Edition edition() const;
00399 const Rel editionRel() const;
00400
00404 bool caseSensitive() const;
00405
00407 bool filesMatchFullPath() const;
00409 bool filesMatchBasename() const
00410 { return !filesMatchFullPath(); }
00411
00412 bool matchExact() const;
00413 bool matchSubstring() const;
00414 bool matchGlob() const;
00415 bool matchRegex() const;
00416 bool matchWord() const;
00417
00421 Match::Mode matchMode() const
00422 { return flags().mode(); }
00423
00428 bool requireAll() const;
00429
00430 StatusFilter statusFilterFlags() const;
00432
00443 bool recover( std::istream &str, char delim = '\n' );
00444
00454 void serialize( std::ostream &str, char delim = '\n' ) const;
00455
00457 std::string asString() const;
00458
00459 bool operator==(const PoolQuery& b) const;
00460 bool operator!=(const PoolQuery& b) const { return !(*this == b ); }
00461
00462
00463
00470 Match flags() const;
00471
00478 void setFlags( const Match & flags );
00479
00480 public:
00481 class Impl;
00482 private:
00484 RW_pointer<Impl> _pimpl;
00485 };
00487
00489 std::ostream & operator<<( std::ostream & str, const PoolQuery & obj );
00490
00492 std::ostream & dumpOn( std::ostream & str, const PoolQuery & obj );
00493
00495 namespace detail
00496 {
00497
00498 class PoolQueryMatcher;
00499
00501
00502
00503
00511 class PoolQueryIterator : public boost::iterator_adaptor<
00512 PoolQueryIterator
00513 , sat::LookupAttr::iterator
00514 , const sat::Solvable
00515 , boost::forward_traversal_tag
00516 , const sat::Solvable
00517 >
00518 {
00519 typedef std::vector<sat::LookupAttr::iterator> Matches;
00520 public:
00521 typedef Matches::size_type size_type;
00522 typedef Matches::const_iterator matches_iterator;
00523 public:
00525 PoolQueryIterator()
00526 {}
00527
00529 PoolQueryIterator( const shared_ptr<PoolQueryMatcher> & matcher_r )
00530 : _matcher( matcher_r )
00531 { increment(); }
00532
00579 bool matchesEmpty() const { return ! _matcher; }
00581 size_type matchesSize() const { return matches().size(); }
00583 matches_iterator matchesBegin() const { return matches().begin(); }
00585 matches_iterator matchesEnd() const { return matches().end(); }
00587
00588 private:
00589 friend class boost::iterator_core_access;
00590
00591 sat::Solvable dereference() const
00592 { return base_reference().inSolvable(); }
00593
00594 void increment();
00595
00596 private:
00597 const Matches & matches() const;
00598
00599 private:
00600 shared_ptr<PoolQueryMatcher> _matcher;
00601 mutable shared_ptr<Matches> _matches;
00602 };
00604
00606 inline std::ostream & operator<<( std::ostream & str, const PoolQueryIterator & obj )
00607 { return str << obj.base(); }
00608
00610 std::ostream & dumpOn( std::ostream & str, const PoolQueryIterator & obj );
00611
00613 }
00615
00616 inline detail::PoolQueryIterator PoolQuery::end() const
00617 { return detail::PoolQueryIterator(); }
00618
00620 }
00622
00623 #endif // ZYPP_POOLQUERY_H