CapabilityImpl.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #ifndef ZYPP_CAPABILITY_CAPABILITYIMPL_H
00013 #define ZYPP_CAPABILITY_CAPABILITYIMPL_H
00014 
00015 #include "zypp/base/ReferenceCounted.h"
00016 #include "zypp/base/NonCopyable.h"
00017 
00018 #include "zypp/Capability.h"
00019 #include "zypp/Resolvable.h"
00020 #include "zypp/CapMatch.h"
00021 
00023 namespace zypp
00024 { 
00025 
00026   namespace capability
00027   { 
00028     DEFINE_PTR_TYPE(CapabilityImpl)
00029 
00030 
00031     
00032     //
00033     //  CLASS NAME : CapabilityImpl
00034     //
00066     class CapabilityImpl : public base::ReferenceCounted, private base::NonCopyable
00067     {
00068     public:
00069       typedef CapabilityImpl           Self;
00070       typedef CapabilityImpl_Ptr       Ptr;
00071       typedef CapabilityImpl_constPtr  constPtr;
00072 
00073       typedef CapabilityTraits::KindType  Kind;
00074 
00075     public:
00077       virtual const Kind & kind() const = 0;
00078 
00080       const Resolvable::Kind & refers() const
00081       { return _refers; }
00082 
00084       virtual bool relevant() const
00085       { return true; }
00086 
00090       virtual CapMatch matches( const constPtr & rhs ) const = 0;
00091 
00096       virtual std::string encode() const = 0;
00097 
00102       virtual std::string asString() const
00103       { return encode(); }
00104 
00110       virtual std::string index() const
00111       { return encode(); }
00112 
00113     public:
00115       struct SplitInfo
00116       {
00117         std::string name;
00118         std::string path;
00119       };
00121       static SplitInfo getSplitInfo( const Capability & cap );
00122 
00124       static constPtr backdoor( const Capability & cap )
00125       { return cap._pimpl.getPtr(); }
00126 
00127     protected:
00129       CapabilityImpl( const Resolvable::Kind & refers_r );
00130 
00131     protected: // Match helpers
00132       bool sameKind( const constPtr & rhs ) const
00133       { return kind() == rhs->kind(); }
00134 
00135       bool sameRefers( const constPtr & rhs ) const
00136       { return _refers == rhs->_refers; }
00137 
00138       bool sameKindAndRefers( const constPtr & rhs ) const
00139       { return sameKind( rhs ) && sameRefers( rhs ); }
00140 
00141     protected:
00143       virtual std::ostream & dumpOn( std::ostream & str ) const;
00144 
00145     private:
00147       Resolvable::Kind _refers;
00148 
00149     private:
00150       friend struct CapImplOrder;
00158       virtual bool capImplOrderLess( const constPtr & rhs ) const;
00159     };
00161 
00171     bool isEditionSpec( Rel op_r, const Edition & edition_r );
00172 
00174     bool isFileSpec( const std::string & name_r );
00175 
00181     bool isInterestingFileSpec( const std::string & name_r );
00182 
00184     bool isSplitSpec( const std::string & name_r );
00185 
00187     bool isHalSpec( const std::string & name_r );
00188 
00190     bool isModaliasSpec( const std::string & name_r );
00191 
00193     bool isFilesystemSpec( const std::string & name_r );
00194 
00201     CapabilityImpl::Ptr buildFile( const Resolvable::Kind & refers_r,
00202                                    const std::string & name_r );
00203 
00210     CapabilityImpl::Ptr buildNamed( const Resolvable::Kind & refers_r,
00211                                     const std::string & name_r );
00212 
00221     CapabilityImpl::Ptr buildVersioned( const Resolvable::Kind & refers_r,
00222                                         const std::string & name_r,
00223                                         Rel op_r,
00224                                         const Edition & edition_r );
00225 
00234     CapabilityImpl::Ptr buildHal( const Resolvable::Kind & refers_r,
00235                                   const std::string & name_r,
00236                                   Rel op_r = Rel::ANY,
00237                                   const std::string & value_r = std::string() );
00238 
00247     CapabilityImpl::Ptr buildModalias( const Resolvable::Kind & refers_r,
00248                                        const std::string & name_r,
00249                                        Rel op_r = Rel::ANY,
00250                                        const std::string & value_r = std::string() );
00251 
00260     CapabilityImpl::Ptr buildFilesystem( const Resolvable::Kind & refers_r,
00261                                          const std::string & name_r );
00262 
00264 
00265     CapabilityImpl::Ptr parse( const Resolvable::Kind & refers_r,
00266                                const std::string & strval_r );
00267 
00268     CapabilityImpl::Ptr parse( const Resolvable::Kind & refers_r,
00269                                const std::string & name_r,
00270                                const std::string & op_r,
00271                                const std::string & edition_r );
00272 
00273     CapabilityImpl::Ptr parse( const Resolvable::Kind & refers_r,
00274                                const std::string & name_r,
00275                                Rel op_r,
00276                                const Edition & edition_r );
00277 
00283     template<class _Cap>
00284       inline bool isKind( const CapabilityImpl::constPtr & cap )
00285       { return cap && cap->kind() == CapTraits<_Cap>::kind; }
00286 
00288     template<class _Cap>
00289       inline intrusive_ptr<const _Cap> asKind( const CapabilityImpl::constPtr & cap )
00290       { return dynamic_pointer_cast<const _Cap>(cap); }
00291 
00293     template<class _Cap>
00294       inline intrusive_ptr<_Cap> asKind( const CapabilityImpl::Ptr & cap )
00295       { return dynamic_pointer_cast<_Cap>(cap); }
00296 
00298     template<class _Cap>
00299       inline intrusive_ptr<const _Cap> asKind( const Capability & cap )
00300       { return dynamic_pointer_cast<const _Cap>( CapabilityImpl::backdoor(cap) ); }
00301 
00303 
00305     struct CapImplOrder : public std::binary_function<CapabilityImpl::constPtr, CapabilityImpl::constPtr, bool>
00306     {
00308       bool operator()( const CapabilityImpl::constPtr & lhs,
00309                        const CapabilityImpl::constPtr & rhs ) const
00310       {
00311         if ( lhs->refers() != rhs->refers() )
00312           return lhs->refers() < rhs->refers();
00313         if ( lhs->kind() != rhs->kind() )
00314           return lhs->kind() < rhs->kind();
00315         return lhs->capImplOrderLess( rhs );
00316       }
00317     };
00318 
00319     typedef std::set<CapabilityImpl::Ptr> CapabilityImplPtrSet;
00320 
00322   } // namespace capability
00325 } // namespace zypp
00327 #endif // ZYPP_CAPABILITY_CAPABILITYIMPL_H

Generated on Tue Sep 25 19:23:00 2007 for libzypp by  doxygen 1.5.3