libzypp 17.32.5
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
22#include <zypp/sat/SolvAttr.h>
23
25namespace zypp
26{
27
28 class CheckSum;
29 class Match;
30 struct MatchException;
31 class StrMatcher;
32
34 namespace sat
35 {
36
38 //
39 // CLASS NAME : LookupAttr
40 //
109 {
110 public:
112
113 public:
114 using size_type = unsigned int;
115
117 enum Location {
119 REPO_ATTR = -1
120 };
121
122 public:
124 LookupAttr();
125
126 LookupAttr(const LookupAttr &) = default;
128 LookupAttr &operator=(const LookupAttr &) = default;
130
135
140
145
146 public:
151
153 iterator begin() const;
154
156 iterator end() const;
157
159 bool empty() const;
160
164 size_type size() const;
165
170
171 public:
175 SolvAttr attr() const;
176
178 void setAttr( SolvAttr attr_r );
180
192 const StrMatcher & strMatcher() const;
193
197 void setStrMatcher( const StrMatcher & matcher_r );
198
202
203 public:
207 bool pool() const;
208
210 void setPool( Location = SOLV_ATTR );
211
213 Repository repo() const;
214
217
219 Solvable solvable() const;
220
223
225 SolvAttr parent() const;
226
228 void setParent( SolvAttr attr_r );
230
231 private:
232 class Impl;
234 };
236
238 std::ostream & operator<<( std::ostream & str, const LookupAttr & obj );
239
241 std::ostream & dumpOn( std::ostream & str, const LookupAttr & obj );
242
244 //
245 // CLASS NAME : LookupRepoAttr
246 //
264 {
265 public:
271 : LookupAttr( std::move(attr_r), REPO_ATTR )
272 {}
275
276 public:
281 void setRepo( Repository repo_r );
282 private:
283 // Hide. You can't look inside and outside Solvables at the same time.
286 };
288
289 namespace detail
290 {
298 class DIWrap
299 {
300 public:
303 : _dip( 0 )
304 {}
307 std::string mstring_r = std::string(), int flags_r = 0 );
310 const char * mstring_r, int flags_r = 0 );
311 DIWrap( const DIWrap & rhs );
312 ~DIWrap();
313 public:
314 void swap( DIWrap & rhs ) noexcept
315 {
316 if ( &rhs != this ) // prevent self assign!
317 {
318 std::swap( _dip, rhs._dip );
319 std::swap( _mstring, rhs._mstring );
320 }
321 }
322 DIWrap & operator=( const DIWrap & rhs )
323 {
324 if ( &rhs != this ) // prevent self assign!
325 DIWrap( rhs ).swap( *this );
326 return *this;
327 }
328 void reset()
329 { DIWrap().swap( *this ); }
330 public:
332 explicit operator bool() const
333 { return _dip; }
334
335 public:
336 detail::CDataiterator * operator->() const { return _dip; }
337 detail::CDataiterator * get() const { return _dip; }
338 const std::string & getstr() const { return _mstring; }
339
340 private:
342 std::string _mstring;
343 };
345 std::ostream & operator<<( std::ostream & str, const DIWrap & obj );
346 }
347
349 //
350 // CLASS NAME : LookupAttr::iterator
351 //
356 class LookupAttr::iterator : public boost::iterator_adaptor<
357 iterator // Derived
358 , detail::CDataiterator * // Base
359 , detail::IdType // Value
360 , boost::forward_traversal_tag // CategoryOrTraversal
361 , detail::IdType // Reference
362 >
363 {
364 public:
368 void nextSkipSolvAttr();
369
371 void nextSkipSolvable();
372
374 void nextSkipRepo();
375
378 { nextSkipSolvAttr(); increment(); }
379
382 { nextSkipSolvable(); increment(); }
383
385 void skipRepo()
386 { nextSkipRepo(); increment(); }
387
389 void stayInThisSolvable();
390
392 void stayInThisRepo();
394
398 Repository inRepo() const;
399
401 Solvable inSolvable() const;
402
404 SolvAttr inSolvAttr() const;
405
407 bool atEnd() const
408 { return !_dip; }
410
414 detail::IdType solvAttrType() const;
415
417 bool solvAttrNumeric() const;
418
420 bool solvAttrString() const;
421
423 bool solvAttrIdString() const;
424
426 bool solvAttrCheckSum() const;
427
432 bool solvAttrSubEntry() const;
434
466 bool subEmpty() const;
467
471 size_type subSize() const;
472
476 iterator subBegin() const;
480 iterator subEnd() const;
485 iterator subFind( const SolvAttr& attr_r ) const;
493 iterator subFind( const C_Str & attrname_r ) const;
495
499 int asInt() const;
501 unsigned asUnsigned() const;
503 bool asBool() const;
505 unsigned long long asUnsignedLL() const;
506
508 const char * c_str() const;
513 std::string asString() const;
514
520 IdString idStr() const;
523 { return idStr().id(); }
524
526 CheckSum asCheckSum() const;
527
534 template<class Tp> Tp asType() const { return Tp(id()); }
536
538 // internal stuff below
540 public:
541 iterator();
542
543 iterator( const iterator & rhs );
544
545 iterator & operator=( const iterator & rhs );
546
547 ~iterator();
548
549 public:
555
556 private:
557 friend class boost::iterator_core_access;
558
559 template <class OtherDerived, class OtherIterator, class V, class C, class R, class D>
560 bool equal( const boost::iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> & rhs ) const
561 {
562 return ( bool(base()) == bool(rhs.base()) )
563 && ( ! base() || dip_equal( *base(), *rhs.base() ) );
564 }
565
566 bool dip_equal( const detail::CDataiterator & lhs, const detail::CDataiterator & rhs ) const;
567
568 detail::IdType dereference() const;
569
570 void increment();
571
572 public:
575 { return _dip.get(); }
576 private:
578 };
580
582 std::ostream & operator<<( std::ostream & str, const LookupAttr::iterator & obj );
583
585
588 template<> inline int LookupAttr::iterator::asType<int>() const { return asInt(); }
589 template<> inline unsigned LookupAttr::iterator::asType<unsigned>() const { return asUnsigned(); }
590 template<> inline unsigned long long LookupAttr::iterator::asType<unsigned long long>() const { return asUnsignedLL(); }
591 template<> inline bool LookupAttr::iterator::asType<bool>() const { return asBool(); }
592 template<> inline const char * LookupAttr::iterator::asType<const char *>() const { return c_str(); }
593 template<> inline std::string LookupAttr::iterator::asType<std::string>() const { return asString(); }
594 template<> inline IdString LookupAttr::iterator::asType<IdString>() const { return idStr(); }
595 template<> CheckSum LookupAttr::iterator::asType<CheckSum>() const;
596
597 template<class TResult, class TAttr>
598 class ArrayAttr;
600
602 } // namespace sat
605} // namespace zypp
607
609std::ostream & operator<<( std::ostream & str, const zypp::sat::detail::CDataiterator * obj );
610
612inline std::ostream & operator<<( std::ostream & str, const zypp::sat::detail::CDataiterator & obj )
613{ return str << &obj; }
614
615#endif // ZYPP_SAT_LOOKUPATTR_H
std::ostream & operator<<(std::ostream &str, const zypp::sat::detail::CDataiterator *obj)
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
Definition AutoDispose.h:95
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
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:574
detail::IdType id() const
Definition LookupAttr.h:522
Tp asType() const
Templated return type.
Definition LookupAttr.h:534
bool equal(const boost::iterator_adaptor< OtherDerived, OtherIterator, V, C, R, D > &rhs) const
Definition LookupAttr.h:560
void skipSolvable()
Immediately advance to the next Solvable.
Definition LookupAttr.h:381
bool atEnd() const
Whether this points to the end of a query (Iterator is invalid).
Definition LookupAttr.h:407
void skipSolvAttr()
Immediately advance to the next SolvAttr.
Definition LookupAttr.h:377
void skipRepo()
Immediately advance to the next Repository.
Definition LookupAttr.h:385
Lightweight attribute value lookup.
Definition LookupAttr.h:109
void resetStrMatcher()
Reset the pattern to match.
iterator end() const
Iterator behind the end of query results.
RWCOW_pointer< Impl > _pimpl
Definition LookupAttr.h:233
const StrMatcher & strMatcher() const
The pattern to match.
std::ostream & dumpOn(std::ostream &str, const LookupAttr &obj)
Verbose stream output including the query result.
bool empty() const
Whether the query is empty.
LookupAttr(LookupAttr &&) noexcept=default
Location
Specify the where to look for the attribule.
Definition LookupAttr.h:117
@ REPO_ATTR
Search for repository attributes.
Definition LookupAttr.h:119
@ SOLV_ATTR
Search for solvable attributes (default)
Definition LookupAttr.h:118
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(const LookupAttr &)=default
void setSolvable(Solvable solv_r)
Set search in one Solvable.
Solvable solvable() const
Whether to search in one Solvable.
std::ostream & operator<<(std::ostream &str, const LookupAttr &obj)
Stream output.
LookupAttr()
Default ctor finds nothing.
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:264
LookupRepoAttr(SolvAttr attr_r)
Definition LookupAttr.h:270
LookupRepoAttr()
Default ctor finds nothing.
Definition LookupAttr.h:267
void setPool()
Set search in Pool (all repositories).
Definition LookupAttr.h:278
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:299
void swap(DIWrap &rhs) noexcept
Definition LookupAttr.h:314
detail::CDataiterator * get() const
Definition LookupAttr.h:337
DIWrap & operator=(const DIWrap &rhs)
Definition LookupAttr.h:322
detail::CDataiterator * operator->() const
Definition LookupAttr.h:336
const std::string & getstr() const
Definition LookupAttr.h:338
DIWrap()
NULL detail::CDataiterator
Definition LookupAttr.h:302
detail::CDataiterator * _dip
Definition LookupAttr.h:341
Definition Arch.h:364
String related utilities and Regular expression matching.
int IdType
Generic Id type.
Definition PoolMember.h:104
::s_Dataiterator CDataiterator
Wrapped libsolv C data type exposed as backdoor.
Definition PoolMember.h:58
Easy-to use interface to the ZYPP dependency resolver.
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
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:468