libzypp 17.38.7
lookupattr.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#ifndef ZYPPNG_SAT_LOOKUPATTR_H
13#define ZYPPNG_SAT_LOOKUPATTR_H
14
15#include <iosfwd>
16#include <utility>
17
20#include <zypp-core/Globals.h>
21
25#include <zypp/ng/idstring.h>
26
27namespace zypp
28{
29 class CheckSum;
30 class Match;
31 struct MatchException;
32 class StrMatcher;
33}
34
35namespace zyppng::sat
36{
37 class Pool;
38
39 using zypp::MatchException;
40 using zypp::StrMatcher;
41 using zypp::CheckSum;
42
112 {
113 public:
115
116 public:
117 using size_type = unsigned int;
118
120 enum Location {
123 };
124
125 public:
127 LookupAttr();
128
129 LookupAttr(const LookupAttr &) = default;
130 LookupAttr(LookupAttr &&) noexcept = default;
131 LookupAttr &operator=(const LookupAttr &) = default;
132 LookupAttr &operator=(LookupAttr &&) noexcept = default;
133
135 explicit LookupAttr( Pool & pool, SolvAttr attr_r, Location = SOLV_ATTR );
137 LookupAttr( Pool & pool, SolvAttr attr_r, SolvAttr parent_r, Location = SOLV_ATTR );
138
140 LookupAttr( SolvAttr attr_r, Repository repo_r, Location = SOLV_ATTR );
142 LookupAttr( SolvAttr attr_r, SolvAttr parent_r, Repository repo_r, Location = SOLV_ATTR );
143
145 LookupAttr( SolvAttr attr_r, Solvable solv_r );
147 LookupAttr( SolvAttr attr_r, SolvAttr parent_r, Solvable solv_r );
148
149 public:
152
153 class iterator;
154
156 iterator begin() const;
157
159 iterator end() const;
160
162 bool empty() const;
163
167 size_type size() const;
168
170 template<class TResult, class TAttr = TResult>
173
174 public:
177
178 SolvAttr attr() const;
179
181 void setAttr( SolvAttr attr_r );
183
186
195 const StrMatcher & strMatcher() const;
196
200 void setStrMatcher( const StrMatcher & matcher_r );
201
205
206 public:
209
210 bool pool() const;
211
213 void setPool(Location = SOLV_ATTR );
214
216 Repository repo() const;
217
219 void setRepo( Repository repo_r, Location = SOLV_ATTR );
220
222 Solvable solvable() const;
223
225 void setSolvable( Solvable solv_r );
226
228 SolvAttr parent() const;
229
231 void setParent( SolvAttr attr_r );
233
234 private:
235 class Impl;
237 };
238
257 {
258 public:
262
263 explicit LookupRepoAttr( Pool & pool, SolvAttr attr_r )
264 : LookupAttr( pool, std::move(attr_r), REPO_ATTR )
265 {}
266
267 explicit LookupRepoAttr( SolvAttr attr_r, Repository repo_r );
268
269 public:
273
274 void setRepo( Repository repo_r );
275 private:
276 // Hide. You can't look inside and outside Solvables at the same time.
279 };
280
281 namespace detail
282 {
291 class DIWrap
292 {
293 public:
296 : _dip( 0 )
297 , _pool( 0 )
298 {}
299
300 DIWrap( detail::CPool * pool, RepoIdType repoId_r, SolvableIdType solvId_r, IdType attrId_r,
301 std::string mstring_r = std::string(), int flags_r = 0 );
303 DIWrap( detail::CPool * pool, RepoIdType repoId_r, SolvableIdType solvId_r, IdType attrId_r,
304 const char * mstring_r, int flags_r = 0 );
305 DIWrap( const DIWrap & rhs );
306 ~DIWrap();
307 public:
308 void swap( DIWrap & rhs ) noexcept
309 {
310 if ( &rhs != this ) // prevent self assign!
311 {
312 std::swap( _dip, rhs._dip );
313 std::swap( _pool, rhs._pool );
314 std::swap( _mstring, rhs._mstring );
315 }
316 }
317 DIWrap & operator=( const DIWrap & rhs )
318 {
319 if ( &rhs != this ) // prevent self assign!
320 DIWrap( rhs ).swap( *this );
321 return *this;
322 }
323 void reset()
324 { DIWrap().swap( *this ); }
325 public:
327 explicit operator bool() const
328 { return _dip; }
329
330 public:
332 detail::CDataiterator * get() const { return _dip; }
333 detail::CPool * pool() const { return _pool; }
334 const std::string & getstr() const { return _mstring; }
335
336 private:
339 std::string _mstring;
340 };
341 }
342
348 {
349 public:
350 using iterator_category = std::forward_iterator_tag;
352 using difference_type = std::ptrdiff_t;
353 using pointer = void;
355
358
359 void nextSkipSolvAttr();
360
362 void nextSkipSolvable();
363
365 void nextSkipRepo();
366
370
374
376 void skipRepo()
377 { nextSkipRepo(); increment(); }
378
380 void stayInThisSolvable();
381
383 void stayInThisRepo();
385
388
389 Repository inRepo() const;
390
392 Solvable inSolvable() const;
393
395 SolvAttr inSolvAttr() const;
396
398 bool atEnd() const
399 { return !_dip; }
400
401
404
405 detail::IdType solvAttrType() const;
406
408 bool solvAttrNumeric() const;
409
411 bool solvAttrString() const;
412
414 bool solvAttrIdString() const;
415
417 bool solvAttrCheckSum() const;
418
423 bool solvAttrSubEntry() const;
425
457
458 bool subEmpty() const;
459
463 size_type subSize() const;
464
468 iterator subBegin() const;
472 iterator subEnd() const;
477 iterator subFind( const SolvAttr& attr_r ) const;
485 iterator subFind( const zypp::C_Str & attrname_r ) const;
487
490
491 int asInt() const;
493 unsigned asUnsigned() const;
495 bool asBool() const;
497 unsigned long long asUnsignedLL() const;
498
500 const char * c_str() const;
505 std::string asString() const;
506
512 IdString idStr() const;
515 { return idStr().id(); }
516
518 CheckSum asCheckSum() const;
519
526 template<class Tp> Tp asType() const { return Tp(id()); }
528
529 public:
530 iterator();
531
532 iterator( const iterator & rhs );
533
534 iterator & operator=( const iterator & rhs );
535
536 ~iterator();
537
538 public:
543 iterator( detail::DIWrap & dip_r );
544
545 reference operator*() const;
546 iterator& operator++();
547 iterator operator++(int);
548
549 bool operator==( const iterator & rhs ) const;
550 bool operator!=( const iterator & rhs ) const
551 { return !(*this == rhs); }
552
553 private:
554 bool dip_equal( const detail::CDataiterator & lhs, const detail::CDataiterator & rhs ) const;
555 void increment();
556
557 public:
560 { return _dip.get(); }
561 private:
563 };
564
567 template<> inline int LookupAttr::iterator::asType<int>() const { return asInt(); }
568 template<> inline unsigned LookupAttr::iterator::asType<unsigned>() const { return asUnsigned(); }
569 template<> inline unsigned long long LookupAttr::iterator::asType<unsigned long long>() const { return asUnsignedLL(); }
570 template<> inline bool LookupAttr::iterator::asType<bool>() const { return asBool(); }
571 template<> inline const char * LookupAttr::iterator::asType<const char *>() const { return c_str(); }
572 template<> inline std::string LookupAttr::iterator::asType<std::string>() const { return asString(); }
573 template<> inline IdString LookupAttr::iterator::asType<IdString>() const { return idStr(); }
575
576 template<class TResult, class TAttr>
579
580} // namespace zyppng::sat
581
582#endif // ZYPPNG_SAT_LOOKUPATTR_H
Provides API related macros.
Convenience char* constructible from std::string and char*, it maps (char*)0 to an empty string.
Definition String.h:92
Access to the sat-pools string space.
Definition IdString.h:55
String matching option flags as used e.g.
Definition StrMatcher.h:33
String matching (STRING|SUBSTRING|GLOB|REGEX).
Definition StrMatcher.h:298
unsigned long long asUnsignedLL() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
unsigned asUnsigned() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Tp asType() const
Templated return type.
Definition LookupAttr.h:535
IdString idStr() const
As IdStr.
bool asBool() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
const char * c_str() const
Conversion to string types.
int asInt() const
Conversion to numeric types.
Solvable attribute keys.
Definition SolvAttr.h:41
LookupAttr implementation.
Definition lookupattr.cc:47
TransformIterator returning an iterator vaue of type TResult.
Definition lookupattr.h:171
void nextSkipRepo()
On the next call to operator++ advance to the next Repository.
void skipRepo()
Immediately advance to the next Repository.
Definition lookupattr.h:376
void skipSolvAttr()
Immediately advance to the next SolvAttr.
Definition lookupattr.h:368
Tp asType() const
Templated return type.
Definition lookupattr.h:526
std::forward_iterator_tag iterator_category
Definition lookupattr.h:350
void skipSolvable()
Immediately advance to the next Solvable.
Definition lookupattr.h:372
IdString idStr() const
As IdString.
void nextSkipSolvable()
On the next call to operator++ advance to the next Solvable.
void nextSkipSolvAttr()
On the next call to operator++ advance to the next SolvAttr.
bool operator!=(const iterator &rhs) const
Definition lookupattr.h:550
detail::CDataiterator * get() const
Expert backdoor.
Definition lookupattr.h:559
bool atEnd() const
Whether this points to the end of a query (Iterator is invalid).
Definition lookupattr.h:398
detail::IdType id() const
Definition lookupattr.h:514
Lightweight attribute value lookup.
Definition lookupattr.h:112
void setAttr(SolvAttr attr_r)
Set the SolvAttr to search.
SolvAttr parent() const
Whether to search within a sub-structure (SolvAttr::noAttr if not).
LookupAttr(LookupAttr &&) noexcept=default
void setPool(Location=SOLV_ATTR)
Set search in Pool (all repositories).
iterator end() const
Iterator behind the end of query results.
bool pool() const
Whether to search in Pool.
void setSolvable(Solvable solv_r)
Set search in one Solvable.
iterator begin() const
Iterator to the begin of query results.
void setParent(SolvAttr attr_r)
Set search within a sub-structure (SolvAttr::noAttr for none).
void resetStrMatcher()
Reset the pattern to match.
MatchException Exception
Definition lookupattr.h:114
LookupAttr & operator=(const LookupAttr &)=default
SolvAttr attr() const
The SolvAttr to search.
bool empty() const
Whether the query is empty.
LookupAttr(const LookupAttr &)=default
Location
Specify the where to look for the attribule.
Definition lookupattr.h:120
@ REPO_ATTR
Search for repository attributes.
Definition lookupattr.h:122
@ SOLV_ATTR
Search for solvable attributes (default).
Definition lookupattr.h:121
size_type size() const
Ammount of results.
const StrMatcher & strMatcher() const
The pattern to match.
LookupAttr()
Default ctor finds nothing.
Solvable solvable() const
Whether to search in one Solvable.
void setRepo(Repository repo_r, Location=SOLV_ATTR)
Set search in one Repository.
zypp::RWCOW_pointer< Impl > _pimpl
Definition lookupattr.h:236
Repository repo() const
Whether to search in one Repository.
void setStrMatcher(const StrMatcher &matcher_r)
Set the pattern to match.
Lightweight repository attribute value lookup.
Definition lookupattr.h:257
LookupRepoAttr()
Default ctor finds nothing.
Definition lookupattr.h:260
LookupRepoAttr(Pool &pool, SolvAttr attr_r)
Definition lookupattr.h:263
void setPool()
Set search in Pool (all repositories).
Definition lookupattr.h:271
Orchestrator for a libsolv pool instance.
Definition pool.h:37
A Solvable object within the sat Pool.
Definition solvable.h:65
Wrapper around sat detail::CDataiterator.
Definition lookupattr.h:292
detail::CDataiterator * get() const
Definition lookupattr.h:332
detail::CPool * pool() const
Definition lookupattr.h:333
DIWrap()
NULL detail::CDataiterator
Definition lookupattr.h:295
detail::CDataiterator * operator->() const
Definition lookupattr.h:331
void swap(DIWrap &rhs) noexcept
Definition lookupattr.h:308
DIWrap & operator=(const DIWrap &rhs)
Definition lookupattr.h:317
detail::CDataiterator * _dip
Definition lookupattr.h:337
const std::string & getstr() const
Definition lookupattr.h:334
Definition ansi.h:855
Easy-to use interface to the ZYPP dependency resolver.
const Arch Arch_empty ZYPP_API
relates: Arch This is an empty Arch represented by an empty string.
Definition Arch.h:173
std::string asString(const Patch::Category &obj)
relates: Patch::Category string representation.
Definition Patch.cc:122
zypp::sat::detail::CDataiterator CDataiterator
zypp::sat::detail::RepoIdType RepoIdType
zypp::sat::detail::CPool CPool
zypp::sat::detail::SolvableIdType SolvableIdType
zypp::sat::detail::IdType IdType
This file contains private API, this might break at any time between releases.
bool operator==(const Capability &lhs, const Capability &rhs)
relates: Capability
Definition capability.h:311
Exceptions thrown from attribute matching.
Definition StrMatcher.h:248
RW_pointer supporting 'copy on write' functionality.
Definition PtrTypes.h:469