libzypp: zypp/PoolQuery.h Source File

libzypp 17.25.10

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
97 typedef detail::PoolQueryIterator const_iterator;
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
169 enum StatusFilter {
170 ALL = 0, // both install filter and uninstall filter bits are 0
171 INSTALLED_ONLY = 1,
172 UNINSTALLED_ONLY = 2
173 };
174
176 void setInstalledOnly();
178 void setUninstalledOnly();
180 void setStatusFilterFlags( StatusFilter flags );
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
319 void addDependency( const sat::SolvAttr & attr )
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
418 Match::Mode matchMode() const
419 { return flags().mode(); }
420
421 StatusFilter statusFilterFlags() const;
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:
519 typedef Matches::size_type size_type;
520 typedef Matches::const_iterator matches_iterator;
521 public:
523 PoolQueryIterator()
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
614 inline detail::PoolQueryIterator PoolQuery::end() const
615 { return detail::PoolQueryIterator(); }
616
618 } // namespace zypp
620
621 #endif // ZYPP_POOLQUERY_H
Function.h
LookupAttr.h
attr
sat::SolvAttr attr
Definition: PoolQuery.cc:311
Pool.h
PtrTypes.h
Regex.h
SolvIterMixin.h
StrMatcher.h
Impl
zypp::Arch
Architecture.
Definition: Arch.h:37
zypp::Capability
A sat capability.
Definition: Capability.h:60
zypp::Edition
Edition represents [epoch:]version[-release]
Definition: Edition.h:61
zypp::Match
String matching option flags as used e.g.
Definition: StrMatcher.h:33
zypp::Match::Mode
Mode
Mode flags (mutual exclusive).
Definition: StrMatcher.h:41
zypp::Match::mode
Mode mode() const
Return the mode part.
Definition: StrMatcher.cc:52
zypp::PoolQuery::Impl
Definition: PoolQuery.cc:416
zypp::PoolQuery
Meta-data query API.
Definition: PoolQuery.h:91
zypp::PoolQuery::flags
Match flags() const
Free function to get libsolv repo search flags.
Definition: PoolQuery.cc:957
zypp::PoolQuery::addString
void addString(const std::string &value)
Add a global query string.
Definition: PoolQuery.cc:870
zypp::PoolQuery::editionRel
const Rel editionRel() const
Definition: PoolQuery.cc:989
zypp::PoolQuery::StrContainer
std::set< std::string > StrContainer
Definition: PoolQuery.h:94
zypp::PoolQuery::addDependency
void addDependency(const sat::SolvAttr &attr, const Arch &arch)
Definition: PoolQuery.h:322
zypp::PoolQuery::matchSubstring
bool matchSubstring() const
Definition: PoolQuery.cc:1013
zypp::PoolQuery::repos
const StrContainer & repos() const
Definition: PoolQuery.cc:998
zypp::PoolQuery::setMatchExact
void setMatchExact()
Set to match exact string instead of substring.
Definition: PoolQuery.cc:952
zypp::PoolQuery::setMatchWord
void setMatchWord()
Set substring to match words.
Definition: PoolQuery.cc:955
zypp::PoolQuery::setMatchRegex
void setMatchRegex()
Set to use the query strings as regexes.
Definition: PoolQuery.cc:953
zypp::PoolQuery::edition
const Edition edition() const
Definition: PoolQuery.cc:987
zypp::PoolQuery::setFlags
void setFlags(const Match &flags)
Free function to set libsolv repo search flags.
Definition: PoolQuery.cc:959
zypp::PoolQuery::_pimpl
RW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: PoolQuery.h:479
zypp::PoolQuery::setCaseSensitive
void setCaseSensitive(bool value=true)
Turn case sentitivity on or off (unsets or sets SEARCH_NOCASE flag).
Definition: PoolQuery.cc:1004
zypp::PoolQuery::matchRegex
bool matchRegex() const
Definition: PoolQuery.cc:1015
zypp::PoolQuery::addDependency
void addDependency(const sat::SolvAttr &attr, const Edition &edition, const Arch &arch)
Definition: PoolQuery.h:315
zypp::PoolQuery::execute
void execute(ProcessResolvable fnc)
Executes the query with the current settings.
Definition: PoolQuery.cc:1041
zypp::PoolQuery::asString
std::string asString() const
Return a human-readable description of the query.
Definition: PoolQuery.cc:1468
zypp::PoolQuery::size_type
unsigned int size_type
Definition: PoolQuery.h:98
zypp::PoolQuery::setStatusFilterFlags
void setStatusFilterFlags(StatusFilter flags)
Set status filter directly.
Definition: PoolQuery.cc:967
zypp::PoolQuery::empty
bool empty() const
Whether the result is empty.
Definition: PoolQuery.cc:1021
zypp::PoolQuery::addKind
void addKind(const ResKind &kind)
Filter by selectable kind.
Definition: PoolQuery.cc:867
zypp::PoolQuery::operator==
bool operator==(const PoolQuery &b) const
Definition: PoolQuery.cc:1477
zypp::PoolQuery::setFilesMatchBasename
void setFilesMatchBasename(bool value=true)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: PoolQuery.h:363
zypp::PoolQuery::matchExact
bool matchExact() const
Definition: PoolQuery.cc:1012
zypp::PoolQuery::filesMatchBasename
bool filesMatchBasename() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: PoolQuery.h:406
zypp::PoolQuery::setRequireAll
void setRequireAll(bool require_all=true) ZYPP_DEPRECATED
Definition: PoolQuery.cc:1045
zypp::PoolQuery::matchWord
bool matchWord() const
Definition: PoolQuery.cc:1016
zypp::PoolQuery::operator!=
bool operator!=(const PoolQuery &b) const
Definition: PoolQuery.h:452
zypp::PoolQuery::~PoolQuery
~PoolQuery()
Definition: PoolQuery.cc:854
zypp::PoolQuery::addAttribute
void addAttribute(const sat::SolvAttr &attr, const std::string &value="")
Filter by the value of the specified attr attribute.
Definition: PoolQuery.cc:873
zypp::PoolQuery::requireAll
bool requireAll() const ZYPP_DEPRECATED
Definition: PoolQuery.cc:1046
zypp::PoolQuery::addDependency
void addDependency(const sat::SolvAttr &attr, const std::string &name, const Edition &edition, const Arch &arch)
Definition: PoolQuery.h:294
zypp::PoolQuery::filesMatchFullPath
bool filesMatchFullPath() const
Whether searching in filelists looks at the full path or just at the basenames.
Definition: PoolQuery.cc:1007
zypp::PoolQuery::addRepo
void addRepo(const std::string &repoalias)
Filter by repo.
Definition: PoolQuery.cc:857
zypp::PoolQuery::kinds
const Kinds & kinds() const
Definition: PoolQuery.cc:994
zypp::PoolQuery::matchMode
Match::Mode matchMode() const
Returns string matching mode as enum.
Definition: PoolQuery.h:418
zypp::PoolQuery::dumpOn
std::ostream & dumpOn(std::ostream &str, const PoolQuery &obj)
Detailed stream output.
Definition: PoolQuery.cc:1474
zypp::PoolQuery::setInstalledOnly
void setInstalledOnly()
Return only @System repo packages.
Definition: PoolQuery.cc:963
zypp::PoolQuery::PoolQuery
PoolQuery()
Definition: PoolQuery.cc:850
zypp::PoolQuery::addDependency
void addDependency(const sat::SolvAttr &attr, const Rel &op, const Edition &edition, const Arch &arch)
Definition: PoolQuery.h:308
zypp::PoolQuery::end
const_iterator end() const
An iterator pointing to the end of the query result.
Definition: PoolQuery.h:614
zypp::PoolQuery::statusFilterFlags
StatusFilter statusFilterFlags() const
Definition: PoolQuery.cc:1018
zypp::PoolQuery::strings
const StrContainer & strings() const
Search strings added via addString()
Definition: PoolQuery.cc:972
zypp::PoolQuery::Kinds
std::set< ResKind > Kinds
Definition: PoolQuery.h:93
zypp::PoolQuery::matchGlob
bool matchGlob() const
Definition: PoolQuery.cc:1014
zypp::PoolQuery::addDependency
void addDependency(const sat::SolvAttr &attr, const std::string &name, const Arch &arch)
Definition: PoolQuery.h:301
zypp::PoolQuery::addDependency
void addDependency(const sat::SolvAttr &attr, const Edition &edition)
Definition: PoolQuery.h:312
zypp::PoolQuery::size
size_type size() const
Number of solvables in the query result.
Definition: PoolQuery.cc:1028
zypp::PoolQuery::begin
const_iterator begin() const
Query result accessers.
Definition: PoolQuery.cc:1826
zypp::PoolQuery::addDependency
void addDependency(const sat::SolvAttr &attr, const Rel &op, const Edition &edition)
Definition: PoolQuery.h:305
zypp::PoolQuery::recover
bool recover(std::istream &str, char delim='\n')
Reads from stream query.
Definition: PoolQuery.cc:1135
zypp::PoolQuery::serialize
void serialize(std::ostream &str, char delim='\n') const
Writes a machine-readable string representation of the query to stream.
Definition: PoolQuery.cc:1372
zypp::PoolQuery::AttrRawStrMap
std::map< sat::SolvAttr, StrContainer > AttrRawStrMap
Definition: PoolQuery.h:95
zypp::PoolQuery::attributes
const AttrRawStrMap & attributes() const
Map (map<SolvAttr, StrContainer>) of attribute values added via addAttribute(), addDep in string form...
Definition: PoolQuery.cc:976
zypp::PoolQuery::addDependency
void addDependency(const sat::SolvAttr &attr, const std::string &name, const Rel &op, const Edition &edition)
Query "name|global op edition".
Definition: PoolQuery.cc:876
zypp::PoolQuery::StatusFilter
StatusFilter
Installed status filter setters.
Definition: PoolQuery.h:169
zypp::PoolQuery::UNINSTALLED_ONLY
@ UNINSTALLED_ONLY
Definition: PoolQuery.h:172
zypp::PoolQuery::ALL
@ ALL
Definition: PoolQuery.h:170
zypp::PoolQuery::INSTALLED_ONLY
@ INSTALLED_ONLY
Definition: PoolQuery.h:171
zypp::PoolQuery::addDependency
void addDependency(const sat::SolvAttr &attr)
Definition: PoolQuery.h:319
zypp::PoolQuery::setEdition
void setEdition(const Edition &edition, const Rel &op=Rel::EQ)
Set version condition.
Definition: PoolQuery.cc:945
zypp::PoolQuery::attribute
const StrContainer & attribute(const sat::SolvAttr &attr) const
Definition: PoolQuery.cc:980
zypp::PoolQuery::setMatchSubstring
void setMatchSubstring()
Set to substring (the default).
Definition: PoolQuery.cc:951
zypp::PoolQuery::setFilesMatchFullPath
void setFilesMatchFullPath(bool value=true)
If set (default), look at the full path when searching in filelists.
Definition: PoolQuery.cc:1009
zypp::PoolQuery::addDependency
void addDependency(const sat::SolvAttr &attr, const std::string &name, const Edition &edition)
Definition: PoolQuery.h:291
zypp::PoolQuery::addDependency
void addDependency(const sat::SolvAttr &attr, const std::string &name)
Definition: PoolQuery.h:298
zypp::PoolQuery::setUninstalledOnly
void setUninstalledOnly()
Return only packages from repos other than @System.
Definition: PoolQuery.cc:965
zypp::PoolQuery::const_iterator
detail::PoolQueryIterator const_iterator
Definition: PoolQuery.h:97
zypp::PoolQuery::ProcessResolvable
function< bool(const sat::Solvable &)> ProcessResolvable
Definition: PoolQuery.h:101
zypp::PoolQuery::setMatchGlob
void setMatchGlob()
Set to match globs.
Definition: PoolQuery.cc:954
zypp::PoolQuery::operator<
bool operator<(const PoolQuery &b) const
Definition: PoolQuery.cc:1480
zypp::PoolQuery::caseSensitive
bool caseSensitive() const
returns true if search is case sensitive
Definition: PoolQuery.cc:1002
zypp::ResKind
Resolvable kinds.
Definition: ResKind.h:33
zypp::detail::PoolQueryIterator
PoolQuery iterator as returned by PoolQuery::begin.
Definition: PoolQuery.h:516
zypp::detail::PoolQueryIterator::dereference
sat::Solvable dereference() const
Definition: PoolQuery.h:589
zypp::detail::PoolQueryIterator::matchesSize
size_type matchesSize() const
Number of attribute matches.
Definition: PoolQuery.h:579
zypp::detail::PoolQueryIterator::matchesEnd
matches_iterator matchesEnd() const
End of matches.
Definition: PoolQuery.h:583
zypp::detail::PoolQueryIterator::matchesEmpty
bool matchesEmpty() const
False unless this is the end iterator.
Definition: PoolQuery.h:577
zypp::detail::PoolQueryIterator::_matches
shared_ptr< Matches > _matches
Definition: PoolQuery.h:599
zypp::detail::PoolQueryIterator::matchesBegin
matches_iterator matchesBegin() const
Begin of matches.
Definition: PoolQuery.h:581
zypp::detail::PoolQueryIterator::size_type
Matches::size_type size_type
Definition: PoolQuery.h:519
zypp::detail::PoolQueryIterator::_matcher
shared_ptr< PoolQueryMatcher > _matcher
Definition: PoolQuery.h:598
zypp::detail::PoolQueryIterator::matches_iterator
Matches::const_iterator matches_iterator
Definition: PoolQuery.h:520
zypp::detail::PoolQueryIterator::Matches
std::vector< sat::LookupAttr::iterator > Matches
Definition: PoolQuery.h:517
zypp::detail::PoolQueryIterator::operator<<
std::ostream & operator<<(std::ostream &str, const PoolQueryIterator &obj)
Stream output.
Definition: PoolQuery.h:604
zypp::detail::PoolQueryIterator::PoolQueryIterator
PoolQueryIterator()
Default ctor is also end.
Definition: PoolQuery.h:523
zypp::detail::PoolQueryIterator::PoolQueryIterator
PoolQueryIterator(const shared_ptr< PoolQueryMatcher > &matcher_r)
\Ref PoolQuery ctor.
Definition: PoolQuery.h:527
zypp::sat::SolvAttr
Solvable attribute keys.
Definition: SolvAttr.h:41
zypp::sat::SolvIterMixin
Base class providing common iterator types based on a Solvable iterator.
Definition: SolvIterMixin.h:117
zypp::sat::Solvable
A Solvable object within the sat Pool.
Definition: Solvable.h:54
std
Definition: Arch.h:348
str
String related utilities and Regular expression matching.
zypp::sat::detail::size_type
SolvableIdType size_type
Definition: PoolMember.h:126
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
zypp::RW_pointer
Wrapper for const correct access via Smart pointer types.
Definition: PtrTypes.h:286
zypp::Rel
Relational operators.
Definition: Rel.h:44
zypp::Rel::ANY
static const Rel ANY
Definition: Rel.h:56
zypp::Rel::EQ
static const Rel EQ
Definition: Rel.h:50