libzypp: zypp/ng/sat/lookupattr.h Source File

libzypp 17.38.11

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
18#include <zypp-core/base/PtrTypes.h>
19#include <zypp-core/base/defaultintegral.h>
20#include <zypp-core/Globals.h>
21#include <zypp-core/ng/base/ranges.h>
22
23#include <zypp/ng/sat/solvattr.h>
24#include <zypp/ng/sat/solvable.h>
25#include <zypp/ng/sat/repository.h>
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
113 class LookupAttr
114 {
115 public:
116 using Exception = MatchException;
117
118 public:
119 using size_type = unsigned int;
120
122 enum Location {
123 SOLV_ATTR = 0,
124 REPO_ATTR = -1
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>
173 class TransformIterator;
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
205 void resetStrMatcher();
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;
238 zypp::RWCOW_pointer<Impl> _pimpl;
239 };
240
258 class LookupRepoAttr : public LookupAttr
259 {
260 public:
262 LookupRepoAttr()
263 {}
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:
273 void setPool( )
274 { LookupAttr::setPool( REPO_ATTR ); }
275
276 void setRepo( Repository repo_r );
277 private:
278 // Hide. You can't look inside and outside Solvables at the same time.
279 using LookupAttr::solvable;
280 using LookupAttr::setSolvable;
281 };
282
283 namespace detail
284 {
293 class DIWrap
294 {
295 public:
297 DIWrap()
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:
333 detail::CDataiterator * operator->() const { return _dip; }
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:
339 detail::CDataiterator * _dip;
340 detail::CPool * _pool;
341 std::string _mstring;
342 };
343 }
344
349 class LookupAttr::iterator
350 {
351 public:
352 using iterator_category = std::forward_iterator_tag;
353 using value_type = LookupAttrValue;
354 using difference_type = std::ptrdiff_t;
355 using pointer = void;
356 using reference = LookupAttrValue;
357
360
361 void nextSkipSolvAttr();
362
364 void nextSkipSolvable();
365
367 void nextSkipRepo();
368
370 void skipSolvAttr()
371 { nextSkipSolvAttr(); increment(); }
372
374 void skipSolvable()
375 { nextSkipSolvable(); increment(); }
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:
422 detail::CDataiterator * get() const
423 { return _dip.get(); }
424 private:
425 detail::DIWrap _dip;
426 };
427
430 template<class TResult, class TAttr>
431 class ArrayAttr;
433
434 template<class TResult, class TAttr>
435 class ArrayAttr;
437
438 // -----------------------------------------------------------------------
439
453 class LookupAttrValue
454 {
455 public:
456 using size_type = LookupAttr::size_type;
457
459 LookupAttrValue( detail::CDataiterator * dip, detail::CPool * pool )
460 : _dip( dip ), _pool( pool )
461 {}
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
575 detail::IdType id() const
576 { return idStr().id(); }
577
579 CheckSum asCheckSum() const;
580
587 template<class Tp> Tp asType() const { return Tp( id() ); }
589
590 private:
591 detail::CDataiterator * _dip;
592 detail::CPool * _pool;
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(); }
603 template<> CheckSum LookupAttrValue::asType<CheckSum>() const;
604
605} // namespace zyppng::sat
606
607#endif // ZYPPNG_SAT_LOOKUPATTR_H
Globals.h
Provides API related macros.
PtrTypes.h
bool
zypp::C_Str
Convenience char* constructible from std::string and char*, it maps (char*)0 to an empty string.
Definition String.h:92
zypp::CheckSum
Definition CheckSum.h:34
zypp::IdString
Access to the sat-pools string space.
Definition IdString.h:55
zypp::Match
String matching option flags as used e.g.
Definition StrMatcher.h:33
zypp::StrMatcher
String matching (STRING|SUBSTRING|GLOB|REGEX).
Definition StrMatcher.h:298
zypp::sat::SolvAttr
Solvable attribute keys.
Definition SolvAttr.h:41
zyppng::sat::ArrayAttr
Definition lookupattr.h:431
zyppng::sat::LookupAttrValue
Value proxy returned by LookupAttr::iterator::operator*().
Definition lookupattr.h:454
zyppng::sat::LookupAttrValue::id
detail::IdType id() const
Definition lookupattr.h:575
zyppng::sat::LookupAttrValue::asUnsigned
unsigned asUnsigned() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition lookupattr.cc:523
zyppng::sat::LookupAttrValue::LookupAttrValue
LookupAttrValue(detail::CDataiterator *dip, detail::CPool *pool)
Definition lookupattr.h:459
zyppng::sat::LookupAttrValue::asInt
int asInt() const
Conversion to numeric types.
Definition lookupattr.cc:508
zyppng::sat::LookupAttrValue::size_type
LookupAttr::size_type size_type
Definition lookupattr.h:456
zyppng::sat::LookupAttrValue::_dip
detail::CDataiterator * _dip
non-owning — current iterator position
Definition lookupattr.h:591
zyppng::sat::LookupAttrValue::idStr
IdString idStr() const
As IdString.
Definition lookupattr.cc:629
zyppng::sat::LookupAttrValue::asType
Tp asType() const
Templated return type.
Definition lookupattr.h:587
zyppng::sat::LookupAttrValue::asBool
bool asBool() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition lookupattr.cc:541
zyppng::sat::LookupAttrValue::asUnsignedLL
unsigned long long asUnsignedLL() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition lookupattr.cc:526
zyppng::sat::LookupAttrValue::_pool
detail::CPool * _pool
non-owning — needed for sub-structure DIWrap construction
Definition lookupattr.h:592
zyppng::sat::LookupAttrValue::c_str
const char * c_str() const
Conversion to string types.
Definition lookupattr.cc:545
zyppng::sat::LookupAttr::Impl
LookupAttr implementation.
Definition lookupattr.cc:47
zyppng::sat::LookupAttr::TransformIterator
TransformIterator returning an iterator vaue of type TResult.
Definition lookupattr.h:173
zyppng::sat::LookupAttr::iterator
Result iterator.
Definition lookupattr.h:350
zyppng::sat::LookupAttr::iterator::nextSkipRepo
void nextSkipRepo()
On the next call to operator++ advance to the next Repository.
Definition lookupattr.cc:336
zyppng::sat::LookupAttr::iterator::skipRepo
void skipRepo()
Immediately advance to the next Repository.
Definition lookupattr.h:378
zyppng::sat::LookupAttr::iterator::skipSolvAttr
void skipSolvAttr()
Immediately advance to the next SolvAttr.
Definition lookupattr.h:370
zyppng::sat::LookupAttr::iterator::iterator_category
std::forward_iterator_tag iterator_category
Definition lookupattr.h:352
zyppng::sat::LookupAttr::iterator::iterator
iterator()
Definition lookupattr.cc:679
zyppng::sat::LookupAttr::iterator::skipSolvable
void skipSolvable()
Immediately advance to the next Solvable.
Definition lookupattr.h:374
zyppng::sat::LookupAttr::iterator::reference
LookupAttrValue reference
Definition lookupattr.h:356
zyppng::sat::LookupAttr::iterator::_dip
detail::DIWrap _dip
Definition lookupattr.h:425
zyppng::sat::LookupAttr::iterator::nextSkipSolvable
void nextSkipSolvable()
On the next call to operator++ advance to the next Solvable.
Definition lookupattr.cc:333
zyppng::sat::LookupAttr::iterator::nextSkipSolvAttr
void nextSkipSolvAttr()
On the next call to operator++ advance to the next SolvAttr.
Definition lookupattr.cc:330
zyppng::sat::LookupAttr::iterator::value_type
LookupAttrValue value_type
Definition lookupattr.h:353
zyppng::sat::LookupAttr::iterator::pointer
void pointer
proxy type — no stable address
Definition lookupattr.h:355
zyppng::sat::LookupAttr::iterator::difference_type
std::ptrdiff_t difference_type
Definition lookupattr.h:354
zyppng::sat::LookupAttr::iterator::operator!=
bool operator!=(const iterator &rhs) const
Definition lookupattr.h:413
zyppng::sat::LookupAttr::iterator::get
detail::CDataiterator * get() const
Expert backdoor.
Definition lookupattr.h:422
zyppng::sat::LookupAttr::iterator::increment
void increment()
Definition lookupattr.cc:735
zyppng::sat::LookupAttr::iterator::atEnd
bool atEnd() const
Whether this points to the end of a query (iterator is invalid).
Definition lookupattr.h:389
zyppng::sat::LookupAttr::setAttr
void setAttr(SolvAttr attr_r)
Set the SolvAttr to search.
Definition lookupattr.cc:207
zyppng::sat::LookupAttr::parent
SolvAttr parent() const
Whether to search within a sub-structure (SolvAttr::noAttr if not).
Definition lookupattr.cc:234
zyppng::sat::LookupAttr::LookupAttr
LookupAttr(LookupAttr &&) noexcept=default
zyppng::sat::LookupAttr::setPool
void setPool(Location=SOLV_ATTR)
Set search in Pool (all repositories).
Definition lookupattr.cc:219
zyppng::sat::LookupAttr::end
iterator end() const
Iterator behind the end of query results.
Definition lookupattr.cc:243
zyppng::sat::LookupAttr::pool
bool pool() const
Whether to search in Pool.
Definition lookupattr.cc:216
zyppng::sat::LookupAttr::setSolvable
void setSolvable(Solvable solv_r)
Set search in one Solvable.
Definition lookupattr.cc:231
zyppng::sat::LookupAttr::begin
iterator begin() const
Iterator to the begin of query results.
Definition lookupattr.cc:240
zyppng::sat::LookupAttr::setParent
void setParent(SolvAttr attr_r)
Set search within a sub-structure (SolvAttr::noAttr for none).
Definition lookupattr.cc:237
zyppng::sat::LookupAttr::resetStrMatcher
void resetStrMatcher()
Reset the pattern to match.
zyppng::sat::LookupAttr::Exception
MatchException Exception
Definition lookupattr.h:116
zyppng::sat::LookupAttr::operator=
LookupAttr & operator=(const LookupAttr &)=default
zyppng::sat::LookupAttr::attr
SolvAttr attr() const
The SolvAttr to search.
Definition lookupattr.cc:204
zyppng::sat::LookupAttr::size_type
unsigned int size_type
Definition lookupattr.h:119
zyppng::sat::LookupAttr::empty
bool empty() const
Whether the query is empty.
Definition lookupattr.cc:246
zyppng::sat::LookupAttr::LookupAttr
LookupAttr(const LookupAttr &)=default
zyppng::sat::LookupAttr::Location
Location
Specify the where to look for the attribule.
Definition lookupattr.h:122
zyppng::sat::LookupAttr::REPO_ATTR
@ REPO_ATTR
Search for repository attributes.
Definition lookupattr.h:124
zyppng::sat::LookupAttr::SOLV_ATTR
@ SOLV_ATTR
Search for solvable attributes (default).
Definition lookupattr.h:123
zyppng::sat::LookupAttr::size
size_type size() const
Ammount of results.
Definition lookupattr.cc:249
zyppng::sat::LookupAttr::strMatcher
const StrMatcher & strMatcher() const
The pattern to match.
Definition lookupattr.cc:210
zyppng::sat::LookupAttr::LookupAttr
LookupAttr()
Default ctor finds nothing.
Definition lookupattr.cc:165
zyppng::sat::LookupAttr::solvable
Solvable solvable() const
Whether to search in one Solvable.
Definition lookupattr.cc:228
zyppng::sat::LookupAttr::setRepo
void setRepo(Repository repo_r, Location=SOLV_ATTR)
Set search in one Repository.
Definition lookupattr.cc:225
zyppng::sat::LookupAttr::_pimpl
zypp::RWCOW_pointer< Impl > _pimpl
Definition lookupattr.h:238
zyppng::sat::LookupAttr::repo
Repository repo() const
Whether to search in one Repository.
Definition lookupattr.cc:222
zyppng::sat::LookupAttr::setStrMatcher
void setStrMatcher(const StrMatcher &matcher_r)
Set the pattern to match.
Definition lookupattr.cc:213
zyppng::sat::LookupRepoAttr
Lightweight repository attribute value lookup.
Definition lookupattr.h:259
zyppng::sat::LookupRepoAttr::LookupRepoAttr
LookupRepoAttr()
Default ctor finds nothing.
Definition lookupattr.h:262
zyppng::sat::LookupRepoAttr::LookupRepoAttr
LookupRepoAttr(Pool &pool, SolvAttr attr_r)
Definition lookupattr.h:265
zyppng::sat::LookupRepoAttr::setPool
void setPool()
Set search in Pool (all repositories).
Definition lookupattr.h:273
zyppng::sat::Pool
Orchestrator for a libsolv pool instance.
Definition pool.h:37
zyppng::sat::Repository
Definition repository.h:51
zyppng::sat::Solvable
A Solvable object within the sat Pool.
Definition solvable.h:66
zyppng::sat::detail::DIWrap
Wrapper around sat detail::CDataiterator.
Definition lookupattr.h:294
zyppng::sat::detail::DIWrap::get
detail::CDataiterator * get() const
Definition lookupattr.h:334
zyppng::sat::detail::DIWrap::pool
detail::CPool * pool() const
Definition lookupattr.h:335
zyppng::sat::detail::DIWrap::DIWrap
DIWrap()
NULL detail::CDataiterator
Definition lookupattr.h:297
zyppng::sat::detail::DIWrap::_mstring
std::string _mstring
Definition lookupattr.h:341
zyppng::sat::detail::DIWrap::operator->
detail::CDataiterator * operator->() const
Definition lookupattr.h:333
zyppng::sat::detail::DIWrap::_pool
detail::CPool * _pool
Definition lookupattr.h:340
zyppng::sat::detail::DIWrap::swap
void swap(DIWrap &rhs) noexcept
Definition lookupattr.h:310
zyppng::sat::detail::DIWrap::operator=
DIWrap & operator=(const DIWrap &rhs)
Definition lookupattr.h:319
zyppng::sat::detail::DIWrap::_dip
detail::CDataiterator * _dip
Definition lookupattr.h:339
zyppng::sat::detail::DIWrap::reset
void reset()
Definition lookupattr.h:325
zyppng::sat::detail::DIWrap::getstr
const std::string & getstr() const
Definition lookupattr.h:336
defaultintegral.h
std
Definition ansi.h:855
zypp::pool
Definition ByIdent.h:24
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
zypp::asString
std::string asString(const Patch::Category &obj)
relates: Patch::Category string representation.
Definition Patch.cc:122
zyppng::detail
Definition reporthelper.h:31
zyppng::sat::detail::CDataiterator
zypp::sat::detail::CDataiterator CDataiterator
Definition poolconstants.h:33
zyppng::sat::detail::RepoIdType
zypp::sat::detail::RepoIdType RepoIdType
Definition poolconstants.h:45
zyppng::sat::detail::CPool
zypp::sat::detail::CPool CPool
Definition poolconstants.h:36
zyppng::sat::detail::SolvableIdType
zypp::sat::detail::SolvableIdType SolvableIdType
Definition poolconstants.h:44
zyppng::sat::detail::IdType
zypp::sat::detail::IdType IdType
Definition poolconstants.h:43
zyppng::sat
This file contains private API, this might break at any time between releases.
Definition capabilities.h:22
zyppng::sat::operator==
bool operator==(const Capability &lhs, const Capability &rhs)
relates: Capability
Definition capability.h:311
ranges.h
Namespace routing for C++20 ranges and C++23 ranges::to<T>() backport.
repository.h
solvable.h
solvattr.h
zypp::MatchException
Exceptions thrown from attribute matching.
Definition StrMatcher.h:248
zypp::RWCOW_pointer
RW_pointer supporting 'copy on write' functionality.
Definition PtrTypes.h:469
idstring.h