libzypp: zypp/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 ZYPP_SAT_LOOKUPATTR_H
13#define ZYPP_SAT_LOOKUPATTR_H
14
15#include <iosfwd>
16#include <utility>
17
18#include <zypp-core/base/PtrTypes.h>
19#include <zypp-core/base/DefaultIntegral>
20#include <zypp-core/Globals.h>
21
22#include <zypp/sat/detail/PoolMember.h>
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 //
109 class ZYPP_API LookupAttr
110 {
111 public:
112 using Exception = MatchException;
113
114 public:
115 using size_type = unsigned int;
116
118 enum Location {
119 SOLV_ATTR = 0,
120 REPO_ATTR = -1
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
201 void resetStrMatcher();
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;
234 RWCOW_pointer<Impl> _pimpl;
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 //
264 class LookupRepoAttr : public LookupAttr
265 {
266 public:
268 LookupRepoAttr()
269 {}
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:
279 void setPool()
280 { LookupAttr::setPool( REPO_ATTR ); }
281
282 void setRepo( Repository repo_r );
283 private:
284 // Hide. You can't look inside and outside Solvables at the same time.
285 using LookupAttr::solvable;
286 using LookupAttr::setSolvable;
287 };
288
289
290 namespace detail
291 {
299 class DIWrap
300 {
301 public:
303 DIWrap()
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:
337 detail::CDataiterator * operator->() const { return _dip; }
338 detail::CDataiterator * get() const { return _dip; }
339 const std::string & getstr() const { return _mstring; }
340
341 private:
342 detail::CDataiterator * _dip;
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
378 void skipSolvAttr()
379 { nextSkipSolvAttr(); increment(); }
380
382 void skipSolvable()
383 { nextSkipSolvable(); increment(); }
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;
523 detail::IdType id() 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:
575 detail::CDataiterator * get() const
576 { return _dip.get(); }
577 private:
578 detail::DIWrap _dip;
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
613 inline std::ostream & operator<<( std::ostream & str, const zypp::sat::detail::CDataiterator & obj )
614{ return str << &obj; }
615
616#endif // ZYPP_SAT_LOOKUPATTR_H
Globals.h
Provides API related macros.
operator<<
std::ostream & operator<<(std::ostream &str, const zypp::sat::detail::CDataiterator *obj)
relates: zypp::sat::LookupAttr::iterator Stream output of the underlying iterator for debug.
Definition LookupAttr.cc:808
PoolMember.h
PtrTypes.h
SolvAttr.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::Repository
Definition Repository.h:40
zypp::StrMatcher
String matching (STRING|SUBSTRING|GLOB|REGEX).
Definition StrMatcher.h:298
zypp::sat::LookupAttr::Impl
LookupAttr implememtation.
Definition LookupAttr.cc:57
zypp::sat::LookupAttr::TransformIterator
TransformIterator returning an iterator vaue of type TResult.
Definition LookupAttrTools.h:65
zypp::sat::LookupAttr::iterator
Result iterator.
Definition LookupAttr.h:364
zypp::sat::LookupAttr::iterator::get
detail::CDataiterator * get() const
Expert backdoor.
Definition LookupAttr.h:575
zypp::sat::LookupAttr::iterator::id
detail::IdType id() const
Definition LookupAttr.h:523
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::nextSkipSolvable
void nextSkipSolvable()
On the next call to operator++ advance to the next Solvable.
Definition LookupAttr.cc:364
zypp::sat::LookupAttr::iterator::increment
void increment()
Definition LookupAttr.cc:766
zypp::sat::LookupAttr::iterator::nextSkipSolvAttr
void nextSkipSolvAttr()
On the next call to operator++ advance to the next SolvAttr.
Definition LookupAttr.cc:361
zypp::sat::LookupAttr::iterator::equal
bool equal(const boost::iterator_adaptor< OtherDerived, OtherIterator, V, C, R, D > &rhs) const
Definition LookupAttr.h:561
zypp::sat::LookupAttr::iterator::skipSolvable
void skipSolvable()
Immediately advance to the next Solvable.
Definition LookupAttr.h:382
zypp::sat::LookupAttr::iterator::_dip
detail::DIWrap _dip
Definition LookupAttr.h:578
zypp::sat::LookupAttr::iterator::nextSkipRepo
void nextSkipRepo()
On the next call to operator++ advance to the next Repository.
Definition LookupAttr.cc:367
zypp::sat::LookupAttr::iterator::dip_equal
bool dip_equal(const detail::CDataiterator &lhs, const detail::CDataiterator &rhs) const
Definition LookupAttr.cc:753
zypp::sat::LookupAttr::iterator::atEnd
bool atEnd() const
Whether this points to the end of a query (Iterator is invalid).
Definition LookupAttr.h:408
zypp::sat::LookupAttr::iterator::skipSolvAttr
void skipSolvAttr()
Immediately advance to the next SolvAttr.
Definition LookupAttr.h:378
zypp::sat::LookupAttr::iterator::skipRepo
void skipRepo()
Immediately advance to the next Repository.
Definition LookupAttr.h:386
zypp::sat::LookupAttr
Lightweight attribute value lookup.
Definition LookupAttr.h:110
zypp::sat::LookupAttr::resetStrMatcher
void resetStrMatcher()
Reset the pattern to match.
zypp::sat::LookupAttr::end
iterator end() const
Iterator behind the end of query results.
Definition LookupAttr.cc:240
zypp::sat::LookupAttr::_pimpl
RWCOW_pointer< Impl > _pimpl
Definition LookupAttr.h:234
zypp::sat::LookupAttr::strMatcher
const StrMatcher & strMatcher() const
The pattern to match.
Definition LookupAttr.cc:203
zypp::sat::LookupAttr::empty
bool empty() const
Whether the query is empty.
Definition LookupAttr.cc:243
zypp::sat::LookupAttr::size_type
unsigned int size_type
Definition LookupAttr.h:115
zypp::sat::LookupAttr::LookupAttr
LookupAttr(LookupAttr &&) noexcept=default
zypp::sat::LookupAttr::Location
Location
Specify the where to look for the attribule.
Definition LookupAttr.h:118
zypp::sat::LookupAttr::REPO_ATTR
@ REPO_ATTR
Search for repository attributes.
Definition LookupAttr.h:120
zypp::sat::LookupAttr::SOLV_ATTR
@ SOLV_ATTR
Search for solvable attributes (default).
Definition LookupAttr.h:119
zypp::sat::LookupAttr::setStrMatcher
void setStrMatcher(const StrMatcher &matcher_r)
Set the pattern to match.
Definition LookupAttr.cc:206
zypp::sat::LookupAttr::repo
Repository repo() const
Whether to search in one Repository.
Definition LookupAttr.cc:217
zypp::sat::LookupAttr::attr
SolvAttr attr() const
The SolvAttr to search.
Definition LookupAttr.cc:197
zypp::sat::LookupAttr::parent
SolvAttr parent() const
Whether to search within a sub-structure (SolvAttr::noAttr if not).
Definition LookupAttr.cc:229
zypp::sat::LookupAttr::setAttr
void setAttr(SolvAttr attr_r)
Set the SolvAttr to search.
Definition LookupAttr.cc:200
zypp::sat::LookupAttr::setRepo
void setRepo(Repository repo_r, Location=SOLV_ATTR)
Set search in one Repository.
Definition LookupAttr.cc:220
zypp::sat::LookupAttr::pool
bool pool() const
Whether to search in Pool.
Definition LookupAttr.cc:211
zypp::sat::LookupAttr::size
size_type size() const
Ammount of results.
Definition LookupAttr.cc:246
zypp::sat::LookupAttr::begin
iterator begin() const
Iterator to the begin of query results.
Definition LookupAttr.cc:237
zypp::sat::LookupAttr::operator=
LookupAttr & operator=(const LookupAttr &)=default
zypp::sat::LookupAttr::LookupAttr
LookupAttr(const LookupAttr &)=default
zypp::sat::LookupAttr::setSolvable
void setSolvable(Solvable solv_r)
Set search in one Solvable.
Definition LookupAttr.cc:226
zypp::sat::LookupAttr::solvable
Solvable solvable() const
Whether to search in one Solvable.
Definition LookupAttr.cc:223
zypp::sat::LookupAttr::LookupAttr
LookupAttr()
Default ctor finds nothing.
Definition LookupAttr.cc:169
zypp::sat::LookupAttr::Exception
MatchException Exception
Definition LookupAttr.h:112
zypp::sat::LookupAttr::setPool
void setPool(Location=SOLV_ATTR)
Set search in Pool (all repositories).
Definition LookupAttr.cc:214
zypp::sat::LookupAttr::setParent
void setParent(SolvAttr attr_r)
Set search within a sub-structure (SolvAttr::noAttr for none).
Definition LookupAttr.cc:232
zypp::sat::LookupRepoAttr
Lightweight repository attribute value lookup.
Definition LookupAttr.h:265
zypp::sat::LookupRepoAttr::LookupRepoAttr
LookupRepoAttr(SolvAttr attr_r)
Definition LookupAttr.h:271
zypp::sat::LookupRepoAttr::LookupRepoAttr
LookupRepoAttr()
Default ctor finds nothing.
Definition LookupAttr.h:268
zypp::sat::LookupRepoAttr::setPool
void setPool()
Set search in Pool (all repositories).
Definition LookupAttr.h:279
zypp::sat::SolvAttr
Solvable attribute keys.
Definition SolvAttr.h:41
zypp::sat::Solvable
A Solvable object within the sat Pool.
Definition Solvable.h:54
zypp::sat::detail::DIWrap
Wrapper around sat detail::CDataiterator.
Definition LookupAttr.h:300
zypp::sat::detail::DIWrap::swap
void swap(DIWrap &rhs) noexcept
Definition LookupAttr.h:315
zypp::sat::detail::DIWrap::get
detail::CDataiterator * get() const
Definition LookupAttr.h:338
zypp::sat::detail::DIWrap::operator=
DIWrap & operator=(const DIWrap &rhs)
Definition LookupAttr.h:323
zypp::sat::detail::DIWrap::operator->
detail::CDataiterator * operator->() const
Definition LookupAttr.h:337
zypp::sat::detail::DIWrap::getstr
const std::string & getstr() const
Definition LookupAttr.h:339
zypp::sat::detail::DIWrap::_mstring
std::string _mstring
Definition LookupAttr.h:343
zypp::sat::detail::DIWrap::reset
void reset()
Definition LookupAttr.h:329
zypp::sat::detail::DIWrap::DIWrap
DIWrap()
NULL detail::CDataiterator
Definition LookupAttr.h:303
zypp::sat::detail::DIWrap::_dip
detail::CDataiterator * _dip
Definition LookupAttr.h:342
std
Definition ansi.h:855
str
String related utilities and Regular expression matching.
zypp::base
Definition Random.cc:7
zypp::sat::detail::SolvableIdType
unsigned int SolvableIdType
Id type to connect Solvable and sat-solvable.
Definition PoolDefines.h:63
zypp::sat::detail::IdType
int IdType
Generic Id type.
Definition PoolDefines.h:42
zypp::sat::detail::CDataiterator
::s_Dataiterator CDataiterator
Wrapped libsolv C data type exposed as backdoor.
Definition PoolDefines.h:31
zypp::sat::detail::RepoIdType
CRepo * RepoIdType
Id type to connect Repo and sat-repo.
Definition PoolDefines.h:71
zypp::sat
Libsolv interface
zypp::sat::dumpOn
std::ostream & dumpOn(std::ostream &str, const LocaleSupport &obj)
relates: LocaleSupport More verbose stream output including dependencies
Definition LocaleSupport.cc:41
zypp::solver::detail
Definition PoolImpl.h:110
zypp::str
Provide print[f] and sprint[f] functions based on JoinFormat.
Definition PurgeKernels.h:19
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
zypp::operator<<
std::ostream & operator<<(std::ostream &str, const Capabilities &obj)
relates: Capabilities Stream output
Definition Capabilities.cc:65
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