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
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 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
371
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;
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:
565 { return _dip.get(); }
566 private:
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(); }
580
581 template<class TResult, class TAttr>
584
585} // namespace zyppng::sat
586
587#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:377
void skipSolvAttr()
Immediately advance to the next SolvAttr.
Definition lookupattr.h:369
Tp asType() const
Templated return type.
Definition lookupattr.h:527
bool dip_equal(const detail::CDataiterator &lhs, const detail::CDataiterator &rhs) const
void skipSolvable()
Immediately advance to the next Solvable.
Definition lookupattr.h:373
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 equal(const boost::iterator_adaptor< OtherDerived, OtherIterator, V, C, R, D > &rhs) const
Definition lookupattr.h:550
detail::CDataiterator * get() const
Expert backdoor.
Definition lookupattr.h:564
bool atEnd() const
Whether this points to the end of a query (Iterator is invalid).
Definition lookupattr.h:399
detail::IdType id() const
Definition lookupattr.h:515
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.
Exceptions thrown from attribute matching.
Definition StrMatcher.h:248
RW_pointer supporting 'copy on write' functionality.
Definition PtrTypes.h:469