1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/capability/CapabilityImpl.h
12 #ifndef ZYPP_CAPABILITY_CAPABILITYIMPL_H
13 #define ZYPP_CAPABILITY_CAPABILITYIMPL_H
15 #include "zypp/base/ReferenceCounted.h"
16 #include "zypp/base/NonCopyable.h"
17 #include "zypp/base/KindOf.h"
19 #include "zypp/Resolvable.h" // maybe ResTraits are sufficient?
20 #include "zypp/solver/SolverFwd.h"
22 ///////////////////////////////////////////////////////////////////
24 { /////////////////////////////////////////////////////////////////
25 ///////////////////////////////////////////////////////////////////
27 { /////////////////////////////////////////////////////////////////
28 DEFINE_PTR_TYPE(CapabilityImpl)
30 ///////////////////////////////////////////////////////////////////
32 // CLASS NAME : CapabilityImpl
34 /** Abstract base for Capability implementations. */
35 class CapabilityImpl : public base::ReferenceCounted, private base::NonCopyable
38 typedef CapabilityImpl Self;
39 typedef CapabilityImpl_Ptr Ptr;
40 typedef CapabilityImpl_constPtr constPtr;
42 typedef KindOf<Capability> Kind;
45 /** Ctor taking the kind of Resolvable \c this refers to.*/
46 CapabilityImpl( const Resolvable::Kind & refers_r );
49 /** Kind of capabiliy. */
50 virtual const Kind & kind() const = 0;
52 /** Kind of Resolvable \c this refers to. */
53 const Resolvable::Kind & refers() const
56 /** More or less human readable representation as string. */
57 virtual std::string asString() const = 0;
60 virtual bool matches( Resolvable::constPtr resolvable_r,
61 solver::Context_constPtr solverContext_r ) const = 0;
64 /** Helper for stream output. */
65 virtual std::ostream & dumpOn( std::ostream & str ) const;
68 /** Kind of Resolvable \c this refers to. */
69 Resolvable::Kind _refers;
72 friend struct CapImplOrder;
73 /** Helper for CapImplOrder to define an order relation.
74 * \invariant CapImplOrder asserts that \a rhs \c refers
75 * and \c kind values are equal to \c this. Implementation
76 * may concentrate on the remaining values.
78 * \todo make it pure virt?
80 virtual bool capImplOrderLess( const CapabilityImpl::constPtr & rhs ) const; // = 0;
82 ///////////////////////////////////////////////////////////////////
84 /** Ordering relation used by ::CapFactory to unify CapabilityImpl. */
85 struct CapImplOrder : public std::binary_function<CapabilityImpl::constPtr, CapabilityImpl::constPtr, bool>
88 bool operator()( const CapabilityImpl::constPtr & lhs,
89 const CapabilityImpl::constPtr & rhs ) const
91 if ( lhs->refers() != rhs->refers() )
92 return lhs->refers() < rhs->refers();
93 if ( lhs->kind() != rhs->kind() )
94 return lhs->kind() < rhs->kind();
95 return lhs->capImplOrderLess( rhs );
99 /////////////////////////////////////////////////////////////////
100 } // namespace capability
101 ///////////////////////////////////////////////////////////////////
102 /////////////////////////////////////////////////////////////////
104 ///////////////////////////////////////////////////////////////////
105 #endif // ZYPP_CAPABILITY_CAPABILITYIMPL_H