a7c0e0ee57ae351759824b3819e37dc52b9e6dd8
[platform/upstream/libzypp.git] / zypp / capability / CapabilityImpl.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/capability/CapabilityImpl.h
10  *
11 */
12 #ifndef ZYPP_CAPABILITY_CAPABILITYIMPL_H
13 #define ZYPP_CAPABILITY_CAPABILITYIMPL_H
14
15 #include "zypp/base/ReferenceCounted.h"
16 #include "zypp/base/NonCopyable.h"
17 #include "zypp/base/KindOf.h"
18
19 #include "zypp/Resolvable.h" // maybe ResTraits are sufficient?
20 #include "zypp/solver/SolverFwd.h"
21
22 ///////////////////////////////////////////////////////////////////
23 namespace zypp
24 { /////////////////////////////////////////////////////////////////
25   ///////////////////////////////////////////////////////////////////
26   namespace capability
27   { /////////////////////////////////////////////////////////////////
28     DEFINE_PTR_TYPE(CapabilityImpl)
29
30     ///////////////////////////////////////////////////////////////////
31     //
32     //  CLASS NAME : CapabilityImpl
33     //
34     /** Abstract base for Capability implementations. */
35     class CapabilityImpl : public base::ReferenceCounted, private base::NonCopyable
36     {
37     public:
38       typedef CapabilityImpl           Self;
39       typedef CapabilityImpl_Ptr       Ptr;
40       typedef CapabilityImpl_constPtr  constPtr;
41
42       typedef KindOf<Capability> Kind;
43
44     public:
45       /** Ctor taking the kind of Resolvable \c this refers to.*/
46       CapabilityImpl( const Resolvable::Kind & refers_r );
47
48     public:
49       /** Kind of capabiliy.  */
50       virtual const Kind & kind() const = 0;
51
52       /** Kind of Resolvable \c this refers to. */
53       const Resolvable::Kind & refers() const
54       { return _refers; }
55
56       /** More or less human readable representation as string. */
57       virtual std::string asString() const = 0;
58
59       /**  */
60       virtual bool matches( Resolvable::constPtr resolvable_r,
61                             solver::Context_constPtr solverContext_r ) const = 0;
62
63     protected:
64       /** Helper for stream output. */
65       virtual std::ostream & dumpOn( std::ostream & str ) const;
66
67     private:
68       /** Kind of Resolvable \c this refers to. */
69       Resolvable::Kind _refers;
70
71     private:
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.
77        *
78        * \todo make it pure virt?
79       */
80       virtual bool capImplOrderLess( const CapabilityImpl::constPtr & rhs ) const; // = 0;
81     };
82     ///////////////////////////////////////////////////////////////////
83
84     /** Ordering relation used by ::CapFactory to unify CapabilityImpl. */
85     struct CapImplOrder : public std::binary_function<CapabilityImpl::constPtr, CapabilityImpl::constPtr, bool>
86     {
87       /** */
88       bool operator()( const CapabilityImpl::constPtr & lhs,
89                        const CapabilityImpl::constPtr & rhs ) const
90       {
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 );
96       }
97     };
98
99     /////////////////////////////////////////////////////////////////
100   } // namespace capability
101   ///////////////////////////////////////////////////////////////////
102   /////////////////////////////////////////////////////////////////
103 } // namespace zypp
104 ///////////////////////////////////////////////////////////////////
105 #endif // ZYPP_CAPABILITY_CAPABILITYIMPL_H