summaryrefslogtreecommitdiff
path: root/swig/Capability.i
blob: 5f3984cc4a3c48690a4261299e1f270d857e465d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92

class Capability
{
  public:
    /** */
    typedef capability::CapabilityTraits::KindType  Kind;

  public:
    /** DefaultCtor creating \ref noCap. */
    Capability();

    /** Dtor */
    virtual ~Capability();

    /** Constant representing no Capabiliy.
     * It refers to no kind of Resolvable, and matches returns
     *  returns \c CapMatch::irrelevant.
    */
    static const Capability noCap;

  public:
    /** Kind of Capability.  */
    const Kind & kind() const;

    /** Kind of Resolvable the Capability refers to. */
    const Resolvable::Kind & refers() const;

    /** Whether to consider this Capability.
     * Evaluates the Capabilities pre-condition (if any), and
     * returns whether the condition applies. If not, the Capability
     * is to be ignored.
    */
    bool relevant() const;

    /** Return whether the Capabilities match.
     * If either Capability is not \ref relevant, CapMatch::irrelevant
     * is returned.
    */
    CapMatch matches( const Capability & rhs ) const;

    /** More or less human readable representation as string. */
    std::string asString() const;

    /** accessors needed by solver/zmd  */
    /** Deprecated */
    std::string index() const;

  private:
    typedef capability::CapabilityImpl          Impl;
    typedef capability::CapabilityImpl_Ptr      Impl_Ptr ;
    typedef capability::CapabilityImpl_constPtr Impl_constPtr;

    /** Factory */
    friend class CapFactory;

    /** Factory ctor */
    explicit
    Capability( Impl_Ptr impl_r );

  private:
    /** */
    friend class capability::CapabilityImpl;
    /** Pointer to implementation */
    RW_pointer<Impl,rw_pointer::Intrusive<Impl> > _pimpl;
};

template<class _Cap>
inline bool isKind( const Capability & cap )
{ return cap.kind() == capability::CapTraits<_Cap>::kind; }


/** Ordering relation used by ::CapSet. */
struct CapOrder : public std::binary_function<Capability, Capability, bool>
{
    bool operator()( const Capability & lhs, const Capability & rhs ) const
    { return lhs._pimpl.get() < rhs._pimpl.get(); }
};


%extend Capability
{
    int __cmp__(const Capability& other)
    {
	// TODO: use CapOrder::operator()?
	if(self->asString() < other.asString())
	    return -1;
	if(self->asString() > other.asString())
	    return +1;
	return 0;
    }
}