libzypp 17.31.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
17#include <zypp/base/PtrTypes.h>
18#include <zypp-core/base/DefaultIntegral>
19
21#include <zypp/sat/SolvAttr.h>
22
24namespace 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 //
108 {
109 public:
111
112 public:
113 typedef unsigned size_type;
114
116 enum Location {
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
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;
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 //
258 {
259 public:
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()
275 void setRepo( Repository repo_r );
276 private:
277 // Hide. You can't look inside and outside Solvables at the same time.
280 };
282
283 namespace detail
284 {
292 class DIWrap
293 {
294 public:
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:
331 detail::CDataiterator * get() const { return _dip; }
332 const std::string & getstr() const { return _mstring; }
333
334 private:
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
373
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
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;
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:
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
563
564 void increment();
565
566 public:
569 { return _dip.get(); }
570 private:
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
603std::ostream & operator<<( std::ostream & str, const zypp::sat::detail::CDataiterator * obj );
604
606inline std::ostream & operator<<( std::ostream & str, const zypp::sat::detail::CDataiterator & obj )
607{ return str << &obj; }
608
609#endif // ZYPP_SAT_LOOKUPATTR_H
Convenience char* constructible from std::string and char*, it maps (char*)0 to an empty string.
Definition: String.h:91
Access to the sat-pools string space.
Definition: IdString.h:43
IdType id() const
Expert backdoor.
Definition: IdString.h:122
String matching (STRING|SUBSTRING|GLOB|REGEX).
Definition: StrMatcher.h:298
LookupAttr implememtation.
Definition: LookupAttr.cc:56
detail::CDataiterator * get() const
Expert backdoor.
Definition: LookupAttr.h:568
iterator subBegin() const
Iterator to the begin of a sub-structure.
Definition: LookupAttr.cc:470
detail::IdType id() const
Definition: LookupAttr.h:516
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
unsigned asUnsigned() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: LookupAttr.cc:558
void stayInThisSolvable()
Stop after all matches in the current Solvable are processed.
Definition: LookupAttr.cc:369
Tp asType() const
Templated return type.
Definition: LookupAttr.h:528
IdString idStr() const
As IdStr.
Definition: LookupAttr.cc:664
detail::IdType dereference() const
Definition: LookupAttr.cc:759
void nextSkipSolvable()
On the next call to operator++ advance to the next Solvable.
Definition: LookupAttr.cc:363
SolvAttr inSolvAttr() const
The current SolvAttr.
Definition: LookupAttr.cc:357
bool subEmpty() const
Whether the sub-structure is empty.
Definition: LookupAttr.cc:459
iterator subFind(SolvAttr attr_r) const
Iterator pointing to the first occurance of SolvAttr attr_r in sub-structure.
Definition: LookupAttr.cc:497
CheckSum asCheckSum() const
As CheckSum.
Definition: LookupAttr.cc:680
bool solvAttrCheckSum() const
Whether this is a CheckSum attribute.
Definition: LookupAttr.cc:422
std::string asString() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: LookupAttr.cc:610
void nextSkipSolvAttr()
On the next call to operator++ advance to the next SolvAttr.
Definition: LookupAttr.cc:360
bool asBool() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: LookupAttr.cc:576
bool equal(const boost::iterator_adaptor< OtherDerived, OtherIterator, V, C, R, D > &rhs) const
Definition: LookupAttr.h:554
iterator subEnd() const
Iterator behind the end of a sub-structure.
Definition: LookupAttr.cc:492
void skipSolvable()
Immediately advance to the next Solvable.
Definition: LookupAttr.h:375
void stayInThisRepo()
Stop after all matches in the current Repository are processed.
Definition: LookupAttr.cc:372
bool solvAttrSubEntry() const
Whether this is the entry to a sub-structure (flexarray).
Definition: LookupAttr.cc:452
Solvable inSolvable() const
The current Solvable.
Definition: LookupAttr.cc:354
void nextSkipRepo()
On the next call to operator++ advance to the next Repository.
Definition: LookupAttr.cc:366
const char * c_str() const
Conversion to string types.
Definition: LookupAttr.cc:580
size_type subSize() const
Ammount of attributes in the sub-structure.
Definition: LookupAttr.cc:462
iterator & operator=(const iterator &rhs)
Definition: LookupAttr.cc:740
bool solvAttrNumeric() const
Whether this is a numeric attribute (incl.
Definition: LookupAttr.cc:382
bool solvAttrIdString() const
Whether this string attribute is available as IdString.
Definition: LookupAttr.cc:409
friend class boost::iterator_core_access
Definition: LookupAttr.h:551
bool dip_equal(const detail::CDataiterator &lhs, const detail::CDataiterator &rhs) const
Definition: LookupAttr.cc:752
bool solvAttrString() const
Whether this is a string attribute.
Definition: LookupAttr.cc:394
detail::IdType solvAttrType() const
The current SolvAttr type.
Definition: LookupAttr.cc:379
int asInt() const
Conversion to numeric types.
Definition: LookupAttr.cc:543
bool atEnd() const
Whether this points to the end of a query (Iterator is invalid).
Definition: LookupAttr.h:401
Repository inRepo() const
The current Repository.
Definition: LookupAttr.cc:351
void skipSolvAttr()
Immediately advance to the next SolvAttr.
Definition: LookupAttr.h:371
void skipRepo()
Immediately advance to the next Repository.
Definition: LookupAttr.h:379
Lightweight attribute value lookup.
Definition: LookupAttr.h:108
void resetStrMatcher()
Reset the pattern to match.
iterator end() const
Iterator behind the end of query results.
Definition: LookupAttr.cc:239
RWCOW_pointer< Impl > _pimpl
Definition: LookupAttr.h:226
const StrMatcher & strMatcher() const
The pattern to match.
Definition: LookupAttr.cc:202
bool empty() const
Whether the query is empty.
Definition: LookupAttr.cc:242
Location
Specify the where to look for the attribule.
Definition: LookupAttr.h:116
@ REPO_ATTR
Search for repository attributes.
Definition: LookupAttr.h:118
@ SOLV_ATTR
Search for solvable attributes (default)
Definition: LookupAttr.h:117
void setStrMatcher(const StrMatcher &matcher_r)
Set the pattern to match.
Definition: LookupAttr.cc:205
Repository repo() const
Whether to search in one Repository.
Definition: LookupAttr.cc:216
SolvAttr attr() const
The SolvAttr to search.
Definition: LookupAttr.cc:196
SolvAttr parent() const
Whether to search within a sub-structure (SolvAttr::noAttr if not)
Definition: LookupAttr.cc:228
void setAttr(SolvAttr attr_r)
Set the SolvAttr to search.
Definition: LookupAttr.cc:199
void setRepo(Repository repo_r, Location=SOLV_ATTR)
Set search in one Repository.
Definition: LookupAttr.cc:219
bool pool() const
Whether to search in Pool.
Definition: LookupAttr.cc:210
size_type size() const
Ammount of results.
Definition: LookupAttr.cc:245
MatchException Exception
Definition: LookupAttr.h:110
iterator begin() const
Iterator to the begin of query results.
Definition: LookupAttr.cc:236
void setSolvable(Solvable solv_r)
Set search in one Solvable.
Definition: LookupAttr.cc:225
Solvable solvable() const
Whether to search in one Solvable.
Definition: LookupAttr.cc:222
LookupAttr()
Default ctor finds nothing.
Definition: LookupAttr.cc:168
void setPool(Location=SOLV_ATTR)
Set search in Pool (all repositories).
Definition: LookupAttr.cc:213
void setParent(SolvAttr attr_r)
Set search within a sub-structure (SolvAttr::noAttr for none)
Definition: LookupAttr.cc:231
Lightweight repository attribute value lookup.
Definition: LookupAttr.h:258
LookupRepoAttr(SolvAttr attr_r)
Definition: LookupAttr.h:264
void setRepo(Repository repo_r)
Set search in one Repository.
Definition: LookupAttr.cc:287
LookupRepoAttr()
Default ctor finds nothing.
Definition: LookupAttr.h:261
void setPool()
Set search in Pool (all repositories).
Definition: LookupAttr.h:272
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:293
detail::CDataiterator * get() const
Definition: LookupAttr.h:331
DIWrap & operator=(const DIWrap &rhs)
Definition: LookupAttr.h:316
detail::CDataiterator * operator->() const
Definition: LookupAttr.h:330
const std::string & getstr() const
Definition: LookupAttr.h:332
void swap(DIWrap &rhs)
Definition: LookupAttr.h:308
DIWrap()
NULL detail::CDataiterator
Definition: LookupAttr.h:296
detail::CDataiterator * _dip
Definition: LookupAttr.h:335
String related utilities and Regular expression matching.
::s_Dataiterator CDataiterator
Wrapped libsolv C data type exposed as backdoor.
Definition: PoolMember.h:58
int IdType
Generic Id type.
Definition: PoolMember.h:104
std::ostream & operator<<(std::ostream &str, const DIWrap &obj)
Definition: LookupAttr.cc:337
unsigned SolvableIdType
Id type to connect Solvable and sat-solvable.
Definition: PoolMember.h:125
CRepo * RepoIdType
Id type to connect Repo and sat-repo.
Definition: PoolMember.h:133
std::ostream & operator<<(std::ostream &str, const FileConflicts &obj)
std::ostream & dumpOn(std::ostream &str, const LocaleSupport &obj)
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
Definition: SerialNumber.cc:52
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:459