libzypp: zypp/sat/LookupAttr.h Source File

libzypp 17.25.10

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
17 #include <zypp/base/PtrTypes.h>
18 #include <zypp/base/DefaultIntegral.h>
19
20 #include <zypp/sat/detail/PoolMember.h>
21 #include <zypp/sat/SolvAttr.h>
22
24 namespace zypp
25 {
26
27 class CheckSum;
28 class Match;
29 struct MatchException;
30 class StrMatcher;
31
33 namespace sat
34 {
35
37 //
38 // CLASS NAME : LookupAttr
39 //
107 class LookupAttr
108 {
109 public:
110 typedef MatchException Exception;
111
112 public:
113 typedef unsigned size_type;
114
116 enum Location {
117 SOLV_ATTR = 0,
118 REPO_ATTR = -1
119 };
120
121 public:
123 LookupAttr();
124
126 explicit LookupAttr( SolvAttr attr_r, Location = SOLV_ATTR );
128 LookupAttr( SolvAttr attr_r, SolvAttr parent_r, Location = SOLV_ATTR );
129
131 LookupAttr( SolvAttr attr_r, Repository repo_r, Location = SOLV_ATTR );
133 LookupAttr( SolvAttr attr_r, SolvAttr parent_r, Repository repo_r, Location = SOLV_ATTR );
134
136 LookupAttr( SolvAttr attr_r, Solvable solv_r );
138 LookupAttr( SolvAttr attr_r, SolvAttr parent_r, Solvable solv_r );
139
140 public:
144 class iterator;
145
147 iterator begin() const;
148
150 iterator end() const;
151
153 bool empty() const;
154
158 size_type size() const;
159
161 template<class TResult, class TAttr = TResult>
162 class TransformIterator;
164
165 public:
169 SolvAttr attr() const;
170
172 void setAttr( SolvAttr attr_r );
174
186 const StrMatcher & strMatcher() const;
187
191 void setStrMatcher( const StrMatcher & matcher_r );
192
194 void resetStrMatcher();
196
197 public:
201 bool pool() const;
202
204 void setPool( Location = SOLV_ATTR );
205
207 Repository repo() const;
208
210 void setRepo( Repository repo_r, Location = SOLV_ATTR );
211
213 Solvable solvable() const;
214
216 void setSolvable( Solvable solv_r );
217
219 SolvAttr parent() const;
220
222 void setParent( SolvAttr attr_r );
224
225 private:
226 class Impl;
227 RWCOW_pointer<Impl> _pimpl;
228 };
230
232 std::ostream & operator<<( std::ostream & str, const LookupAttr & obj );
233
235 std::ostream & dumpOn( std::ostream & str, const LookupAttr & obj );
236
238 //
239 // CLASS NAME : LookupRepoAttr
240 //
257 class LookupRepoAttr : public LookupAttr
258 {
259 public:
261 LookupRepoAttr()
262 {}
264 explicit LookupRepoAttr( SolvAttr attr_r )
265 : LookupAttr( attr_r, REPO_ATTR )
266 {}
268 explicit LookupRepoAttr( SolvAttr attr_r, Repository repo_r );
269
270 public:
272 void setPool()
273 { LookupAttr::setPool( REPO_ATTR ); }
275 void setRepo( Repository repo_r );
276 private:
277 // Hide. You can't look inside and outside Solvables at the same time.
278 using LookupAttr::solvable;
279 using LookupAttr::setSolvable;
280 };
282
283 namespace detail
284 {
292 class DIWrap
293 {
294 public:
296 DIWrap()
297 : _dip( 0 )
298 {}
300 DIWrap( RepoIdType repoId_r, SolvableIdType solvId_r, IdType attrId_r,
301 const std::string & mstring_r = std::string(), int flags_r = 0 );
303 DIWrap( 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 )
309 {
310 if ( &rhs != this ) // prevent self assign!
311 {
312 std::swap( _dip, rhs._dip );
313 std::swap( _mstring, rhs._mstring );
314 }
315 }
316 DIWrap & operator=( const DIWrap & rhs )
317 {
318 if ( &rhs != this ) // prevent self assign!
319 DIWrap( rhs ).swap( *this );
320 return *this;
321 }
322 void reset()
323 { DIWrap().swap( *this ); }
324 public:
326 explicit operator bool() const
327 { return _dip; }
328
329 public:
330 detail::CDataiterator * operator->() const { return _dip; }
331 detail::CDataiterator * get() const { return _dip; }
332 const std::string & getstr() const { return _mstring; }
333
334 private:
335 detail::CDataiterator * _dip;
336 std::string _mstring;
337 };
339 std::ostream & operator<<( std::ostream & str, const DIWrap & obj );
340 }
341
343 //
344 // CLASS NAME : LookupAttr::iterator
345 //
350 class LookupAttr::iterator : public boost::iterator_adaptor<
351 iterator // Derived
352 , detail::CDataiterator * // Base
353 , detail::IdType // Value
354 , boost::forward_traversal_tag // CategoryOrTraversal
355 , detail::IdType // Reference
356 >
357 {
358 public:
362 void nextSkipSolvAttr();
363
365 void nextSkipSolvable();
366
368 void nextSkipRepo();
369
371 void skipSolvAttr()
372 { nextSkipSolvAttr(); increment(); }
373
375 void skipSolvable()
376 { nextSkipSolvable(); increment(); }
377
379 void skipRepo()
380 { nextSkipRepo(); increment(); }
381
383 void stayInThisSolvable();
384
386 void stayInThisRepo();
388
392 Repository inRepo() const;
393
395 Solvable inSolvable() const;
396
398 SolvAttr inSolvAttr() const;
399
401 bool atEnd() const
402 { return !_dip; }
404
408 detail::IdType solvAttrType() const;
409
411 bool solvAttrNumeric() const;
412
414 bool solvAttrString() const;
415
417 bool solvAttrIdString() const;
418
420 bool solvAttrCheckSum() const;
421
426 bool solvAttrSubEntry() const;
428
460 bool subEmpty() const;
461
465 size_type subSize() const;
466
470 iterator subBegin() const;
474 iterator subEnd() const;
479 iterator subFind( SolvAttr attr_r ) const;
487 iterator subFind( const C_Str & attrname_r ) const;
489
493 int asInt() const;
495 unsigned asUnsigned() const;
497 bool asBool() const;
499 unsigned long long asUnsignedLL() const;
500
502 const char * c_str() const;
507 std::string asString() const;
508
514 IdString idStr() const;
516 detail::IdType id() const
517 { return idStr().id(); }
518
520 CheckSum asCheckSum() const;
521
528 template<class Tp> Tp asType() const { return Tp(id()); }
530
532 // internal stuff below
534 public:
535 iterator();
536
537 iterator( const iterator & rhs );
538
539 iterator & operator=( const iterator & rhs );
540
541 ~iterator();
542
543 public:
548 iterator( detail::DIWrap & dip_r );
549
550 private:
551 friend class boost::iterator_core_access;
552
553 template <class OtherDerived, class OtherIterator, class V, class C, class R, class D>
554 bool equal( const boost::iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> & rhs ) const
555 {
556 return ( bool(base()) == bool(rhs.base()) )
557 && ( ! base() || dip_equal( *base(), *rhs.base() ) );
558 }
559
560 bool dip_equal( const detail::CDataiterator & lhs, const detail::CDataiterator & rhs ) const;
561
562 detail::IdType dereference() const;
563
564 void increment();
565
566 public:
568 detail::CDataiterator * get() const
569 { return _dip.get(); }
570 private:
571 detail::DIWrap _dip;
572 };
574
576 std::ostream & operator<<( std::ostream & str, const LookupAttr::iterator & obj );
577
579
582 template<> inline int LookupAttr::iterator::asType<int>() const { return asInt(); }
583 template<> inline unsigned LookupAttr::iterator::asType<unsigned>() const { return asUnsigned(); }
584 template<> inline unsigned long long LookupAttr::iterator::asType<unsigned long long>() const { return asUnsignedLL(); }
585 template<> inline bool LookupAttr::iterator::asType<bool>() const { return asBool(); }
586 template<> inline const char * LookupAttr::iterator::asType<const char *>() const { return c_str(); }
587 template<> inline std::string LookupAttr::iterator::asType<std::string>() const { return asString(); }
588 template<> inline IdString LookupAttr::iterator::asType<IdString>() const { return idStr(); }
589 template<> CheckSum LookupAttr::iterator::asType<CheckSum>() const;
590
591 template<class TResult, class TAttr>
592 class ArrayAttr;
594
596 } // namespace sat
599 } // namespace zypp
601
603 std::ostream & operator<<( std::ostream & str, const zypp::sat::detail::CDataiterator * obj );
604
606 inline std::ostream & operator<<( std::ostream & str, const zypp::sat::detail::CDataiterator & obj )
607 { return str << &obj; }
608
609 #endif // ZYPP_SAT_LOOKUPATTR_H
DefaultIntegral.h
PoolMember.h
PtrTypes.h
SolvAttr.h
zypp::C_Str
Convenience char* constructible from std::string and char*, it maps (char*)0 to an empty string.
Definition: String.h:91
zypp::CheckSum
Definition: CheckSum.h:34
zypp::IdString
Access to the sat-pools string space.
Definition: IdString.h:43
zypp::IdString::id
IdType id() const
Expert backdoor.
Definition: IdString.h:122
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:56
zypp::sat::LookupAttr::iterator
Result iterator.
Definition: LookupAttr.h:357
zypp::sat::LookupAttr::iterator::subBegin
iterator subBegin() const
Iterator to the begin of a sub-structure.
Definition: LookupAttr.cc:470
zypp::sat::LookupAttr::iterator::id
detail::IdType id() const
Definition: LookupAttr.h:516
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:561
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:558
zypp::sat::LookupAttr::iterator::stayInThisSolvable
void stayInThisSolvable()
Stop after all matches in the current Solvable are processed.
Definition: LookupAttr.cc:369
zypp::sat::LookupAttr::iterator::asType
Tp asType() const
Templated return type.
Definition: LookupAttr.h:528
zypp::sat::LookupAttr::iterator::idStr
IdString idStr() const
As IdStr.
Definition: LookupAttr.cc:664
zypp::sat::LookupAttr::iterator::dereference
detail::IdType dereference() const
Definition: LookupAttr.cc:759
zypp::sat::LookupAttr::iterator::nextSkipSolvable
void nextSkipSolvable()
On the next call to operator++ advance to the next Solvable.
Definition: LookupAttr.cc:363
zypp::sat::LookupAttr::iterator::inSolvAttr
SolvAttr inSolvAttr() const
The current SolvAttr.
Definition: LookupAttr.cc:357
zypp::sat::LookupAttr::iterator::iterator
iterator()
Definition: LookupAttr.cc:718
zypp::sat::LookupAttr::iterator::subEmpty
bool subEmpty() const
Whether the sub-structure is empty.
Definition: LookupAttr.cc:459
zypp::sat::LookupAttr::iterator::subFind
iterator subFind(SolvAttr attr_r) const
Iterator pointing to the first occurance of SolvAttr attr_r in sub-structure.
Definition: LookupAttr.cc:497
zypp::sat::LookupAttr::iterator::increment
void increment()
Definition: LookupAttr.cc:765
zypp::sat::LookupAttr::iterator::asCheckSum
CheckSum asCheckSum() const
As CheckSum.
Definition: LookupAttr.cc:680
zypp::sat::LookupAttr::iterator::~iterator
~iterator()
Definition: LookupAttr.cc:737
zypp::sat::LookupAttr::iterator::solvAttrCheckSum
bool solvAttrCheckSum() const
Whether this is a CheckSum attribute.
Definition: LookupAttr.cc:422
zypp::sat::LookupAttr::iterator::asString
std::string asString() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: LookupAttr.cc:610
zypp::sat::LookupAttr::iterator::nextSkipSolvAttr
void nextSkipSolvAttr()
On the next call to operator++ advance to the next SolvAttr.
Definition: LookupAttr.cc:360
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:576
zypp::sat::LookupAttr::iterator::equal
bool equal(const boost::iterator_adaptor< OtherDerived, OtherIterator, V, C, R, D > &rhs) const
Definition: LookupAttr.h:554
zypp::sat::LookupAttr::iterator::subEnd
iterator subEnd() const
Iterator behind the end of a sub-structure.
Definition: LookupAttr.cc:492
zypp::sat::LookupAttr::iterator::get
detail::CDataiterator * get() const
Expert backdoor.
Definition: LookupAttr.h:568
zypp::sat::LookupAttr::iterator::skipSolvable
void skipSolvable()
Immediately advance to the next Solvable.
Definition: LookupAttr.h:375
zypp::sat::LookupAttr::iterator::stayInThisRepo
void stayInThisRepo()
Stop after all matches in the current Repository are processed.
Definition: LookupAttr.cc:372
zypp::sat::LookupAttr::iterator::solvAttrSubEntry
bool solvAttrSubEntry() const
Whether this is the entry to a sub-structure (flexarray).
Definition: LookupAttr.cc:452
zypp::sat::LookupAttr::iterator::inSolvable
Solvable inSolvable() const
The current Solvable.
Definition: LookupAttr.cc:354
zypp::sat::LookupAttr::iterator::_dip
detail::DIWrap _dip
Definition: LookupAttr.h:571
zypp::sat::LookupAttr::iterator::nextSkipRepo
void nextSkipRepo()
On the next call to operator++ advance to the next Repository.
Definition: LookupAttr.cc:366
zypp::sat::LookupAttr::iterator::c_str
const char * c_str() const
Conversion to string types.
Definition: LookupAttr.cc:580
zypp::sat::LookupAttr::iterator::subSize
size_type subSize() const
Ammount of attributes in the sub-structure.
Definition: LookupAttr.cc:462
zypp::sat::LookupAttr::iterator::operator=
iterator & operator=(const iterator &rhs)
Definition: LookupAttr.cc:740
zypp::sat::LookupAttr::iterator::solvAttrNumeric
bool solvAttrNumeric() const
Whether this is a numeric attribute (incl.
Definition: LookupAttr.cc:382
zypp::sat::LookupAttr::iterator::solvAttrIdString
bool solvAttrIdString() const
Whether this string attribute is available as IdString.
Definition: LookupAttr.cc:409
zypp::sat::LookupAttr::iterator::iterator_core_access
friend class boost::iterator_core_access
Definition: LookupAttr.h:551
zypp::sat::LookupAttr::iterator::dip_equal
bool dip_equal(const detail::CDataiterator &lhs, const detail::CDataiterator &rhs) const
Definition: LookupAttr.cc:752
zypp::sat::LookupAttr::iterator::solvAttrString
bool solvAttrString() const
Whether this is a string attribute.
Definition: LookupAttr.cc:394
zypp::sat::LookupAttr::iterator::solvAttrType
detail::IdType solvAttrType() const
The current SolvAttr type.
Definition: LookupAttr.cc:379
zypp::sat::LookupAttr::iterator::asInt
int asInt() const
Conversion to numeric types.
Definition: LookupAttr.cc:543
zypp::sat::LookupAttr::iterator::atEnd
bool atEnd() const
Whether this points to the end of a query (Iterator is invalid).
Definition: LookupAttr.h:401
zypp::sat::LookupAttr::iterator::inRepo
Repository inRepo() const
The current Repository.
Definition: LookupAttr.cc:351
zypp::sat::LookupAttr::iterator::skipSolvAttr
void skipSolvAttr()
Immediately advance to the next SolvAttr.
Definition: LookupAttr.h:371
zypp::sat::LookupAttr::iterator::skipRepo
void skipRepo()
Immediately advance to the next Repository.
Definition: LookupAttr.h:379
zypp::sat::LookupAttr
Lightweight attribute value lookup.
Definition: LookupAttr.h:108
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:239
zypp::sat::LookupAttr::_pimpl
RWCOW_pointer< Impl > _pimpl
Definition: LookupAttr.h:226
zypp::sat::LookupAttr::strMatcher
const StrMatcher & strMatcher() const
The pattern to match.
Definition: LookupAttr.cc:202
zypp::sat::LookupAttr::empty
bool empty() const
Whether the query is empty.
Definition: LookupAttr.cc:242
zypp::sat::LookupAttr::size_type
unsigned size_type
Definition: LookupAttr.h:113
zypp::sat::LookupAttr::Location
Location
Specify the where to look for the attribule.
Definition: LookupAttr.h:116
zypp::sat::LookupAttr::REPO_ATTR
@ REPO_ATTR
Search for repository attributes.
Definition: LookupAttr.h:118
zypp::sat::LookupAttr::SOLV_ATTR
@ SOLV_ATTR
Search for solvable attributes (default)
Definition: LookupAttr.h:117
zypp::sat::LookupAttr::setStrMatcher
void setStrMatcher(const StrMatcher &matcher_r)
Set the pattern to match.
Definition: LookupAttr.cc:205
zypp::sat::LookupAttr::repo
Repository repo() const
Whether to search in one Repository.
Definition: LookupAttr.cc:216
zypp::sat::LookupAttr::attr
SolvAttr attr() const
The SolvAttr to search.
Definition: LookupAttr.cc:196
zypp::sat::LookupAttr::parent
SolvAttr parent() const
Whether to search within a sub-structure (SolvAttr::noAttr if not)
Definition: LookupAttr.cc:228
zypp::sat::LookupAttr::setAttr
void setAttr(SolvAttr attr_r)
Set the SolvAttr to search.
Definition: LookupAttr.cc:199
zypp::sat::LookupAttr::setRepo
void setRepo(Repository repo_r, Location=SOLV_ATTR)
Set search in one Repository.
Definition: LookupAttr.cc:219
zypp::sat::LookupAttr::pool
bool pool() const
Whether to search in Pool.
Definition: LookupAttr.cc:210
zypp::sat::LookupAttr::size
size_type size() const
Ammount of results.
Definition: LookupAttr.cc:245
zypp::sat::LookupAttr::Exception
MatchException Exception
Definition: LookupAttr.h:110
zypp::sat::LookupAttr::begin
iterator begin() const
Iterator to the begin of query results.
Definition: LookupAttr.cc:236
zypp::sat::LookupAttr::setSolvable
void setSolvable(Solvable solv_r)
Set search in one Solvable.
Definition: LookupAttr.cc:225
zypp::sat::LookupAttr::solvable
Solvable solvable() const
Whether to search in one Solvable.
Definition: LookupAttr.cc:222
zypp::sat::LookupAttr::LookupAttr
LookupAttr()
Default ctor finds nothing.
Definition: LookupAttr.cc:168
zypp::sat::LookupAttr::setPool
void setPool(Location=SOLV_ATTR)
Set search in Pool (all repositories).
Definition: LookupAttr.cc:213
zypp::sat::LookupAttr::setParent
void setParent(SolvAttr attr_r)
Set search within a sub-structure (SolvAttr::noAttr for none)
Definition: LookupAttr.cc:231
zypp::sat::LookupRepoAttr
Lightweight repository attribute value lookup.
Definition: LookupAttr.h:258
zypp::sat::LookupRepoAttr::LookupRepoAttr
LookupRepoAttr(SolvAttr attr_r)
Definition: LookupAttr.h:264
zypp::sat::LookupRepoAttr::setRepo
void setRepo(Repository repo_r)
Set search in one Repository.
Definition: LookupAttr.cc:287
zypp::sat::LookupRepoAttr::LookupRepoAttr
LookupRepoAttr()
Default ctor finds nothing.
Definition: LookupAttr.h:261
zypp::sat::LookupRepoAttr::setPool
void setPool()
Set search in Pool (all repositories).
Definition: LookupAttr.h:272
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:293
zypp::sat::detail::DIWrap::_mstring
std::string _mstring
Definition: LookupAttr.h:336
zypp::sat::detail::DIWrap::get
detail::CDataiterator * get() const
Definition: LookupAttr.h:331
zypp::sat::detail::DIWrap::swap
void swap(DIWrap &rhs)
Definition: LookupAttr.h:308
zypp::sat::detail::DIWrap::reset
void reset()
Definition: LookupAttr.h:322
zypp::sat::detail::DIWrap::DIWrap
DIWrap()
NULL detail::CDataiterator
Definition: LookupAttr.h:296
zypp::sat::detail::DIWrap::~DIWrap
~DIWrap()
Definition: LookupAttr.cc:328
zypp::sat::detail::DIWrap::_dip
detail::CDataiterator * _dip
Definition: LookupAttr.h:335
zypp::sat::detail::DIWrap::getstr
const std::string & getstr() const
Definition: LookupAttr.h:332
zypp::sat::detail::DIWrap::operator->
detail::CDataiterator * operator->() const
Definition: LookupAttr.h:330
zypp::sat::detail::DIWrap::operator=
DIWrap & operator=(const DIWrap &rhs)
Definition: LookupAttr.h:316
str
String related utilities and Regular expression matching.
zypp::sat::detail::operator<<
std::ostream & operator<<(std::ostream &str, const DIWrap &obj)
Definition: LookupAttr.cc:337
zypp::sat::detail::CDataiterator
::s_Dataiterator CDataiterator
Wrapped libsolv C data type exposed as backdoor.
Definition: PoolMember.h:58
zypp::sat::detail::IdType
int IdType
Generic Id type.
Definition: PoolMember.h:104
zypp::sat::detail::SolvableIdType
unsigned SolvableIdType
Id type to connect Solvable and sat-solvable.
Definition: PoolMember.h:125
zypp::sat::detail::RepoIdType
CRepo * RepoIdType
Id type to connect Repo and sat-repo.
Definition: PoolMember.h:133
zypp::sat::dumpOn
std::ostream & dumpOn(std::ostream &str, const LocaleSupport &obj)
Definition: LocaleSupport.cc:41
zypp::sat::operator<<
std::ostream & operator<<(std::ostream &str, const FileConflicts &obj)
Definition: FileConflicts.cc:109
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
zypp::asString
std::string asString(const DefaultIntegral< Tp, TInitial > &obj)
Definition: DefaultIntegral.h:98
zypp::operator<<
std::ostream & operator<<(std::ostream &str, const Exception &obj)
Definition: Exception.cc:147
zypp::MatchException
Exceptions thrown from attribute matching.
Definition: StrMatcher.h:248
zypp::RWCOW_pointer
RW_pointer supporting 'copy on write' functionality.
Definition: PtrTypes.h:459