libzypp  10.5.0
LookupAttr.h
Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #ifndef ZYPP_SAT_LOOKUPATTR_H
00013 #define ZYPP_SAT_LOOKUPATTR_H
00014 
00015 extern "C"
00016 {
00017 struct _Dataiterator;
00018 }
00019 #include <iosfwd>
00020 
00021 #include "zypp/base/PtrTypes.h"
00022 #include "zypp/base/DefaultIntegral.h"
00023 
00024 #include "zypp/sat/detail/PoolMember.h"
00025 #include "zypp/sat/SolvAttr.h"
00026 
00028 namespace zypp
00029 { 
00030 
00031   class CheckSum;
00032   class Match;
00033   class MatchException;
00034 
00036   namespace sat
00037   { 
00038 
00039     class AttrMatcher;
00040 
00042     //
00043     //  CLASS NAME : LookupAttr
00044     //
00112     class LookupAttr
00113     {
00114       public:
00115         typedef MatchException Exception;
00116 
00117       public:
00118         typedef unsigned size_type;
00119 
00121         enum Location {
00122           SOLV_ATTR = 0,  
00123           REPO_ATTR = -1  
00124         };
00125 
00126       public:
00128         LookupAttr();
00129 
00131         explicit LookupAttr( SolvAttr attr_r, Location = SOLV_ATTR );
00133         LookupAttr( SolvAttr attr_r, SolvAttr parent_r, Location = SOLV_ATTR );
00134 
00136         LookupAttr( SolvAttr attr_r, Repository repo_r, Location = SOLV_ATTR );
00138         LookupAttr( SolvAttr attr_r, SolvAttr parent_r, Repository repo_r, Location = SOLV_ATTR );
00139 
00141         LookupAttr( SolvAttr attr_r, Solvable solv_r );
00143         LookupAttr( SolvAttr attr_r, SolvAttr parent_r, Solvable solv_r );
00144 
00145       public:
00149         class iterator;
00150 
00152         iterator begin() const;
00153 
00155         iterator end() const;
00156 
00158         bool empty() const;
00159 
00163         size_type size() const;
00164 
00166         template<class _ResultT, class _AttrT = _ResultT> class transformIterator;
00168 
00169       public:
00173         SolvAttr attr() const;
00174 
00176         void setAttr( SolvAttr attr_r );
00178 
00190         const AttrMatcher & attrMatcher() const;
00191 
00195         void setAttrMatcher( const AttrMatcher & matcher_r );
00196 
00198         void resetAttrMatcher();
00200 
00201       public:
00205         bool pool() const;
00206 
00208         void setPool( Location = SOLV_ATTR );
00209 
00211         Repository repo() const;
00212 
00214         void setRepo( Repository repo_r, Location = SOLV_ATTR );
00215 
00217         Solvable solvable() const;
00218 
00220         void setSolvable( Solvable solv_r );
00221 
00223         SolvAttr parent() const;
00224 
00226         void setParent( SolvAttr attr_r );
00228 
00229       private:
00230         class Impl;
00231         RWCOW_pointer<Impl> _pimpl;
00232     };
00234 
00236     std::ostream & operator<<( std::ostream & str, const LookupAttr & obj );
00237 
00239     std::ostream & dumpOn( std::ostream & str, const LookupAttr & obj );
00240 
00242     //
00243     //  CLASS NAME : LookupRepoAttr
00244     //
00261     class LookupRepoAttr : public LookupAttr
00262     {
00263       public:
00265         LookupRepoAttr()
00266         {}
00268         explicit LookupRepoAttr( SolvAttr attr_r )
00269         : LookupAttr( attr_r, REPO_ATTR )
00270         {}
00272         explicit LookupRepoAttr( SolvAttr attr_r, Repository repo_r );
00273 
00274       public:
00276         void setPool()
00277         { LookupAttr::setPool( REPO_ATTR ); }
00279         void setRepo( Repository repo_r );
00280       private:
00281         // Hide. You can't look inside and outside Solvables at the same time.
00282         using LookupAttr::solvable;
00283         using LookupAttr::setSolvable;
00284     };
00286 
00287     namespace detail
00288     {
00296       class DIWrap : private base::SafeBool<DIWrap>
00297       {
00298         public:
00300           DIWrap()
00301           : _dip( 0 )
00302           {}
00304           DIWrap( RepoIdType repoId_r, SolvableIdType solvId_r, IdType attrId_r,
00305                   const std::string & mstring_r = std::string(), int flags_r = 0 );
00307           DIWrap( RepoIdType repoId_r, SolvableIdType solvId_r, IdType attrId_r,
00308                   const char * mstring_r, int flags_r = 0 );
00309           DIWrap( const DIWrap & rhs );
00310           ~DIWrap();
00311         public:
00312           void swap( DIWrap & rhs )
00313           {
00314             if ( &rhs != this ) // prevent self assign!
00315             {
00316               std::swap( _dip, rhs._dip );
00317               std::swap( _mstring, rhs._mstring );
00318             }
00319           }
00320           DIWrap & operator=( const DIWrap & rhs )
00321           {
00322             if ( &rhs != this ) // prevent self assign!
00323               DIWrap( rhs ).swap( *this );
00324             return *this;
00325           }
00326           void reset()
00327           { DIWrap().swap( *this ); }
00328         public:
00329 #ifndef SWIG // Swig treats it as syntax error
00330 
00331           using base::SafeBool<DIWrap>::operator bool_type;
00332 #endif
00333         public:
00334           ::_Dataiterator * operator->() const  { return _dip; }
00335           ::_Dataiterator * get()        const  { return _dip; }
00336           const std::string & getstr()   const  { return _mstring; }
00337         private:
00338           friend base::SafeBool<DIWrap>::operator bool_type() const;
00339           bool boolTest() const
00340           { return _dip; }
00341         private:
00342           ::_Dataiterator * _dip;
00343           std::string _mstring;
00344       };
00346       std::ostream & operator<<( std::ostream & str, const DIWrap & obj );
00347     }
00348 
00350     //
00351     //  CLASS NAME : LookupAttr::iterator
00352     //
00357     class LookupAttr::iterator : public boost::iterator_adaptor<
00358         iterator                       // Derived
00359         , ::_Dataiterator *            // Base
00360         , detail::IdType               // Value
00361         , boost::forward_traversal_tag // CategoryOrTraversal
00362         , detail::IdType               // Reference
00363     >
00364     {
00365       public:
00369         void nextSkipSolvAttr();
00370 
00372         void nextSkipSolvable();
00373 
00375         void nextSkipRepo();
00376 
00378         void skipSolvAttr()
00379         { nextSkipSolvAttr(); increment(); }
00380 
00382         void skipSolvable()
00383         { nextSkipSolvable(); increment(); }
00384 
00386         void skipRepo()
00387         { nextSkipRepo(); increment(); }
00388 
00390         void stayInThisSolvable();
00391 
00393         void stayInThisRepo();
00395 
00399         Repository inRepo() const;
00400 
00402         Solvable inSolvable() const;
00403 
00405         SolvAttr inSolvAttr() const;
00406 
00408         bool atEnd() const
00409         { return !_dip; }
00411 
00415         detail::IdType solvAttrType() const;
00416 
00418         bool solvAttrNumeric() const;
00419 
00421         bool solvAttrString() const;
00422 
00424         bool solvAttrIdString() const;
00425 
00427         bool solvAttrCheckSum() const;
00428 
00433         bool solvAttrSubEntry() const;
00435 
00467         bool subEmpty() const;
00468 
00472         size_type subSize() const;
00473 
00477         iterator subBegin() const;
00481         iterator subEnd() const;
00486         iterator subFind( SolvAttr attr_r ) const;
00494         iterator subFind( const C_Str & attrname_r ) const;
00496 
00500         int asInt() const;
00502         unsigned asUnsigned() const;
00504         bool asBool() const;
00505 
00507         const char * c_str() const;
00512         std::string asString() const;
00513 
00519         IdString idStr() const;
00521         detail::IdType id() const
00522         { return idStr().id(); }
00523 
00525         CheckSum asCheckSum() const;
00526 
00533         template<class _Tp> _Tp asType() const { return _Tp(id()); }
00535 
00537         // internal stuff below
00539       public:
00540         iterator();
00541 
00542         iterator( const iterator & rhs );
00543 
00544         iterator & operator=( const iterator & rhs );
00545 
00546         ~iterator();
00547 
00548       public:
00553         iterator( detail::DIWrap & dip_r );
00554 
00555       private:
00556         friend class boost::iterator_core_access;
00557 
00558         template <class OtherDerived, class OtherIterator, class V, class C, class R, class D>
00559         bool equal( const boost::iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> & rhs ) const
00560         {
00561           return ( bool(base()) == bool(rhs.base()) )
00562               && ( ! base() || dip_equal( *base(), *rhs.base() ) );
00563         }
00564 
00565         bool dip_equal( const ::_Dataiterator & lhs, const ::_Dataiterator & rhs ) const;
00566 
00567         detail::IdType dereference() const;
00568 
00569         void increment();
00570 
00571       public:
00573         ::_Dataiterator * get() const
00574         { return _dip.get(); }
00575       private:
00576         detail::DIWrap _dip;
00577     };
00579 
00581     std::ostream & operator<<( std::ostream & str, const LookupAttr::iterator & obj );
00582 
00584 
00587     template<> inline int          LookupAttr::iterator::asType<int>()          const { return asInt(); }
00588     template<> inline unsigned     LookupAttr::iterator::asType<unsigned>()     const { return asUnsigned(); }
00589     template<> inline bool         LookupAttr::iterator::asType<bool>()         const { return asBool(); }
00590     template<> inline const char * LookupAttr::iterator::asType<const char *>() const { return c_str(); }
00591     template<> inline std::string  LookupAttr::iterator::asType<std::string>()  const { return asString(); }
00592     template<> inline IdString     LookupAttr::iterator::asType<IdString>()     const { return idStr(); }
00593     template<>        CheckSum     LookupAttr::iterator::asType<CheckSum>()     const;
00594 
00595     template<class _ResultT, class _AttrT>
00596     class ArrayAttr;
00598 
00600   } // namespace sat
00603 } // namespace zypp
00605 
00607 std::ostream & operator<<( std::ostream & str, const ::_Dataiterator * obj );
00608 
00610 inline std::ostream & operator<<( std::ostream & str, const ::_Dataiterator & obj )
00611 { return str << &obj; }
00612 
00613 #endif // ZYPP_SAT_LOOKUPATTR_H