PoolQuery.h
Go to the documentation of this file.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
00277 void addDependency( const sat::SolvAttr & attr, const std::string & name, const Rel & op, const Edition & edition );
00278
00280 void addDependency( const sat::SolvAttr & attr, const std::string & name, const Edition & edition )
00281 { addDependency( attr, name, Rel::EQ, edition ); }
00282
00284 void addDependency( const sat::SolvAttr & attr, const std::string & name )
00285 { addDependency( attr, name, Rel::ANY, Edition() ); }
00286
00288 void addDependency( const sat::SolvAttr & attr, const Rel & op, const Edition & edition )
00289 { addDependency( attr, std::string(), op, edition ); }
00290
00292 void addDependency( const sat::SolvAttr & attr, const Edition & edition )
00293 { addDependency( attr, std::string(), Rel::EQ, edition ); }
00294
00296 void addDependency( const sat::SolvAttr & attr )
00297 { addDependency( attr, std::string(), Rel::ANY, Edition() ); }
00298
00303 void addDependency( const sat::SolvAttr & attr, Capability cap_r );
00305
00313 void setEdition(const Edition & edition, const Rel & op = Rel::EQ);
00314
00328 void setCaseSensitive( bool value = true );
00329
00335 void setFilesMatchFullPath( bool value = true );
00337 void setFilesMatchBasename( bool value = true )
00338 { setFilesMatchFullPath( !value ); }
00339
00341 void setMatchExact();
00343 void setMatchSubstring();
00345 void setMatchGlob();
00347 void setMatchRegex();
00349 void setMatchWord();
00350
00352
00359 void setRequireAll( bool require_all = true );
00360
00361
00364
00366 const StrContainer & strings() const;
00370 const AttrRawStrMap & attributes() const;
00371
00372 const StrContainer & attribute(const sat::SolvAttr & attr) const;
00373
00374 const Kinds & kinds() const;
00375
00376 const StrContainer & repos() const;
00377
00378 const Edition edition() const;
00379 const Rel editionRel() const;
00380
00384 bool caseSensitive() const;
00385
00387 bool filesMatchFullPath() const;
00389 bool filesMatchBasename() const
00390 { return !filesMatchFullPath(); }
00391
00392 bool matchExact() const;
00393 bool matchSubstring() const;
00394 bool matchGlob() const;
00395 bool matchRegex() const;
00396 bool matchWord() const;
00397
00401 Match::Mode matchMode() const
00402 { return flags().mode(); }
00403
00408 bool requireAll() const;
00409
00410 StatusFilter statusFilterFlags() const;
00412
00423 bool recover( std::istream &str, char delim = '\n' );
00424
00434 void serialize( std::ostream &str, char delim = '\n' ) const;
00435
00437 std::string asString() const;
00438
00439 bool operator==(const PoolQuery& b) const;
00440 bool operator!=(const PoolQuery& b) const { return !(*this == b ); }
00441
00442
00443
00450 Match flags() const;
00451
00458 void setFlags( const Match & flags );
00459
00460 public:
00461 class Impl;
00462 private:
00464 RW_pointer<Impl> _pimpl;
00465 };
00467
00469 std::ostream & operator<<( std::ostream & str, const PoolQuery & obj );
00470
00472 std::ostream & dumpOn( std::ostream & str, const PoolQuery & obj );
00473
00475 namespace detail
00476 {
00477
00478 class PoolQueryMatcher;
00479
00481
00482
00483
00491 class PoolQueryIterator : public boost::iterator_adaptor<
00492 PoolQueryIterator
00493 , sat::LookupAttr::iterator
00494 , const sat::Solvable
00495 , boost::forward_traversal_tag
00496 , const sat::Solvable
00497 >
00498 {
00499 typedef std::vector<sat::LookupAttr::iterator> Matches;
00500 public:
00501 typedef Matches::size_type size_type;
00502 typedef Matches::const_iterator matches_iterator;
00503 public:
00505 PoolQueryIterator()
00506 {}
00507
00509 PoolQueryIterator( const shared_ptr<PoolQueryMatcher> & matcher_r )
00510 : _matcher( matcher_r )
00511 { increment(); }
00512
00559 bool matchesEmpty() const { return ! _matcher; }
00561 size_type matchesSize() const { return matches().size(); }
00563 matches_iterator matchesBegin() const { return matches().begin(); }
00565 matches_iterator matchesEnd() const { return matches().end(); }
00567
00568 private:
00569 friend class boost::iterator_core_access;
00570
00571 sat::Solvable dereference() const
00572 { return base_reference().inSolvable(); }
00573
00574 void increment();
00575
00576 private:
00577 const Matches & matches() const;
00578
00579 private:
00580 shared_ptr<PoolQueryMatcher> _matcher;
00581 mutable shared_ptr<Matches> _matches;
00582 };
00584
00586 inline std::ostream & operator<<( std::ostream & str, const PoolQueryIterator & obj )
00587 { return str << obj.base(); }
00588
00590 std::ostream & dumpOn( std::ostream & str, const PoolQueryIterator & obj );
00591
00593 }
00595
00596 inline detail::PoolQueryIterator PoolQuery::end() const
00597 { return detail::PoolQueryIterator(); }
00598
00600 }
00602
00603 #endif // ZYPP_POOLQUERY_H