- fixed some typos
[platform/upstream/libzypp.git] / zypp / Capability.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/Capability.h
10  *
11 */
12 #ifndef ZYPP_CAPABILITY_H
13 #define ZYPP_CAPABILITY_H
14
15 #include <iosfwd>
16 #include <functional>
17
18 #include "zypp/base/PtrTypes.h"
19 #include "zypp/capability/CapTraits.h"
20 #include "zypp/Resolvable.h"
21 #include "zypp/CapMatch.h"
22
23 ///////////////////////////////////////////////////////////////////
24 namespace zypp
25 { /////////////////////////////////////////////////////////////////
26   ///////////////////////////////////////////////////////////////////
27   namespace capability
28   { /////////////////////////////////////////////////////////////////
29     DEFINE_PTR_TYPE(CapabilityImpl);
30     /////////////////////////////////////////////////////////////////
31   } // namespace capability
32   ///////////////////////////////////////////////////////////////////
33
34   class CapFactory;
35
36   ///////////////////////////////////////////////////////////////////
37   //
38   //    CLASS NAME : Capability
39   //
40   /** Resolvable capabilitiy.
41    *
42    * Capability is created by a Factory class. Only a default ctor
43    * creating a dummy capability is provided.
44    * \code
45    *   Capability cap;
46    *   try
47    *     {
48    *       cap = CapFactory().parse( ResTraits<Patch>::kind,
49    *                                 parsed.name,
50    *                                 parsed.op,
51    *                                 Edition( parsed.ver,
52    *                                          parsed.rel,
53    *                                          parsed.epoch ) );
54    *     }
55    *   catch ( Exception & excpt_r )
56    *     {
57    *       ERR << excpt_r << endl;
58    *       ... Or maybe just WAR, or ?
59    *     }
60    * \endcode
61    * \see CapFactory: Factory creating Capability.
62    *
63    * \invariant Nonzero \c _pimpl
64    * \invariant Unified \c _pimpl asserted by CapFactory.
65    *
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.
70   */
71   class Capability
72   {
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 );
77
78   public:
79     /** */
80     typedef capability::CapabilityTraits::KindType  Kind;
81
82   public:
83     /** DefaultCtor creating \ref noCap. */
84     Capability();
85
86     /** Dtor */
87     virtual ~Capability();
88
89     /** Constant representing no Capabiliy.
90      * It refers to no kind of Resolvable, and matches returns
91      *  returns \c CapMatch::irrelevant.
92     */
93     static const Capability noCap;
94
95   public:
96     /** Kind of Capability.  */
97     const Kind & kind() const;
98
99     /** Kind of Resolvable the Capability refers to. */
100     const Resolvable::Kind & refers() const;
101
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
105      * is to be ignored.
106     */
107     bool relevant() const;
108
109     /** Return whether the Capabilities match.
110      * If either Capability is not \ref relevant, CapMatch::irrelevant
111      * is returned.
112     */
113     CapMatch matches( const Capability & rhs ) const;
114
115     /** More or less human readable representation as string. */
116     std::string asString() const;
117
118     /** accessors needed by solver/zmd  */
119     /** Deprecated */
120     std::string index() const;
121
122   private:
123     typedef capability::CapabilityImpl          Impl;
124     typedef capability::CapabilityImpl_Ptr      Impl_Ptr ;
125     typedef capability::CapabilityImpl_constPtr Impl_constPtr;
126
127     /** Factory */
128     friend class CapFactory;
129
130     /** Factory ctor */
131     explicit
132     Capability( Impl_Ptr impl_r );
133
134   private:
135     /** */
136     friend class capability::CapabilityImpl;
137     /** Pointer to implementation */
138     RW_pointer<Impl,rw_pointer::Intrusive<Impl> > _pimpl;
139   };
140   ///////////////////////////////////////////////////////////////////
141
142   template<class _Cap>
143     inline bool isKind( const Capability & cap )
144     { return cap.kind() == capability::CapTraits<_Cap>::kind; }
145
146   ///////////////////////////////////////////////////////////////////
147
148   /** Ordering relation used by ::CapSet. */
149   struct CapOrder : public std::binary_function<Capability, Capability, bool>
150   {
151     bool operator()( const Capability & lhs, const Capability & rhs ) const
152     { return lhs._pimpl.get() < rhs._pimpl.get(); }
153   };
154
155   ///////////////////////////////////////////////////////////////////
156
157   /** \relates Capability  */
158   inline bool operator==( const Capability & lhs, const Capability & rhs )
159   { return lhs._pimpl.get() == rhs._pimpl.get(); }
160
161   /** \relates Capability  */
162   inline bool operator!=( const Capability & lhs, const Capability & rhs )
163   { return ! (lhs == rhs); }
164
165   /** \relates Capability Stream output */
166   extern std::ostream & operator<<( std::ostream & str, const Capability & obj );
167
168   /////////////////////////////////////////////////////////////////
169 } // namespace zypp
170 ///////////////////////////////////////////////////////////////////
171 #endif // ZYPP_CAPABILITY_H