libzypp 17.34.1
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 ZYPP_API PoolQuery : public sat::SolvIterMixin<PoolQuery, detail::PoolQueryIterator>
91 {
92 public:
93 using Kinds = std::set<ResKind>;
94 using StrContainer = std::set<std::string>;
95 using AttrRawStrMap = std::map<sat::SolvAttr, StrContainer>;
96
98 using size_type = unsigned int;
99
100 public:
101 using ProcessResolvable = function<bool (const sat::Solvable &)>;
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
179 INSTALLED_ONLY = 1,
180 UNINSTALLED_ONLY = 2
181 };
182
184 void setInstalledOnly();
186 void setUninstalledOnly();
188 void setStatusFilterFlags( StatusFilter flags );
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
320 void addDependency( const sat::SolvAttr & attr, const Edition & edition )
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
431 StatusFilter statusFilterFlags() const;
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 ) ZYPP_API;
498
500 std::ostream & dumpOn( std::ostream & str, const PoolQuery & obj ) ZYPP_API;
501
503 namespace detail
504 {
505
506 class PoolQueryMatcher;
507
509 //
510 // CLASS NAME : PoolQuery::PoolQueryIterator
511 //
519 class ZYPP_API 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 using Matches = std::vector<sat::LookupAttr::iterator>;
528 public:
529 using size_type = Matches::size_type;
530 using matches_iterator = Matches::const_iterator;
531 public:
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 ) ZYPP_API;
619
621 } //namespace detail
623
626
628} // namespace zypp
630
631#endif // ZYPP_POOLQUERY_H
sat::SolvAttr attr
Definition PoolQuery.cc:312
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
Meta-data query API.
Definition PoolQuery.h:91
void addDependency(const sat::SolvAttr &attr, const Arch &arch)
Definition PoolQuery.h:330
void addDependency(const sat::SolvAttr &attr, const Edition &edition, const Arch &arch)
Definition PoolQuery.h:323
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 filesMatchBasename() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition PoolQuery.h:416
unsigned int size_type
Definition PoolQuery.h:98
bool operator!=(const PoolQuery &b) const
Definition PoolQuery.h:462
function< bool(const sat::Solvable &)> ProcessResolvable
Definition PoolQuery.h:101
std::map< sat::SolvAttr, StrContainer > AttrRawStrMap
Definition PoolQuery.h:95
void addDependency(const sat::SolvAttr &attr, const std::string &name, const Edition &edition, const Arch &arch)
Definition PoolQuery.h:302
Match::Mode matchMode() const
Returns string matching mode as enum.
Definition PoolQuery.h:428
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
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
std::set< std::string > StrContainer
Definition PoolQuery.h:94
void addDependency(const sat::SolvAttr &attr, const Rel &op, const Edition &edition)
Definition PoolQuery.h:313
StatusFilter
Installed status filter setters.
Definition PoolQuery.h:177
void addDependency(const sat::SolvAttr &attr)
Definition PoolQuery.h:327
std::set< ResKind > Kinds
Definition PoolQuery.h:93
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
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:364
String related utilities and Regular expression matching.
Easy-to use interface to the ZYPP dependency resolver.
bool operator<(const StrMatcher &lhs, const StrMatcher &rhs)
bool operator==(const SetRelation::Enum &lhs, const SetCompare &rhs)
This is an overloaded member function, provided for convenience. It differs from the above function o...
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Definition Arch.h:247
std::string asString(const Patch::Category &obj)
Definition Patch.cc:122
Wrapper for const correct access via Smart pointer types.
Definition PtrTypes.h:293
Relational operators.
Definition Rel.h:46
static const Rel ANY
Definition Rel.h:58
static const Rel EQ
Definition Rel.h:52
#define ZYPP_DEPRECATED
The ZYPP_DEPRECATED macro can be used to trigger compile-time warnings with gcc >= 3....
Definition Globals.h:106