b40a2d1a97f8a633fac2e2affb511bfd54c70036
[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
20 #include "zypp/Resolvable.h"
21 #include "zypp/solver/SolverFwd.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 ( const 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    * cpabilities 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 defaut Capability.
70   */
71   class Capability
72   {
73     /** Factory */
74     friend class CapFactory;
75
76     /** Ordering for use in CapSet */
77     friend class CapOrder;
78     friend bool operator==( const Capability & lhs, const Capability & rhs );
79     friend std::ostream & operator<<( std::ostream & str, const Capability & obj );
80
81   private:
82     typedef capability::CapabilityImpl          Impl;
83     typedef capability::CapabilityImpl_Ptr      Impl_Ptr ;
84     typedef capability::CapabilityImpl_constPtr Impl_constPtr;
85
86     /** Factory ctor */
87     explicit
88     Capability( Impl_Ptr impl_r );
89
90   public:
91     /** Factory */
92     typedef CapFactory Factory;
93
94     /** DefaultCtor creating a dummy Capability. */
95     Capability();
96
97     /** Dtor */
98     virtual ~Capability();
99
100   public:
101     /** Kind of Resolvable the Capability refers to. */
102     const Resolvable::Kind & refers() const;
103
104     /** More or less human readable representation as string. */
105     std::string asString() const;
106
107     /** */
108     bool matches( Resolvable::constPtr resolvable_r,
109                   solver::Context_constPtr solverContext_r ) const;
110
111     /**  \todo this does not make sense until ther's a default context available*/
112     bool matches( Resolvable::constPtr resolvable_r ) const;
113
114   private:
115     /** Pointer to implementation */
116     RW_pointer<Impl,Impl_Ptr> _pimpl;
117   };
118   ///////////////////////////////////////////////////////////////////
119
120   /** Ordering relation used by ::CapSet. */
121   struct CapOrder : public std::binary_function<Capability, Capability, bool>
122   {
123     bool operator()( const Capability & lhs, const Capability & rhs ) const
124     { return lhs._pimpl.get() < rhs._pimpl.get(); }
125   };
126
127   ///////////////////////////////////////////////////////////////////
128
129   /** \relates Capability  */
130   inline bool operator==( const Capability & lhs, const Capability & rhs )
131   { return lhs._pimpl.get() == rhs._pimpl.get(); }
132
133   /** \relates Capability  */
134   inline bool operator!=( const Capability & lhs, const Capability & rhs )
135   { return ! (lhs == rhs); }
136
137   /** \relates Capability Stream output */
138   extern std::ostream & operator<<( std::ostream & str, const Capability & obj );
139
140   /////////////////////////////////////////////////////////////////
141 } // namespace zypp
142 ///////////////////////////////////////////////////////////////////
143 #endif // ZYPP_CAPABILITY_H