backup
[platform/upstream/libzypp.git] / zypp / sat / Solvable.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/sat/Solvable.h
10  *
11 */
12 #ifndef ZYPP_SAT_SOLVABLE_H
13 #define ZYPP_SAT_SOLVABLE_H
14
15 #include <iosfwd>
16
17 #include "zypp/base/SafeBool.h"
18
19 #include "zypp/sat/detail/PoolMember.h"
20 #include "zypp/sat/IdStr.h"
21 #include "zypp/sat/IdRel.h"
22
23 ///////////////////////////////////////////////////////////////////
24 namespace zypp
25 { /////////////////////////////////////////////////////////////////
26   ///////////////////////////////////////////////////////////////////
27   namespace sat
28   { /////////////////////////////////////////////////////////////////
29
30     ///////////////////////////////////////////////////////////////////
31     //
32     //  CLASS NAME : Solvable
33     //
34     /** */
35     class Solvable : protected detail::PoolMember,
36                      private base::SafeBool<Solvable>
37     {
38       public:
39         /** Default ctor creates \ref nosolvable.*/
40         Solvable()
41         : _id( detail::noSolvableId ) {}
42
43         /** \ref PoolImpl ctor. */
44         explicit Solvable( detail::SolvableIdType id_r )
45         : _id( id_r ) {}
46
47       public:
48         /** Represents no \ref Solvable. */
49         static const Solvable nosolvable;
50
51         /** Evaluate \ref Solvable in a boolean context (\c != \c nosolvable). */
52         using base::SafeBool<Solvable>::operator bool_type;
53
54         /** Return whether this \ref Solvable belongs to the system repo. */
55         bool isSystem() const;
56
57       public:
58         NameId   name() const;
59         EvrId    evr() const;
60         ArchId   arch() const;
61         VendorId vendor() const;
62
63       public:
64         Repo repo() const;
65
66       public:
67         /** Return next Solvable in \ref Pool (or \ref nosolvable). */
68         Solvable nextInPool() const;
69         /** Return next Solvable in \ref Repo (or \ref nosolvable). */
70         Solvable nextInRepo() const;
71       public:
72         /** Expert backdoor. */
73         ::_Solvable * get() const;
74         /** Expert backdoor. */
75         detail::SolvableIdType id() const { return _id; }
76       private:
77         friend base::SafeBool<Solvable>::operator bool_type() const;
78         bool boolTest() const { return get(); }
79       private:
80         detail::SolvableIdType _id;
81     };
82     ///////////////////////////////////////////////////////////////////
83
84     /** \relates Solvable Stream output */
85     std::ostream & operator<<( std::ostream & str, const Solvable & obj );
86
87     /** \relates Solvable */
88     inline bool operator==( const Solvable & lhs, const Solvable & rhs )
89     { return lhs.get() == rhs.get(); }
90
91     /** \relates Solvable */
92     inline bool operator!=( const Solvable & lhs, const Solvable & rhs )
93     { return lhs.get() != rhs.get(); }
94
95     /** \relates Solvable */
96     inline bool operator<( const Solvable & lhs, const Solvable & rhs )
97     { return lhs.get() < rhs.get(); }
98
99     ///////////////////////////////////////////////////////////////////
100     namespace detail
101     { /////////////////////////////////////////////////////////////////
102       ///////////////////////////////////////////////////////////////////
103       //
104       //        CLASS NAME : SolvableIterator
105       //
106       /** */
107       class SolvableIterator : public boost::iterator_adaptor<
108           SolvableIterator                   // Derived
109           , ::_Solvable*                     // Base
110           , Solvable                         // Value
111           , boost::single_pass_traversal_tag // CategoryOrTraversal
112           , Solvable                         // Reference
113           >
114       {
115         public:
116           SolvableIterator()
117           : SolvableIterator::iterator_adaptor_( 0 )
118           {}
119
120           explicit SolvableIterator( const Solvable & val_r )
121           : SolvableIterator::iterator_adaptor_( 0 )
122           { assignVal( val_r ); }
123
124           explicit SolvableIterator( SolvableIdType id_r )
125           : SolvableIterator::iterator_adaptor_( 0 )
126           { assignVal( Solvable( id_r ) ); }
127
128         private:
129           friend class boost::iterator_core_access;
130
131           void increment()
132           { assignVal( _val.nextInPool() ); }
133
134           Solvable dereference() const
135           { return _val; }
136
137           void assignVal( const Solvable & val_r )
138           { _val = val_r; base_reference() = _val.get(); }
139
140           Solvable _val;
141       };
142       ///////////////////////////////////////////////////////////////////
143       /////////////////////////////////////////////////////////////////
144     } // namespace detail
145     ///////////////////////////////////////////////////////////////////
146
147    /////////////////////////////////////////////////////////////////
148   } // namespace sat
149   ///////////////////////////////////////////////////////////////////
150   /////////////////////////////////////////////////////////////////
151 } // namespace zypp
152 ///////////////////////////////////////////////////////////////////
153 #endif // ZYPP_SAT_SOLVABLE_H