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

libzypp 17.38.6

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
348 class LookupAttr::iterator : public boost::iterator_adaptor<
349 iterator // Derived
350 , detail::CDataiterator * // Base
351 , detail::IdType // Value
352 , boost::forward_traversal_tag // CategoryOrTraversal
353 , detail::IdType // Reference
354 >
355 {
356 public:
359
360 void nextSkipSolvAttr();
361
363 void nextSkipSolvable();
364
366 void nextSkipRepo();
367
369 void skipSolvAttr()
370 { nextSkipSolvAttr(); increment(); }
371
373 void skipSolvable()
374 { nextSkipSolvable(); increment(); }
375
377 void skipRepo()
378 { nextSkipRepo(); increment(); }
379
381 void stayInThisSolvable();
382
384 void stayInThisRepo();
386
389
390 Repository inRepo() const;
391
393 Solvable inSolvable() const;
394
396 SolvAttr inSolvAttr() const;
397
399 bool atEnd() const
400 { return !_dip; }
401
402
405
406 detail::IdType solvAttrType() const;
407
409 bool solvAttrNumeric() const;
410
412 bool solvAttrString() const;
413
415 bool solvAttrIdString() const;
416
418 bool solvAttrCheckSum() const;
419
424 bool solvAttrSubEntry() const;
426
458
459 bool subEmpty() const;
460
464 size_type subSize() const;
465
469 iterator subBegin() const;
473 iterator subEnd() const;
478 iterator subFind( const SolvAttr& attr_r ) const;
486 iterator subFind( const zypp::C_Str & attrname_r ) const;
488
491
492 int asInt() const;
494 unsigned asUnsigned() const;
496 bool asBool() const;
498 unsigned long long asUnsignedLL() const;
499
501 const char * c_str() const;
506 std::string asString() const;
507
513 IdString idStr() const;
515 detail::IdType id() const
516 { return idStr().id(); }
517
519 CheckSum asCheckSum() const;
520
527 template<class Tp> Tp asType() const { return Tp(id()); }
529
530 public:
531 iterator();
532
533 iterator( const iterator & rhs );
534
535 iterator & operator=( const iterator & rhs );
536
537 ~iterator();
538
539 public:
544 iterator( detail::DIWrap & dip_r );
545
546 private:
547 friend class boost::iterator_core_access;
548
549 template <class OtherDerived, class OtherIterator, class V, class C, class R, class D>
550 bool equal( const boost::iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> & rhs ) const
551 {
552 return ( bool(base()) == bool(rhs.base()) )
553 && ( ! base() || dip_equal( *base(), *rhs.base() ) );
554 }
555
556 bool dip_equal( const detail::CDataiterator & lhs, const detail::CDataiterator & rhs ) const;
557
558 detail::IdType dereference() const;
559
560 void increment();
561
562 public:
564 detail::CDataiterator * get() const
565 { return _dip.get(); }
566 private:
567 detail::DIWrap _dip;
568 };
569
572 template<> inline int LookupAttr::iterator::asType<int>() const { return asInt(); }
573 template<> inline unsigned LookupAttr::iterator::asType<unsigned>() const { return asUnsigned(); }
574 template<> inline unsigned long long LookupAttr::iterator::asType<unsigned long long>() const { return asUnsignedLL(); }
575 template<> inline bool LookupAttr::iterator::asType<bool>() const { return asBool(); }
576 template<> inline const char * LookupAttr::iterator::asType<const char *>() const { return c_str(); }
577 template<> inline std::string LookupAttr::iterator::asType<std::string>() const { return asString(); }
578 template<> inline IdString LookupAttr::iterator::asType<IdString>() const { return idStr(); }
579 template<> CheckSum LookupAttr::iterator::asType<CheckSum>() const;
580
581 template<class TResult, class TAttr>
582 class ArrayAttr;
584
585} // namespace zyppng::sat
586
587#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:582
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:355
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:377
zyppng::sat::LookupAttr::iterator::skipSolvAttr
void skipSolvAttr()
Immediately advance to the next SolvAttr.
Definition lookupattr.h:369
zyppng::sat::LookupAttr::iterator::asType
Tp asType() const
Templated return type.
Definition lookupattr.h:527
zyppng::sat::LookupAttr::iterator::dip_equal
bool dip_equal(const detail::CDataiterator &lhs, const detail::CDataiterator &rhs) const
Definition lookupattr.cc:702
zyppng::sat::LookupAttr::iterator::skipSolvable
void skipSolvable()
Immediately advance to the next Solvable.
Definition lookupattr.h:373
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:567
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::equal
bool equal(const boost::iterator_adaptor< OtherDerived, OtherIterator, V, C, R, D > &rhs) const
Definition lookupattr.h:550
zyppng::sat::LookupAttr::iterator::get
detail::CDataiterator * get() const
Expert backdoor.
Definition lookupattr.h:564
zyppng::sat::LookupAttr::iterator::increment
void increment()
Definition lookupattr.cc:715
zyppng::sat::LookupAttr::iterator::atEnd
bool atEnd() const
Whether this points to the end of a query (Iterator is invalid).
Definition lookupattr.h:399
zyppng::sat::LookupAttr::iterator::id
detail::IdType id() const
Definition lookupattr.h:515
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:50
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::base
Definition Random.cc:7
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
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