libzypp 17.31.23
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
24#include <zypp/sat/LookupAttr.h>
26#include <zypp/sat/Pool.h>
27
29namespace 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
166 void setComment(const std::string & comment) const;
167#if LEGACY(1722)
168 void setComment(const std::string & comment);
169#endif
170
173
178 ALL = 0, // both install filter and uninstall filter bits are 0
181 };
182
184 void setInstalledOnly();
186 void setUninstalledOnly();
189
191
202 void addString(const std::string & value);
203
229 void addAttribute( const sat::SolvAttr & attr, const std::string & value = "" );
230
292 void addDependency( const sat::SolvAttr & attr, const std::string & name, const Rel & op, const Edition & edition );
294 void addDependency( const sat::SolvAttr & attr, const std::string & name, const Rel & op, const Edition & edition, const Arch & arch );
296 void addDependency( const sat::SolvAttr & attr, const std::string & name, const Rel & op, const Edition & edition, const Arch & arch, Match::Mode mode );
297
299 void addDependency( const sat::SolvAttr & attr, const std::string & name, const Edition & edition )
300 { addDependency( attr, name, Rel::EQ, edition ); }
302 void addDependency( const sat::SolvAttr & attr, const std::string & name, const Edition & edition, const Arch & arch )
303 { addDependency( attr, name, Rel::EQ, edition, arch ); }
304
306 void addDependency( const sat::SolvAttr & attr, const std::string & name )
307 { addDependency( attr, name, Rel::ANY, Edition() ); }
309 void addDependency( const sat::SolvAttr & attr, const std::string & name, const Arch & arch )
310 { addDependency( attr, name, Rel::ANY, Edition(), arch ); }
311
313 void addDependency( const sat::SolvAttr & attr, const Rel & op, const Edition & edition )
314 { addDependency( attr, std::string(), op, edition ); }
316 void addDependency( const sat::SolvAttr & attr, const Rel & op, const Edition & edition, const Arch & arch )
317 { addDependency( attr, std::string(), op, edition, arch ); }
318
321 { addDependency( attr, std::string(), Rel::EQ, edition ); }
323 void addDependency( const sat::SolvAttr & attr, const Edition & edition, const Arch & arch )
324 { addDependency( attr, std::string(), Rel::EQ, edition, arch ); }
325
328 { addDependency( attr, std::string(), Rel::ANY, Edition() ); }
330 void addDependency( const sat::SolvAttr & attr, const Arch & arch )
331 { addDependency( attr, std::string(), Rel::ANY, Edition(), arch ); }
332
337 void addDependency( const sat::SolvAttr & attr, Capability cap_r );
339
347 void setEdition(const Edition & edition, const Rel & op = Rel::EQ);
348
362 void setCaseSensitive( bool value = true );
363
369 void setFilesMatchFullPath( bool value = true );
371 void setFilesMatchBasename( bool value = true )
372 { setFilesMatchFullPath( !value ); }
373
375 void setMatchExact();
377 void setMatchSubstring();
379 void setMatchGlob();
381 void setMatchRegex();
383 void setMatchWord();
384 //void setLocale(const Locale & locale);
386
389
391 const StrContainer & strings() const;
395 const AttrRawStrMap & attributes() const;
396
397 const StrContainer & attribute(const sat::SolvAttr & attr) const;
398
399 const Kinds & kinds() const;
400
401 const StrContainer & repos() const;
402
403 const std::string & comment() const;
404
405 const Edition edition() const;
406 const Rel editionRel() const;
407
411 bool caseSensitive() const;
412
414 bool filesMatchFullPath() const;
417 { return !filesMatchFullPath(); }
418
419 bool matchExact() const;
420 bool matchSubstring() const;
421 bool matchGlob() const;
422 bool matchRegex() const;
423 bool matchWord() const;
424
429 { return flags().mode(); }
430
433
444 bool recover( std::istream &str, char delim = '\n' );
445
455 void serialize( std::ostream &str, char delim = '\n' ) const;
456
458 std::string asString() const;
459
460 bool operator<(const PoolQuery& b) const;
461 bool operator==(const PoolQuery& b) const;
462 bool operator!=(const PoolQuery& b) const { return !(*this == b ); }
463
464 // low level API
465
472 Match flags() const;
473
480 void setFlags( const Match & flags );
481
482 public:
484 void setRequireAll( bool require_all = true ) ZYPP_DEPRECATED;
486 bool requireAll() const ZYPP_DEPRECATED;
487
488 public:
489 class Impl;
490 private:
493 };
495
497 std::ostream & operator<<( std::ostream & str, const PoolQuery & obj );
498
500 std::ostream & dumpOn( std::ostream & str, const PoolQuery & obj );
501
503 namespace detail
504 {
505
506 class PoolQueryMatcher;
507
509 //
510 // CLASS NAME : PoolQuery::PoolQueryIterator
511 //
519 class PoolQueryIterator : public boost::iterator_adaptor<
520 PoolQueryIterator // Derived
521 , sat::LookupAttr::iterator // Base
522 , const sat::Solvable // Value
523 , boost::forward_traversal_tag // CategoryOrTraversal
524 , const sat::Solvable // Reference
525 >
526 {
527 typedef std::vector<sat::LookupAttr::iterator> Matches;
528 public:
529 typedef Matches::size_type size_type;
530 typedef Matches::const_iterator matches_iterator;
531 public:
534 {}
535
537 PoolQueryIterator( const shared_ptr<PoolQueryMatcher> & matcher_r )
538 : _matcher( matcher_r )
539 { increment(); }
540
587 bool matchesEmpty() const { return ! _matcher; }
589 size_type matchesSize() const { return matches().size(); }
591 matches_iterator matchesBegin() const { return matches().begin(); }
593 matches_iterator matchesEnd() const { return matches().end(); }
595
596 private:
597 friend class boost::iterator_core_access;
598
600 { return base_reference().inSolvable(); }
601
602 void increment();
603
604 private:
605 const Matches & matches() const;
606
607 private:
608 shared_ptr<PoolQueryMatcher> _matcher;
609 mutable shared_ptr<Matches> _matches;
610 };
612
614 inline std::ostream & operator<<( std::ostream & str, const PoolQueryIterator & obj )
615 { return str << obj.base(); }
616
618 std::ostream & dumpOn( std::ostream & str, const PoolQueryIterator & obj );
619
621 } //namespace detail
623
625 { return detail::PoolQueryIterator(); }
626
628} // namespace zypp
630
631#endif // ZYPP_POOLQUERY_H
sat::SolvAttr attr
Definition: PoolQuery.cc:311
RepoManager implementation.
Architecture.
Definition: Arch.h:37
A sat capability.
Definition: Capability.h:63
Edition represents [epoch:]version[-release]
Definition: Edition.h:61
String matching option flags as used e.g.
Definition: StrMatcher.h:33
Mode
Mode flags (mutual exclusive).
Definition: StrMatcher.h:41
Mode mode() const
Return the mode part.
Definition: StrMatcher.cc:52
Meta-data query API.
Definition: PoolQuery.h:91
Match flags() const
Free function to get libsolv repo search flags.
Definition: PoolQuery.cc:968
void addString(const std::string &value)
Add a global query string.
Definition: PoolQuery.cc:881
const Rel editionRel() const
Definition: PoolQuery.cc:1000
std::set< std::string > StrContainer
Definition: PoolQuery.h:94
void addDependency(const sat::SolvAttr &attr, const Arch &arch)
Definition: PoolQuery.h:330
bool matchSubstring() const
Definition: PoolQuery.cc:1027
const StrContainer & repos() const
Definition: PoolQuery.cc:1009
void setMatchExact()
Set to match exact string instead of substring.
Definition: PoolQuery.cc:963
void setMatchWord()
Set substring to match words.
Definition: PoolQuery.cc:966
void setMatchRegex()
Set to use the query strings as regexes.
Definition: PoolQuery.cc:964
const Edition edition() const
Definition: PoolQuery.cc:998
void setFlags(const Match &flags)
Free function to set libsolv repo search flags.
Definition: PoolQuery.cc:970
RW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: PoolQuery.h:492
void setCaseSensitive(bool value=true)
Turn case sentitivity on or off (unsets or sets SEARCH_NOCASE flag).
Definition: PoolQuery.cc:1018
bool matchRegex() const
Definition: PoolQuery.cc:1029
void setComment(const std::string &comment) const
Set an optional comment string describing the purpose of the query.
Definition: PoolQuery.cc:874
void addDependency(const sat::SolvAttr &attr, const Edition &edition, const Arch &arch)
Definition: PoolQuery.h:323
void execute(ProcessResolvable fnc)
Executes the query with the current settings.
Definition: PoolQuery.cc:1055
std::string asString() const
Return a human-readable description of the query.
Definition: PoolQuery.cc:1491
unsigned int size_type
Definition: PoolQuery.h:98
void setStatusFilterFlags(StatusFilter flags)
Set status filter directly.
Definition: PoolQuery.cc:978
bool empty() const
Whether the result is empty.
Definition: PoolQuery.cc:1035
void addKind(const ResKind &kind)
Filter by selectable kind.
Definition: PoolQuery.cc:871
bool operator==(const PoolQuery &b) const
Definition: PoolQuery.cc:1500
void setFilesMatchBasename(bool value=true)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: PoolQuery.h:371
bool matchExact() const
Definition: PoolQuery.cc:1026
bool filesMatchBasename() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: PoolQuery.h:416
void setRequireAll(bool require_all=true) ZYPP_DEPRECATED
Definition: PoolQuery.cc:1059
bool matchWord() const
Definition: PoolQuery.cc:1030
bool operator!=(const PoolQuery &b) const
Definition: PoolQuery.h:462
void addAttribute(const sat::SolvAttr &attr, const std::string &value="")
Filter by the value of the specified attr attribute.
Definition: PoolQuery.cc:884
bool requireAll() const ZYPP_DEPRECATED
Definition: PoolQuery.cc:1060
void addDependency(const sat::SolvAttr &attr, const std::string &name, const Edition &edition, const Arch &arch)
Definition: PoolQuery.h:302
const std::string & comment() const
Definition: PoolQuery.cc:1013
bool filesMatchFullPath() const
Whether searching in filelists looks at the full path or just at the basenames.
Definition: PoolQuery.cc:1021
void addRepo(const std::string &repoalias)
Filter by repo.
Definition: PoolQuery.cc:861
const Kinds & kinds() const
Definition: PoolQuery.cc:1005
Match::Mode matchMode() const
Returns string matching mode as enum.
Definition: PoolQuery.h:428
std::ostream & dumpOn(std::ostream &str, const PoolQuery &obj)
Detailed stream output.
Definition: PoolQuery.cc:1497
void setInstalledOnly()
Return only @System repo packages.
Definition: PoolQuery.cc:974
void addDependency(const sat::SolvAttr &attr, const Rel &op, const Edition &edition, const Arch &arch)
Definition: PoolQuery.h:316
const_iterator end() const
An iterator pointing to the end of the query result.
Definition: PoolQuery.h:624
StatusFilter statusFilterFlags() const
Definition: PoolQuery.cc:1032
const StrContainer & strings() const
Search strings added via addString()
Definition: PoolQuery.cc:983
std::set< ResKind > Kinds
Definition: PoolQuery.h:93
bool matchGlob() const
Definition: PoolQuery.cc:1028
void addDependency(const sat::SolvAttr &attr, const std::string &name, const Arch &arch)
Definition: PoolQuery.h:309
void addDependency(const sat::SolvAttr &attr, const Edition &edition)
Definition: PoolQuery.h:320
size_type size() const
Number of solvables in the query result.
Definition: PoolQuery.cc:1042
const_iterator begin() const
Query result accessers.
Definition: PoolQuery.cc:1849
void addDependency(const sat::SolvAttr &attr, const Rel &op, const Edition &edition)
Definition: PoolQuery.h:313
bool recover(std::istream &str, char delim='\n')
Reads from stream query.
Definition: PoolQuery.cc:1151
void serialize(std::ostream &str, char delim='\n') const
Writes a machine-readable string representation of the query to stream.
Definition: PoolQuery.cc:1392
std::map< sat::SolvAttr, StrContainer > AttrRawStrMap
Definition: PoolQuery.h:95
const AttrRawStrMap & attributes() const
Map (map<SolvAttr, StrContainer>) of attribute values added via addAttribute(), addDep in string form...
Definition: PoolQuery.cc:987
void addDependency(const sat::SolvAttr &attr, const std::string &name, const Rel &op, const Edition &edition)
Query "name|global op edition".
Definition: PoolQuery.cc:887
StatusFilter
Installed status filter setters.
Definition: PoolQuery.h:177
void addDependency(const sat::SolvAttr &attr)
Definition: PoolQuery.h:327
void setEdition(const Edition &edition, const Rel &op=Rel::EQ)
Set version condition.
Definition: PoolQuery.cc:956
const StrContainer & attribute(const sat::SolvAttr &attr) const
Definition: PoolQuery.cc:991
void setMatchSubstring()
Set to substring (the default).
Definition: PoolQuery.cc:962
void setFilesMatchFullPath(bool value=true)
If set (default), look at the full path when searching in filelists.
Definition: PoolQuery.cc:1023
void addDependency(const sat::SolvAttr &attr, const std::string &name, const Edition &edition)
Definition: PoolQuery.h:299
void addDependency(const sat::SolvAttr &attr, const std::string &name)
Definition: PoolQuery.h:306
void setUninstalledOnly()
Return only packages from repos other than @System.
Definition: PoolQuery.cc:976
detail::PoolQueryIterator const_iterator
Definition: PoolQuery.h:97
function< bool(const sat::Solvable &)> ProcessResolvable
Definition: PoolQuery.h:101
void setMatchGlob()
Set to match globs.
Definition: PoolQuery.cc:965
bool operator<(const PoolQuery &b) const
Definition: PoolQuery.cc:1503
bool caseSensitive() const
returns true if search is case sensitive
Definition: PoolQuery.cc:1016
Resolvable kinds.
Definition: ResKind.h:33
PoolQuery iterator as returned by PoolQuery::begin.
Definition: PoolQuery.h:526
sat::Solvable dereference() const
Definition: PoolQuery.h:599
size_type matchesSize() const
Number of attribute matches.
Definition: PoolQuery.h:589
matches_iterator matchesEnd() const
End of matches.
Definition: PoolQuery.h:593
bool matchesEmpty() const
False unless this is the end iterator.
Definition: PoolQuery.h:587
shared_ptr< Matches > _matches
Definition: PoolQuery.h:609
matches_iterator matchesBegin() const
Begin of matches.
Definition: PoolQuery.h:591
Matches::size_type size_type
Definition: PoolQuery.h:529
shared_ptr< PoolQueryMatcher > _matcher
Definition: PoolQuery.h:608
Matches::const_iterator matches_iterator
Definition: PoolQuery.h:530
std::vector< sat::LookupAttr::iterator > Matches
Definition: PoolQuery.h:527
std::ostream & operator<<(std::ostream &str, const PoolQueryIterator &obj)
Stream output.
Definition: PoolQuery.h:614
PoolQueryIterator()
Default ctor is also end.
Definition: PoolQuery.h:533
PoolQueryIterator(const shared_ptr< PoolQueryMatcher > &matcher_r)
\Ref PoolQuery ctor.
Definition: PoolQuery.h:537
Solvable attribute keys.
Definition: SolvAttr.h:41
Base class providing common iterator types based on a Solvable iterator.
A Solvable object within the sat Pool.
Definition: Solvable.h:54
unsigned short b
Definition: Arch.h:361
String related utilities and Regular expression matching.
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
Wrapper for const correct access via Smart pointer types.
Definition: PtrTypes.h:286
Relational operators.
Definition: Rel.h:44
static const Rel ANY
Definition: Rel.h:56
static const Rel EQ
Definition: Rel.h:50
#define ZYPP_DEPRECATED
The ZYPP_DEPRECATED macro can be used to trigger compile-time warnings with gcc >= 3....
Definition: Globals.h:99