1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/Capability.h
12 #ifndef ZYPP_CAPABILITY_H
13 #define ZYPP_CAPABILITY_H
18 #include "zypp/base/PtrTypes.h"
19 #include "zypp/capability/CapTraits.h"
20 #include "zypp/Resolvable.h"
21 #include "zypp/CapMatch.h"
23 ///////////////////////////////////////////////////////////////////
25 { /////////////////////////////////////////////////////////////////
26 ///////////////////////////////////////////////////////////////////
28 { /////////////////////////////////////////////////////////////////
29 DEFINE_PTR_TYPE(CapabilityImpl);
30 /////////////////////////////////////////////////////////////////
31 } // namespace capability
32 ///////////////////////////////////////////////////////////////////
36 ///////////////////////////////////////////////////////////////////
38 // CLASS NAME : Capability
40 /** Resolvable capabilitiy.
42 * Capability is created by a Factory class. Only a default ctor
43 * creating a dummy capability is provided.
48 * cap = CapFactory().parse( ResTraits<Patch>::kind,
51 * Edition( parsed.ver,
55 * catch ( Exception & excpt_r )
57 * ERR << excpt_r << endl;
58 * ... Or maybe just WAR, or ?
61 * \see CapFactory: Factory creating Capability.
63 * \invariant Nonzero \c _pimpl
64 * \invariant Unified \c _pimpl asserted by CapFactory.
66 * \todo Need a trival return from matches. E.g. Conditional
67 * capabilities must be able to indicate that they should be
68 * treated as if they were not present at all, if the precondition
69 * does no apply. Same for the default Capability.
73 /** Ordering for use in CapSet */
74 friend class CapOrder;
75 friend bool operator==( const Capability & lhs, const Capability & rhs );
76 friend std::ostream & operator<<( std::ostream & str, const Capability & obj );
80 typedef capability::CapabilityTraits::KindType Kind;
83 /** DefaultCtor creating \ref noCap. */
87 virtual ~Capability();
89 /** Constant representing no Capabiliy.
90 * It refers to no kind of Resolvable, and matches returns
91 * returns \c CapMatch::irrelevant.
93 static const Capability noCap;
96 /** Kind of Capability. */
97 const Kind & kind() const;
99 /** Kind of Resolvable the Capability refers to. */
100 const Resolvable::Kind & refers() const;
102 /** Whether to consider this Capability.
103 * Evaluates the Capabilities pre-condition (if any), and
104 * returns whether the condition applies. If not, the Capability
107 bool relevant() const;
109 /** Return whether the Capabilities match.
110 * If either Capability is not \ref relevant, CapMatch::irrelevant
113 CapMatch matches( const Capability & rhs ) const;
115 /** More or less human readable representation as string. */
116 std::string asString() const;
118 /** accessors needed by solver/zmd */
120 std::string index() const;
123 typedef capability::CapabilityImpl Impl;
124 typedef capability::CapabilityImpl_Ptr Impl_Ptr ;
125 typedef capability::CapabilityImpl_constPtr Impl_constPtr;
128 friend class CapFactory;
132 Capability( Impl_Ptr impl_r );
136 friend class capability::CapabilityImpl;
137 /** Pointer to implementation */
138 RW_pointer<Impl,rw_pointer::Intrusive<Impl> > _pimpl;
140 ///////////////////////////////////////////////////////////////////
143 inline bool isKind( const Capability & cap )
144 { return cap.kind() == capability::CapTraits<_Cap>::kind; }
146 ///////////////////////////////////////////////////////////////////
148 /** Ordering relation used by ::CapSet. */
149 struct CapOrder : public std::binary_function<Capability, Capability, bool>
151 bool operator()( const Capability & lhs, const Capability & rhs ) const
152 { return lhs._pimpl.get() < rhs._pimpl.get(); }
155 ///////////////////////////////////////////////////////////////////
157 /** \relates Capability */
158 inline bool operator==( const Capability & lhs, const Capability & rhs )
159 { return lhs._pimpl.get() == rhs._pimpl.get(); }
161 /** \relates Capability */
162 inline bool operator!=( const Capability & lhs, const Capability & rhs )
163 { return ! (lhs == rhs); }
165 /** \relates Capability Stream output */
166 extern std::ostream & operator<<( std::ostream & str, const Capability & obj );
168 /////////////////////////////////////////////////////////////////
170 ///////////////////////////////////////////////////////////////////
171 #endif // ZYPP_CAPABILITY_H