libzypp 17.38.8
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>
22
26#include <zypp/ng/idstring.h>
27
28namespace zypp
29{
30 class CheckSum;
31 class Match;
32 struct MatchException;
33 class StrMatcher;
34}
35
36namespace zyppng::sat
37{
38 class Pool;
39 class LookupAttrValue;
40
41 using zypp::MatchException;
42 using zypp::StrMatcher;
43 using zypp::CheckSum;
44
114 {
115 public:
117
118 public:
119 using size_type = unsigned int;
120
122 enum Location {
125 };
126
127 public:
129 LookupAttr();
130
131 LookupAttr(const LookupAttr &) = default;
132 LookupAttr(LookupAttr &&) noexcept = default;
133 LookupAttr &operator=(const LookupAttr &) = default;
134 LookupAttr &operator=(LookupAttr &&) noexcept = default;
135
137 explicit LookupAttr( Pool & pool, SolvAttr attr_r, Location = SOLV_ATTR );
139 LookupAttr( Pool & pool, SolvAttr attr_r, SolvAttr parent_r, Location = SOLV_ATTR );
140
142 LookupAttr( SolvAttr attr_r, Repository repo_r, Location = SOLV_ATTR );
144 LookupAttr( SolvAttr attr_r, SolvAttr parent_r, Repository repo_r, Location = SOLV_ATTR );
145
147 LookupAttr( SolvAttr attr_r, Solvable solv_r );
149 LookupAttr( SolvAttr attr_r, SolvAttr parent_r, Solvable solv_r );
150
151 public:
154
155 class iterator;
156
158 iterator begin() const;
159
161 iterator end() const;
162
164 bool empty() const;
165
169 size_type size() const;
170
172 template<class TResult, class TAttr = TResult>
175
176 public:
179
180 SolvAttr attr() const;
181
183 void setAttr( SolvAttr attr_r );
185
188
197 const StrMatcher & strMatcher() const;
198
202 void setStrMatcher( const StrMatcher & matcher_r );
203
207
208 public:
211
212 bool pool() const;
213
215 void setPool(Location = SOLV_ATTR );
216
218 Repository repo() const;
219
221 void setRepo( Repository repo_r, Location = SOLV_ATTR );
222
224 Solvable solvable() const;
225
227 void setSolvable( Solvable solv_r );
228
230 SolvAttr parent() const;
231
233 void setParent( SolvAttr attr_r );
235
236 private:
237 class Impl;
239 };
240
259 {
260 public:
264
265 explicit LookupRepoAttr( Pool & pool, SolvAttr attr_r )
266 : LookupAttr( pool, std::move(attr_r), REPO_ATTR )
267 {}
268
269 explicit LookupRepoAttr( SolvAttr attr_r, Repository repo_r );
270
271 public:
275
276 void setRepo( Repository repo_r );
277 private:
278 // Hide. You can't look inside and outside Solvables at the same time.
281 };
282
283 namespace detail
284 {
293 class DIWrap
294 {
295 public:
298 : _dip( 0 )
299 , _pool( 0 )
300 {}
301
302 DIWrap( detail::CPool * pool, RepoIdType repoId_r, SolvableIdType solvId_r, IdType attrId_r,
303 std::string mstring_r = std::string(), int flags_r = 0 );
305 DIWrap( detail::CPool * pool, RepoIdType repoId_r, SolvableIdType solvId_r, IdType attrId_r,
306 const char * mstring_r, int flags_r = 0 );
307 DIWrap( const DIWrap & rhs );
308 ~DIWrap();
309 public:
310 void swap( DIWrap & rhs ) noexcept
311 {
312 if ( &rhs != this ) // prevent self assign!
313 {
314 std::swap( _dip, rhs._dip );
315 std::swap( _pool, rhs._pool );
316 std::swap( _mstring, rhs._mstring );
317 }
318 }
319 DIWrap & operator=( const DIWrap & rhs )
320 {
321 if ( &rhs != this ) // prevent self assign!
322 DIWrap( rhs ).swap( *this );
323 return *this;
324 }
325 void reset()
326 { DIWrap().swap( *this ); }
327 public:
329 explicit operator bool() const
330 { return _dip; }
331
332 public:
334 detail::CDataiterator * get() const { return _dip; }
335 detail::CPool * pool() const { return _pool; }
336 const std::string & getstr() const { return _mstring; }
337
338 private:
341 std::string _mstring;
342 };
343 }
344
350 {
351 public:
352 using iterator_category = std::forward_iterator_tag;
354 using difference_type = std::ptrdiff_t;
355 using pointer = void;
357
360
361 void nextSkipSolvAttr();
362
364 void nextSkipSolvable();
365
367 void nextSkipRepo();
368
372
376
378 void skipRepo()
379 { nextSkipRepo(); increment(); }
380
382 void stayInThisSolvable();
383
385 void stayInThisRepo();
387
389 bool atEnd() const
390 { return !_dip; }
391
392 public:
393 iterator();
394
395 iterator( const iterator & rhs );
396
397 iterator & operator=( const iterator & rhs );
398
399 ~iterator();
400
401 public:
406 iterator( detail::DIWrap & dip_r );
407
408 reference operator*() const;
409 iterator& operator++();
410 iterator operator++(int);
411
412 bool operator==( const iterator & rhs ) const;
413 bool operator!=( const iterator & rhs ) const
414 { return !(*this == rhs); }
415
416 private:
417 bool dip_equal( const detail::CDataiterator & lhs, const detail::CDataiterator & rhs ) const;
418 void increment();
419
420 public:
423 { return _dip.get(); }
424 private:
426 };
427
430 template<class TResult, class TAttr>
433
434 template<class TResult, class TAttr>
435 class ArrayAttr;
437
438 // -----------------------------------------------------------------------
439
454 {
455 public:
457
462
463 public:
466
467 Repository inRepo() const;
468
470 Solvable inSolvable() const;
471
473 SolvAttr inSolvAttr() const;
475
478
479 detail::IdType solvAttrType() const;
480
482 bool solvAttrNumeric() const;
483
485 bool solvAttrString() const;
486
488 bool solvAttrIdString() const;
489
491 bool solvAttrCheckSum() const;
492
497 bool solvAttrSubEntry() const;
499
513
514 bool subEmpty() const;
515
519 size_type subSize() const;
520
524 LookupAttr::iterator subBegin() const;
525
529 LookupAttr::iterator subEnd() const;
530
536 LookupAttr::iterator subFind( const SolvAttr & attr_r ) const;
537
545 LookupAttr::iterator subFind( const zypp::C_Str & attrname_r ) const;
547
550
551 int asInt() const;
553 unsigned asUnsigned() const;
555 bool asBool() const;
557 unsigned long long asUnsignedLL() const;
558
560 const char * c_str() const;
565 std::string asString() const;
566
572 IdString idStr() const;
573
576 { return idStr().id(); }
577
579 CheckSum asCheckSum() const;
580
587 template<class Tp> Tp asType() const { return Tp( id() ); }
589
590 private:
593 };
594
595 // asType<> specialisations for LookupAttrValue (mirrors those on iterator)
596 template<> inline int LookupAttrValue::asType<int>() const { return asInt(); }
597 template<> inline unsigned LookupAttrValue::asType<unsigned>() const { return asUnsigned(); }
598 template<> inline unsigned long long LookupAttrValue::asType<unsigned long long>()const { return asUnsignedLL(); }
599 template<> inline bool LookupAttrValue::asType<bool>() const { return asBool(); }
600 template<> inline const char * LookupAttrValue::asType<const char *>() const { return c_str(); }
601 template<> inline std::string LookupAttrValue::asType<std::string>() const { return asString(); }
602 template<> inline IdString LookupAttrValue::asType<IdString>() const { return idStr(); }
604
605} // namespace zyppng::sat
606
607#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
Solvable attribute keys.
Definition SolvAttr.h:41
Value proxy returned by LookupAttr::iterator::operator*().
Definition lookupattr.h:454
detail::IdType id() const
Definition lookupattr.h:575
unsigned asUnsigned() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
LookupAttrValue(detail::CDataiterator *dip, detail::CPool *pool)
Definition lookupattr.h:459
int asInt() const
Conversion to numeric types.
LookupAttr::size_type size_type
Definition lookupattr.h:456
detail::CDataiterator * _dip
non-owning — current iterator position
Definition lookupattr.h:591
IdString idStr() const
As IdString.
Tp asType() const
Templated return type.
Definition lookupattr.h:587
bool asBool() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
unsigned long long asUnsignedLL() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
detail::CPool * _pool
non-owning — needed for sub-structure DIWrap construction
Definition lookupattr.h:592
const char * c_str() const
Conversion to string types.
LookupAttr implementation.
Definition lookupattr.cc:47
TransformIterator returning an iterator vaue of type TResult.
Definition lookupattr.h:173
void nextSkipRepo()
On the next call to operator++ advance to the next Repository.
void skipRepo()
Immediately advance to the next Repository.
Definition lookupattr.h:378
void skipSolvAttr()
Immediately advance to the next SolvAttr.
Definition lookupattr.h:370
std::forward_iterator_tag iterator_category
Definition lookupattr.h:352
void skipSolvable()
Immediately advance to the next Solvable.
Definition lookupattr.h:374
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.
void pointer
proxy type — no stable address
Definition lookupattr.h:355
bool operator!=(const iterator &rhs) const
Definition lookupattr.h:413
detail::CDataiterator * get() const
Expert backdoor.
Definition lookupattr.h:422
bool atEnd() const
Whether this points to the end of a query (iterator is invalid).
Definition lookupattr.h:389
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:116
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:122
@ REPO_ATTR
Search for repository attributes.
Definition lookupattr.h:124
@ SOLV_ATTR
Search for solvable attributes (default).
Definition lookupattr.h:123
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:238
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:259
LookupRepoAttr()
Default ctor finds nothing.
Definition lookupattr.h:262
LookupRepoAttr(Pool &pool, SolvAttr attr_r)
Definition lookupattr.h:265
void setPool()
Set search in Pool (all repositories).
Definition lookupattr.h:273
Orchestrator for a libsolv pool instance.
Definition pool.h:37
A Solvable object within the sat Pool.
Definition solvable.h:66
Wrapper around sat detail::CDataiterator.
Definition lookupattr.h:294
detail::CDataiterator * get() const
Definition lookupattr.h:334
detail::CPool * pool() const
Definition lookupattr.h:335
DIWrap()
NULL detail::CDataiterator
Definition lookupattr.h:297
detail::CDataiterator * operator->() const
Definition lookupattr.h:333
void swap(DIWrap &rhs) noexcept
Definition lookupattr.h:310
DIWrap & operator=(const DIWrap &rhs)
Definition lookupattr.h:319
detail::CDataiterator * _dip
Definition lookupattr.h:339
const std::string & getstr() const
Definition lookupattr.h:336
Definition ansi.h:855
Easy-to use interface to the ZYPP dependency resolver.
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
Namespace routing for C++20 ranges and C++23 ranges::to<T>() backport.
Exceptions thrown from attribute matching.
Definition StrMatcher.h:248
RW_pointer supporting 'copy on write' functionality.
Definition PtrTypes.h:469