cd41635eb06fbf2074931a3b49c768e8672b7668
[platform/upstream/libzypp.git] / zypp / capability / ModaliasCap.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/capability/ModaliasCap.h
10  *
11 */
12 #ifndef ZYPP_CAPABILITY_MODALIASCAP_H
13 #define ZYPP_CAPABILITY_MODALIASCAP_H
14
15 #include "zypp/base/Deprecated.h"
16 #include "zypp/capability/CapabilityImpl.h"
17
18 ///////////////////////////////////////////////////////////////////
19 namespace zypp
20 { /////////////////////////////////////////////////////////////////
21   ///////////////////////////////////////////////////////////////////
22   namespace capability
23   { /////////////////////////////////////////////////////////////////
24
25     DEFINE_PTR_TYPE(ModaliasCap)
26     
27     ///////////////////////////////////////////////////////////////////
28     //
29     //  CLASS NAME : ModaliasCap
30     //
31     /** A Capability resolved by a query to target::modalias.
32      *
33      * \note ModaliasCap is special as it is self evaluating, and does not
34      * comapre to the \a rhs (or \a lhs). This is currently solved by
35      * treating a ModaliasCap with an empty name as evaluate command.
36      *
37      * \ref matches returns \c CapMatch::irrelevant, if either both sides
38      * are evaluate commands, or both are not.
39      *
40      * Otherwise the result of the query to target::modalias is returned.
41      * Either from \a lhs or \a rhs, dependent on which one is the
42      * evaluate command.
43     */
44     class ModaliasCap : public CapabilityImpl
45     {
46     public:
47       typedef ModaliasCap Self;
48       typedef ModaliasCap_Ptr Ptr;
49       typedef ModaliasCap_constPtr constPtr;
50       
51     public:
52       /** Ctor */
53       ModaliasCap( const Resolvable::Kind & refers_r, const std::string & name_r );
54
55       /** Ctor */
56       ModaliasCap( const Resolvable::Kind & refers_r,
57                    const std::string & name_r,
58                    Rel op_r,
59                    const std::string & value_r );
60
61     public:
62       /**  */
63       virtual const Kind & kind() const;
64
65       /** Query target::Modalias. */
66       virtual CapMatch matches( const CapabilityImpl::constPtr & rhs ) const;
67
68       /** <tt>modalias(name) [op value]</tt> */
69       virtual std::string encode() const;
70
71       /** <tt>modalias()</tt> */
72       virtual std::string index() const;
73
74     public:
75       const std::string & pkgname() const
76       { return _pkgname; }
77
78       void setPkgname( const std::string &pn )
79       { _pkgname = pn; }
80       
81       ZYPP_DEPRECATED const std::string & querystring() const
82       { return _name; }
83
84       const std::string & name() const
85       { return _name; }
86       
87       Rel op() const
88       { return _op; }
89       
90       const std::string & value() const
91       { return _value; }
92       
93     private:
94       /** Empty ModaliasCap <tt>modalias()</tt> */
95       bool isEvalCmd() const;
96
97       /** Query target::Modalias. */
98       bool evaluate() const;
99
100     private:
101       /**  */
102       std::string _pkgname;
103       std::string _name;
104       Rel _op;
105       std::string _value;
106     };
107     ///////////////////////////////////////////////////////////////////
108
109     /////////////////////////////////////////////////////////////////
110   } // namespace capability
111   ///////////////////////////////////////////////////////////////////
112   /////////////////////////////////////////////////////////////////
113 } // namespace zypp
114 ///////////////////////////////////////////////////////////////////
115 #endif // ZYPP_CAPABILITY_MODALIASCAP_H