Enabled use of ResTraits. Currently they define the
[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/SolverContextFwd.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    * \invariant Nonzero \c _pimpl
42    * \invariant Unified \c _pimpl asserted by CapFactory
43   */
44   class Capability
45   {
46     /** Factory */
47     friend class CapFactory;
48     /** Ordering for use in std::container */
49     friend class CapOrder;
50     friend bool operator==( const Capability & lhs, const Capability & rhs );
51   private:
52     typedef capability::CapabilityImplPtr      ImplPtr;
53     typedef capability::constCapabilityImplPtr constImplPtr;
54    /** Factory ctor */
55     explicit
56     Capability( ImplPtr impl_r );
57   public:
58     /** Factory */
59     typedef CapFactory Factory;
60     /** Dtor */
61     virtual ~Capability();
62
63   public:
64     /**  */
65     const ResKind & refers() const;
66     /**  */
67     std::string asString() const;
68     /**  */
69     bool matches( Resolvable::constPtr resolvable_r,
70                   const SolverContext & colverContext_r ) const;
71     /**  */
72     bool matches( Resolvable::constPtr resolvable_r ) const;
73
74   private:
75     /** Pointer to implementation */
76     ImplPtr _pimpl;
77   public:
78     /** Avoid a bunch of friend decl. */
79     constImplPtr sayFriend() const;
80   };
81   ///////////////////////////////////////////////////////////////////
82
83   struct CapOrder : public std::binary_function<Capability, Capability, bool>
84   {
85     bool operator()( const Capability & lhs, const Capability & rhs ) const
86     { return lhs._pimpl < rhs._pimpl; }
87   };
88
89   ///////////////////////////////////////////////////////////////////
90
91   /** \relates Capability  */
92   inline bool operator==( const Capability & lhs, const Capability & rhs )
93   { return lhs._pimpl == rhs._pimpl; }
94
95   /** \relates Capability  */
96   inline bool operator!=( const Capability & lhs, const Capability & rhs )
97   { return ! (lhs == rhs); }
98
99   /** \relates Capability Stream output */
100   extern std::ostream & operator<<( std::ostream & str, const Capability & obj );
101
102   /////////////////////////////////////////////////////////////////
103 } // namespace zypp
104 ///////////////////////////////////////////////////////////////////
105 #endif // ZYPP_CAPABILITY_H