libzypp 17.37.17
LookupAttr.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#ifndef ZYPP_SAT_LOOKUPATTR_H
13#define ZYPP_SAT_LOOKUPATTR_H
14
15#include <iosfwd>
16#include <utility>
17
18#include <zypp/base/PtrTypes.h>
19#include <zypp-core/base/DefaultIntegral>
20#include <zypp-core/Globals.h>
21
23#include <zypp/sat/SolvAttr.h>
24
26namespace zypp
27{
28
29 class CheckSum;
30 class Match;
31 struct MatchException;
32 class StrMatcher;
33
35 namespace sat
36 {
37
39 //
40 // CLASS NAME : LookupAttr
41 //
110 {
111 public:
113
114 public:
115 using size_type = unsigned int;
116
118 enum Location {
121 };
122
123 public:
125 LookupAttr();
126
127 LookupAttr(const LookupAttr &) = default;
128 LookupAttr(LookupAttr &&) noexcept = default;
129 LookupAttr &operator=(const LookupAttr &) = default;
130 LookupAttr &operator=(LookupAttr &&) noexcept = default;
131
133 explicit LookupAttr( SolvAttr attr_r, Location = SOLV_ATTR );
135 LookupAttr( SolvAttr attr_r, SolvAttr parent_r, Location = SOLV_ATTR );
136
138 LookupAttr( SolvAttr attr_r, Repository repo_r, Location = SOLV_ATTR );
140 LookupAttr( SolvAttr attr_r, SolvAttr parent_r, Repository repo_r, Location = SOLV_ATTR );
141
143 LookupAttr( SolvAttr attr_r, Solvable solv_r );
145 LookupAttr( SolvAttr attr_r, SolvAttr parent_r, Solvable solv_r );
146
147 public:
150
151 class iterator;
152
154 iterator begin() const;
155
157 iterator end() const;
158
160 bool empty() const;
161
165 size_type size() const;
166
168 template<class TResult, class TAttr = TResult>
169 class TransformIterator;
171
172 public:
175
176 SolvAttr attr() const;
177
179 void setAttr( SolvAttr attr_r );
181
184
193 const StrMatcher & strMatcher() const;
194
198 void setStrMatcher( const StrMatcher & matcher_r );
199
203
204 public:
207
208 bool pool() const;
209
211 void setPool( Location = SOLV_ATTR );
212
214 Repository repo() const;
215
217 void setRepo( Repository repo_r, Location = SOLV_ATTR );
218
220 Solvable solvable() const;
221
223 void setSolvable( Solvable solv_r );
224
226 SolvAttr parent() const;
227
229 void setParent( SolvAttr attr_r );
231
232 private:
233 class Impl;
235 };
236
237
239 std::ostream & operator<<( std::ostream & str, const LookupAttr & obj ) ZYPP_API;
240
242 std::ostream & dumpOn( std::ostream & str, const LookupAttr & obj ) ZYPP_API;
243
245 //
246 // CLASS NAME : LookupRepoAttr
247 //
265 {
266 public:
270
271 explicit LookupRepoAttr( SolvAttr attr_r )
272 : LookupAttr( std::move(attr_r), REPO_ATTR )
273 {}
274
275 explicit LookupRepoAttr( SolvAttr attr_r, Repository repo_r );
276
277 public:
281
282 void setRepo( Repository repo_r );
283 private:
284 // Hide. You can't look inside and outside Solvables at the same time.
287 };
288
289
290 namespace detail
291 {
299 class DIWrap
300 {
301 public:
304 : _dip( 0 )
305 {}
306
307 DIWrap( RepoIdType repoId_r, SolvableIdType solvId_r, IdType attrId_r,
308 std::string mstring_r = std::string(), int flags_r = 0 );
310 DIWrap( RepoIdType repoId_r, SolvableIdType solvId_r, IdType attrId_r,
311 const char * mstring_r, int flags_r = 0 );
312 DIWrap( const DIWrap & rhs );
313 ~DIWrap();
314 public:
315 void swap( DIWrap & rhs ) noexcept
316 {
317 if ( &rhs != this ) // prevent self assign!
318 {
319 std::swap( _dip, rhs._dip );
320 std::swap( _mstring, rhs._mstring );
321 }
322 }
323 DIWrap & operator=( const DIWrap & rhs )
324 {
325 if ( &rhs != this ) // prevent self assign!
326 DIWrap( rhs ).swap( *this );
327 return *this;
328 }
329 void reset()
330 { DIWrap().swap( *this ); }
331 public:
333 explicit operator bool() const
334 { return _dip; }
335
336 public:
338 detail::CDataiterator * get() const { return _dip; }
339 const std::string & getstr() const { return _mstring; }
340
341 private:
343 std::string _mstring;
344 };
345
346 std::ostream & operator<<( std::ostream & str, const DIWrap & obj );
347 }
348
350 //
351 // CLASS NAME : LookupAttr::iterator
352 //
357 class LookupAttr::iterator : public boost::iterator_adaptor<
358 iterator // Derived
359 , detail::CDataiterator * // Base
360 , detail::IdType // Value
361 , boost::forward_traversal_tag // CategoryOrTraversal
362 , detail::IdType // Reference
363 >
364 {
365 public:
368
369 void nextSkipSolvAttr();
370
372 void nextSkipSolvable();
373
375 void nextSkipRepo();
376
380
384
386 void skipRepo()
387 { nextSkipRepo(); increment(); }
388
390 void stayInThisSolvable();
391
393 void stayInThisRepo();
395
398
399 Repository inRepo() const;
400
402 Solvable inSolvable() const;
403
405 SolvAttr inSolvAttr() const;
406
408 bool atEnd() const
409 { return !_dip; }
410
411
414
415 detail::IdType solvAttrType() const;
416
418 bool solvAttrNumeric() const;
419
421 bool solvAttrString() const;
422
424 bool solvAttrIdString() const;
425
427 bool solvAttrCheckSum() const;
428
433 bool solvAttrSubEntry() const;
435
466
467 bool subEmpty() const;
468
472 size_type subSize() const;
473
477 iterator subBegin() const;
481 iterator subEnd() const;
486 iterator subFind( const SolvAttr& attr_r ) const;
494 iterator subFind( const C_Str & attrname_r ) const;
496
499
500 int asInt() const;
502 unsigned asUnsigned() const;
504 bool asBool() const;
506 unsigned long long asUnsignedLL() const;
507
509 const char * c_str() const;
514 std::string asString() const;
515
521 IdString idStr() const;
524 { return idStr().id(); }
525
527 CheckSum asCheckSum() const;
528
535 template<class Tp> Tp asType() const { return Tp(id()); }
537
539 // internal stuff below
541 public:
542 iterator();
543
544 iterator( const iterator & rhs );
545
546 iterator & operator=( const iterator & rhs );
547
548 ~iterator();
549
550 public:
555 iterator( detail::DIWrap & dip_r );
556
557 private:
558 friend class boost::iterator_core_access;
559
560 template <class OtherDerived, class OtherIterator, class V, class C, class R, class D>
561 bool equal( const boost::iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> & rhs ) const
562 {
563 return ( bool(base()) == bool(rhs.base()) )
564 && ( ! base() || dip_equal( *base(), *rhs.base() ) );
565 }
566
567 bool dip_equal( const detail::CDataiterator & lhs, const detail::CDataiterator & rhs ) const;
568
569 detail::IdType dereference() const;
570
571 void increment();
572
573 public:
576 { return _dip.get(); }
577 private:
579 };
580
581
583 std::ostream & operator<<( std::ostream & str, const LookupAttr::iterator & obj ) ZYPP_API;
584
586
589 template<> inline int LookupAttr::iterator::asType<int>() const { return asInt(); }
590 template<> inline unsigned LookupAttr::iterator::asType<unsigned>() const { return asUnsigned(); }
591 template<> inline unsigned long long LookupAttr::iterator::asType<unsigned long long>() const { return asUnsignedLL(); }
592 template<> inline bool LookupAttr::iterator::asType<bool>() const { return asBool(); }
593 template<> inline const char * LookupAttr::iterator::asType<const char *>() const { return c_str(); }
594 template<> inline std::string LookupAttr::iterator::asType<std::string>() const { return asString(); }
595 template<> inline IdString LookupAttr::iterator::asType<IdString>() const { return idStr(); }
596 template<> CheckSum LookupAttr::iterator::asType<CheckSum>() const;
597
598 template<class TResult, class TAttr>
599 class ArrayAttr;
601
603 } // namespace sat
606} // namespace zypp
608
610std::ostream & operator<<( std::ostream & str, const zypp::sat::detail::CDataiterator * obj );
611
613inline std::ostream & operator<<( std::ostream & str, const zypp::sat::detail::CDataiterator & obj )
614{ return str << &obj; }
615
616#endif // ZYPP_SAT_LOOKUPATTR_H
std::ostream & operator<<(std::ostream &str, const zypp::sat::detail::CDataiterator *obj)
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:44
String matching option flags as used e.g.
Definition StrMatcher.h:33
String matching (STRING|SUBSTRING|GLOB|REGEX).
Definition StrMatcher.h:298
LookupAttr implememtation.
Definition LookupAttr.cc:57
TransformIterator returning an iterator vaue of type TResult.
detail::CDataiterator * get() const
Expert backdoor.
Definition LookupAttr.h:575
detail::IdType id() const
Definition LookupAttr.h:523
Tp asType() const
Templated return type.
Definition LookupAttr.h:535
IdString idStr() const
As IdStr.
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:561
void skipSolvable()
Immediately advance to the next Solvable.
Definition LookupAttr.h:382
void nextSkipRepo()
On the next call to operator++ advance to the next Repository.
bool dip_equal(const detail::CDataiterator &lhs, const detail::CDataiterator &rhs) const
bool atEnd() const
Whether this points to the end of a query (Iterator is invalid).
Definition LookupAttr.h:408
void skipSolvAttr()
Immediately advance to the next SolvAttr.
Definition LookupAttr.h:378
void skipRepo()
Immediately advance to the next Repository.
Definition LookupAttr.h:386
Lightweight attribute value lookup.
Definition LookupAttr.h:110
void resetStrMatcher()
Reset the pattern to match.
iterator end() const
Iterator behind the end of query results.
RWCOW_pointer< Impl > _pimpl
Definition LookupAttr.h:234
const StrMatcher & strMatcher() const
The pattern to match.
std::ostream & dumpOn(std::ostream &str, const LookupAttr &obj) ZYPP_API
Verbose stream output including the query result.
bool empty() const
Whether the query is empty.
unsigned int size_type
Definition LookupAttr.h:115
LookupAttr(LookupAttr &&) noexcept=default
Location
Specify the where to look for the attribule.
Definition LookupAttr.h:118
@ REPO_ATTR
Search for repository attributes.
Definition LookupAttr.h:120
@ SOLV_ATTR
Search for solvable attributes (default)
Definition LookupAttr.h:119
void setStrMatcher(const StrMatcher &matcher_r)
Set the pattern to match.
Repository repo() const
Whether to search in one Repository.
SolvAttr attr() const
The SolvAttr to search.
SolvAttr parent() const
Whether to search within a sub-structure (SolvAttr::noAttr if not)
void setAttr(SolvAttr attr_r)
Set the SolvAttr to search.
void setRepo(Repository repo_r, Location=SOLV_ATTR)
Set search in one Repository.
bool pool() const
Whether to search in Pool.
size_type size() const
Ammount of results.
iterator begin() const
Iterator to the begin of query results.
LookupAttr & operator=(const LookupAttr &)=default
LookupAttr(const LookupAttr &)=default
void setSolvable(Solvable solv_r)
Set search in one Solvable.
Solvable solvable() const
Whether to search in one Solvable.
LookupAttr()
Default ctor finds nothing.
MatchException Exception
Definition LookupAttr.h:112
void setPool(Location=SOLV_ATTR)
Set search in Pool (all repositories).
void setParent(SolvAttr attr_r)
Set search within a sub-structure (SolvAttr::noAttr for none)
Lightweight repository attribute value lookup.
Definition LookupAttr.h:265
LookupRepoAttr(SolvAttr attr_r)
Definition LookupAttr.h:271
LookupRepoAttr()
Default ctor finds nothing.
Definition LookupAttr.h:268
void setPool()
Set search in Pool (all repositories).
Definition LookupAttr.h:279
Solvable attribute keys.
Definition SolvAttr.h:41
A Solvable object within the sat Pool.
Definition Solvable.h:54
Wrapper around sat detail::CDataiterator.
Definition LookupAttr.h:300
void swap(DIWrap &rhs) noexcept
Definition LookupAttr.h:315
detail::CDataiterator * get() const
Definition LookupAttr.h:338
DIWrap & operator=(const DIWrap &rhs)
Definition LookupAttr.h:323
detail::CDataiterator * operator->() const
Definition LookupAttr.h:337
const std::string & getstr() const
Definition LookupAttr.h:339
DIWrap()
NULL detail::CDataiterator
Definition LookupAttr.h:303
detail::CDataiterator * _dip
Definition LookupAttr.h:342
Definition Arch.h:364
String related utilities and Regular expression matching.
unsigned int SolvableIdType
Id type to connect Solvable and sat-solvable.
Definition PoolMember.h:125
int IdType
Generic Id type.
Definition PoolMember.h:104
::s_Dataiterator CDataiterator
Wrapped libsolv C data type exposed as backdoor.
Definition PoolMember.h:58
CRepo * RepoIdType
Id type to connect Repo and sat-repo.
Definition PoolMember.h:133
Libsolv interface
String related utilities and Regular expression matching.
Easy-to use interface to the ZYPP dependency resolver.
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Definition Arch.h:247
std::string asString(const Patch::Category &obj)
Definition Patch.cc:122
Exceptions thrown from attribute matching.
Definition StrMatcher.h:248
RW_pointer supporting 'copy on write' functionality.
Definition PtrTypes.h:469
Provides API related macros.