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

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
18#include <zypp-core/base/PtrTypes.h>
19#include <zypp-core/base/defaultintegral.h>
20#include <zypp-core/Globals.h>
21
22#include <zypp/ng/sat/solvattr.h>
23#include <zypp/ng/sat/solvable.h>
24#include <zypp/ng/sat/repository.h>
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
111 class ZYPP_API LookupAttr
112 {
113 public:
114 using Exception = MatchException;
115
116 public:
117 using size_type = unsigned int;
118
120 enum Location {
121 SOLV_ATTR = 0,
122 REPO_ATTR = -1
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>
171 class TransformIterator;
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
203 void resetStrMatcher();
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;
236 zypp::RWCOW_pointer<Impl> _pimpl;
237 };
238
256 class LookupRepoAttr : public LookupAttr
257 {
258 public:
260 LookupRepoAttr()
261 {}
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:
271 void setPool( )
272 { LookupAttr::setPool( REPO_ATTR ); }
273
274 void setRepo( Repository repo_r );
275 private:
276 // Hide. You can't look inside and outside Solvables at the same time.
277 using LookupAttr::solvable;
278 using LookupAttr::setSolvable;
279 };
280
281 namespace detail
282 {
291 class DIWrap
292 {
293 public:
295 DIWrap()
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:
331 detail::CDataiterator * operator->() const { return _dip; }
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:
337 detail::CDataiterator * _dip;
338 detail::CPool * _pool;
339 std::string _mstring;
340 };
341 }
342
347 class LookupAttr::iterator
348 {
349 public:
350 using iterator_category = std::forward_iterator_tag;
351 using value_type = detail::IdType;
352 using difference_type = std::ptrdiff_t;
353 using pointer = void;
354 using reference = detail::IdType;
355
358
359 void nextSkipSolvAttr();
360
362 void nextSkipSolvable();
363
365 void nextSkipRepo();
366
368 void skipSolvAttr()
369 { nextSkipSolvAttr(); increment(); }
370
372 void skipSolvable()
373 { nextSkipSolvable(); increment(); }
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;
514 detail::IdType id() 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:
559 detail::CDataiterator * get() const
560 { return _dip.get(); }
561 private:
562 detail::DIWrap _dip;
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(); }
574 template<> CheckSum LookupAttr::iterator::asType<CheckSum>() const;
575
576 template<class TResult, class TAttr>
577 class ArrayAttr;
579
580} // namespace zyppng::sat
581
582#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::LookupAttr::iterator::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:562
zypp::sat::LookupAttr::iterator::asUnsigned
unsigned asUnsigned() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition LookupAttr.cc:559
zypp::sat::LookupAttr::iterator::asType
Tp asType() const
Templated return type.
Definition LookupAttr.h:535
zypp::sat::LookupAttr::iterator::idStr
IdString idStr() const
As IdStr.
Definition LookupAttr.cc:665
zypp::sat::LookupAttr::iterator::asBool
bool asBool() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition LookupAttr.cc:577
zypp::sat::LookupAttr::iterator::c_str
const char * c_str() const
Conversion to string types.
Definition LookupAttr.cc:581
zypp::sat::LookupAttr::iterator::asInt
int asInt() const
Conversion to numeric types.
Definition LookupAttr.cc:544
zypp::sat::SolvAttr
Solvable attribute keys.
Definition SolvAttr.h:41
zyppng::sat::ArrayAttr
Definition lookupattr.h:577
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:171
zyppng::sat::LookupAttr::iterator
Result iterator.
Definition lookupattr.h:348
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:376
zyppng::sat::LookupAttr::iterator::reference
detail::IdType reference
Definition lookupattr.h:354
zyppng::sat::LookupAttr::iterator::skipSolvAttr
void skipSolvAttr()
Immediately advance to the next SolvAttr.
Definition lookupattr.h:368
zyppng::sat::LookupAttr::iterator::asType
Tp asType() const
Templated return type.
Definition lookupattr.h:526
zyppng::sat::LookupAttr::iterator::iterator_category
std::forward_iterator_tag iterator_category
Definition lookupattr.h:350
zyppng::sat::LookupAttr::iterator::iterator
iterator()
Definition lookupattr.cc:670
zyppng::sat::LookupAttr::iterator::skipSolvable
void skipSolvable()
Immediately advance to the next Solvable.
Definition lookupattr.h:372
zyppng::sat::LookupAttr::iterator::idStr
IdString idStr() const
As IdString.
Definition lookupattr.cc:620
zyppng::sat::LookupAttr::iterator::_dip
detail::DIWrap _dip
Definition lookupattr.h:562
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::pointer
void pointer
Definition lookupattr.h:353
zyppng::sat::LookupAttr::iterator::difference_type
std::ptrdiff_t difference_type
Definition lookupattr.h:352
zyppng::sat::LookupAttr::iterator::operator!=
bool operator!=(const iterator &rhs) const
Definition lookupattr.h:550
zyppng::sat::LookupAttr::iterator::get
detail::CDataiterator * get() const
Expert backdoor.
Definition lookupattr.h:559
zyppng::sat::LookupAttr::iterator::increment
void increment()
Definition lookupattr.cc:727
zyppng::sat::LookupAttr::iterator::atEnd
bool atEnd() const
Whether this points to the end of a query (Iterator is invalid).
Definition lookupattr.h:398
zyppng::sat::LookupAttr::iterator::id
detail::IdType id() const
Definition lookupattr.h:514
zyppng::sat::LookupAttr::iterator::value_type
detail::IdType value_type
Definition lookupattr.h:351
zyppng::sat::LookupAttr
Lightweight attribute value lookup.
Definition lookupattr.h:112
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:114
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:117
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:120
zyppng::sat::LookupAttr::REPO_ATTR
@ REPO_ATTR
Search for repository attributes.
Definition lookupattr.h:122
zyppng::sat::LookupAttr::SOLV_ATTR
@ SOLV_ATTR
Search for solvable attributes (default).
Definition lookupattr.h:121
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:236
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:257
zyppng::sat::LookupRepoAttr::LookupRepoAttr
LookupRepoAttr()
Default ctor finds nothing.
Definition lookupattr.h:260
zyppng::sat::LookupRepoAttr::LookupRepoAttr
LookupRepoAttr(Pool &pool, SolvAttr attr_r)
Definition lookupattr.h:263
zyppng::sat::LookupRepoAttr::setPool
void setPool()
Set search in Pool (all repositories).
Definition lookupattr.h:271
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:65
zyppng::sat::detail::DIWrap
Wrapper around sat detail::CDataiterator.
Definition lookupattr.h:292
zyppng::sat::detail::DIWrap::get
detail::CDataiterator * get() const
Definition lookupattr.h:332
zyppng::sat::detail::DIWrap::pool
detail::CPool * pool() const
Definition lookupattr.h:333
zyppng::sat::detail::DIWrap::DIWrap
DIWrap()
NULL detail::CDataiterator
Definition lookupattr.h:295
zyppng::sat::detail::DIWrap::_mstring
std::string _mstring
Definition lookupattr.h:339
zyppng::sat::detail::DIWrap::operator->
detail::CDataiterator * operator->() const
Definition lookupattr.h:331
zyppng::sat::detail::DIWrap::_pool
detail::CPool * _pool
Definition lookupattr.h:338
zyppng::sat::detail::DIWrap::swap
void swap(DIWrap &rhs) noexcept
Definition lookupattr.h:308
zyppng::sat::detail::DIWrap::operator=
DIWrap & operator=(const DIWrap &rhs)
Definition lookupattr.h:317
zyppng::sat::detail::DIWrap::_dip
detail::CDataiterator * _dip
Definition lookupattr.h:337
zyppng::sat::detail::DIWrap::reset
void reset()
Definition lookupattr.h:323
zyppng::sat::detail::DIWrap::getstr
const std::string & getstr() const
Definition lookupattr.h:334
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::ZYPP_API
const Arch Arch_empty ZYPP_API
relates: Arch This is an empty Arch represented by an empty string.
Definition Arch.h:173
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
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