Imported Upstream version 16.3.2
[platform/upstream/libzypp.git] / zypp / sat / SolvableType.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/sat/SolvableType.h
10  */
11 #ifndef ZYPP_SAT_SOLVABLETYPE_H
12 #define ZYPP_SAT_SOLVABLETYPE_H
13
14 #include <iosfwd>
15
16 #include "zypp/sat/Solvable.h"
17 #include "zypp/Repository.h"
18 #include "zypp/OnMediaLocation.h"
19 #include "zypp/ByteCount.h"
20 #include "zypp/CheckSum.h"
21 #include "zypp/CpeId.h"
22 #include "zypp/Date.h"
23
24 ///////////////////////////////////////////////////////////////////
25 namespace zypp
26 {
27   ///////////////////////////////////////////////////////////////////
28   namespace sat
29   {
30     ///////////////////////////////////////////////////////////////////
31     /// \class SolvableType
32     /// \brief Base class for creating \ref Solvable based types.
33     /// \ingroup g_CRTP
34     ///
35     /// Derive from this and offer explicit conversion to \ref Solvable
36     /// to make the \ref Solvable properties directly accessible.
37     ///
38     /// Different SolvableTypes are comparable based on the underlying
39     /// \ref Solvable.
40     ///
41     /// \see \ref Solvable
42     ///
43     /// \code
44     ///   class MySolvable : public SolvableType<MySolvable>
45     ///   {
46     ///     ......
47     ///   public:
48     ///     explicit operator sat::Solvable() const;
49     ///
50     ///   };
51     /// \endcode
52     ///////////////////////////////////////////////////////////////////
53     template <class Derived>
54     struct SolvableType
55     {
56       /** Return the corresponding \ref sat::Solvable. */
57       Solvable satSolvable() const { return Solvable(static_cast<const Derived&>(*this)); }
58
59       explicit operator bool() const                            { return bool(satSolvable()); }
60
61       IdString          ident() const                           { return satSolvable().ident(); }
62
63       ResKind           kind() const                            { return satSolvable().kind(); }
64       bool              isKind( const ResKind & kind_r ) const  { return satSolvable().isKind( kind_r ); }
65       template<class TRes>
66       bool              isKind() const                          { return satSolvable().isKind<TRes>(); }
67       template<class TIterator>
68       bool isKind( TIterator begin, TIterator end ) const       { return satSolvable().isKind( begin, end ); }
69
70       std::string       name() const                            { return satSolvable().name(); }
71       Edition           edition() const                         { return satSolvable().edition(); }
72       Arch              arch() const                            { return satSolvable().arch(); }
73       IdString          vendor() const                          { return satSolvable().vendor(); }
74
75       Repository        repository() const                      { return satSolvable().repository(); }
76       RepoInfo          repoInfo() const                        { return satSolvable().repoInfo(); }
77
78       bool              isSystem() const                        { return satSolvable().isSystem(); }
79       bool              onSystemByUser() const                  { return satSolvable().onSystemByUser(); }
80       bool              multiversionInstall() const             { return satSolvable().multiversionInstall(); }
81
82       Date              buildtime() const                       { return satSolvable().buildtime(); }
83       Date              installtime() const                     { return satSolvable().installtime(); }
84
85       std::string       asString() const                        { return satSolvable().asString(); }
86       std::string       asUserString() const                    { return satSolvable().asUserString(); }
87
88       bool              identical( const Solvable & rhs ) const { return satSolvable().identical( rhs ); }
89       template <class RDerived>
90       bool              identical( const SolvableType<RDerived> & rhs ) const   { return satSolvable().identical( rhs.satSolvable() ); }
91
92       bool              sameNVRA( const Solvable &rhs ) const   { return satSolvable().sameNVRA( rhs ); }
93       template <class RDerived>
94       bool              sameNVRA( const SolvableType<RDerived> & rhs ) const    { return satSolvable().sameNVRA( rhs.satSolvable() ); }
95
96       Capabilities      provides() const                        { return satSolvable().provides(); }
97       Capabilities      requires() const                        { return satSolvable().requires(); }
98       Capabilities      conflicts() const                       { return satSolvable().conflicts(); }
99       Capabilities      obsoletes() const                       { return satSolvable().obsoletes(); }
100       Capabilities      recommends() const                      { return satSolvable().recommends(); }
101       Capabilities      suggests() const                        { return satSolvable().suggests(); }
102       Capabilities      enhances() const                        { return satSolvable().enhances(); }
103       Capabilities      supplements() const                     { return satSolvable().supplements(); }
104       Capabilities      prerequires() const                     { return satSolvable().prerequires(); }
105       Capabilities      dep( Dep which_r ) const                { return satSolvable().dep(which_r); }
106       Capabilities      operator[]( Dep which_r ) const         { return satSolvable()[which_r]; }
107
108       CapabilitySet     providesNamespace( const std::string & namespace_r ) const      { return satSolvable().providesNamespace( namespace_r ); }
109       CapabilitySet     valuesOfNamespace( const std::string & namespace_r ) const      { return satSolvable().valuesOfNamespace( namespace_r ); }
110
111       bool              supportsLocales() const                 { return satSolvable().supportsLocales(); }
112       bool              supportsLocale( const Locale & locale_r ) const { return satSolvable().supportsLocale( locale_r ); }
113       bool              supportsLocale( const LocaleSet & locales_r ) const     { return satSolvable().supportsLocale( locales_r ); }
114       bool              supportsRequestedLocales() const        { return satSolvable().supportsRequestedLocales(); }
115       LocaleSet         getSupportedLocales() const             { return satSolvable().getSupportedLocales(); }
116
117       CpeId             cpeId() const                           { return satSolvable().cpeId(); }
118       unsigned          mediaNr() const                         { return satSolvable().mediaNr(); }
119       ByteCount         installSize() const                     { return satSolvable().installSize(); }
120       ByteCount         downloadSize() const                    { return satSolvable().downloadSize(); }
121       std::string       distribution() const                    { return satSolvable().distribution(); }
122
123       std::string       summary( const Locale & lang_r = Locale() ) const       { return satSolvable().summary( lang_r ); }
124       std::string       description( const Locale & lang_r = Locale() ) const   { return satSolvable().description( lang_r ); }
125       std::string       insnotify( const Locale & lang_r = Locale() ) const     { return satSolvable().insnotify( lang_r ); }
126       std::string       delnotify( const Locale & lang_r = Locale() ) const     { return satSolvable().delnotify( lang_r ); }
127       std::string       licenseToConfirm( const Locale & lang_r = Locale() ) const      { return satSolvable().licenseToConfirm( lang_r ); }
128       bool              needToAcceptLicense() const             { return satSolvable().needToAcceptLicense(); }
129
130     public:
131       std::string       lookupStrAttribute( const SolvAttr & attr ) const       { return satSolvable().lookupStrAttribute( attr ); }
132       std::string       lookupStrAttribute( const SolvAttr & attr, const Locale & lang_r ) const        { return satSolvable().lookupStrAttribute( attr, lang_r ); }
133       bool              lookupBoolAttribute( const SolvAttr & attr ) const      { return satSolvable().lookupBoolAttribute( attr ); }
134       detail::IdType    lookupIdAttribute( const SolvAttr & attr ) const        { return satSolvable().lookupIdAttribute( attr ); }
135       unsigned long long lookupNumAttribute( const SolvAttr & attr ) const      { return satSolvable().lookupNumAttribute( attr ); }
136       unsigned long long lookupNumAttribute( const SolvAttr & attr, unsigned long long notfound_r ) const       { return satSolvable().lookupNumAttribute( attr, notfound_r ); }
137       CheckSum          lookupCheckSumAttribute( const SolvAttr & attr ) const  { return satSolvable().lookupCheckSumAttribute( attr ); }
138       OnMediaLocation   lookupLocation() const                  { return satSolvable().lookupLocation(); }
139       Solvable::IdType  id() const                                      { return satSolvable().id(); }
140
141     protected:
142       SolvableType() {}
143       SolvableType( const SolvableType & ) {}
144       void operator=( const SolvableType & ) {}
145 #ifndef SWIG
146       SolvableType( SolvableType && ) {}
147       void operator=( SolvableType && ) {}
148 #endif
149       ~SolvableType() {}
150     };
151
152     /** \relates SolvableType Stream output */
153     template <class Derived>
154     inline std::ostream & operator<<( std::ostream & str, const SolvableType<Derived> & obj )
155     { return str << obj.satSolvable(); }
156
157     /** \relates SolvableType More verbose stream output including dependencies */
158     template <class Derived>
159     inline std::ostream & dumpOn( std::ostream & str, const SolvableType<Derived> & obj )
160     { return dumpOn( str, obj.satSolvable() ); }
161
162     /** \relates SolvableType Equal*/
163     template <class LDerived, class RDerived>
164     inline bool operator==( const SolvableType<LDerived> & lhs, const SolvableType<RDerived> & rhs )
165     { return lhs.satSolvable() == rhs.satSolvable(); }
166     /** \overload */
167     template <class Derived>
168     inline bool operator==( const SolvableType<Derived> & lhs, const Solvable & rhs )
169     { return lhs.satSolvable() == rhs; }
170     /** \overload */
171     template <class Derived>
172     inline bool operator==( const Solvable & lhs, const SolvableType<Derived> & rhs )
173     { return lhs == rhs.satSolvable(); }
174
175     /** \relates SolvableType NotEqual */
176     template <class LDerived, class RDerived>
177     inline bool operator!=( const SolvableType<LDerived> & lhs, const SolvableType<RDerived> & rhs )
178     { return lhs.satSolvable() != rhs.satSolvable(); }
179     /** \overload */
180     template <class Derived>
181     inline bool operator!=( const SolvableType<Derived> & lhs, const Solvable & rhs )
182     { return lhs.satSolvable() != rhs; }
183     /** \overload */
184     template <class Derived>
185     inline bool operator!=( const Solvable & lhs, const SolvableType<Derived> & rhs )
186     { return lhs != rhs.satSolvable(); }
187
188     /** \relates SolvableType Less*/
189     template <class LDerived, class RDerived>
190     inline bool operator<( const SolvableType<LDerived> & lhs, const SolvableType<RDerived> & rhs )
191     { return lhs.satSolvable() < rhs.satSolvable(); }
192     /** \overload */
193     template <class Derived>
194     inline bool operator<( const SolvableType<Derived> & lhs, const Solvable & rhs )
195     { return lhs.satSolvable() < rhs; }
196     /** \overload */
197     template <class Derived>
198     inline bool operator<( const Solvable & lhs, const SolvableType<Derived> & rhs )
199     { return lhs < rhs.satSolvable(); }
200
201     /** \relates SolvableType Test whether the \ref Solvable is of a certain \ref ResKind. */
202     template<class TRes, class Derived>
203     inline bool isKind( const SolvableType<Derived> & solvable_r )
204     { return isKind<TRes>( solvable_r.satSolvable() ); }
205
206     /** \relates SolvableType Test for same content. */
207     template <class LDerived, class RDerived>
208     inline bool identical( const SolvableType<LDerived> & lhs, const SolvableType<RDerived> & rhs )
209     { return identical( lhs.satSolvable(), rhs.satSolvable() ); }
210     /** \overload */
211     template <class Derived>
212     inline bool identical( const SolvableType<Derived> & lhs, const Solvable & rhs )
213     { return identical( lhs.satSolvable(), rhs ); }
214     /** \overload */
215     template <class Derived>
216     inline bool identical( const Solvable & lhs, const SolvableType<Derived> & rhs )
217     { return identical( lhs, rhs.satSolvable() ); }
218
219     /** \relates SolvableType Test for same name version release and arch. */
220     template <class LDerived, class RDerived>
221     inline bool sameNVRA( const SolvableType<LDerived> & lhs, const SolvableType<RDerived> & rhs )
222     { return sameNVRA( lhs.satSolvable(), rhs.satSolvable() ); }
223     /** \overload */
224     template <class Derived>
225     inline bool sameNVRA( const SolvableType<Derived> & lhs, const Solvable & rhs )
226     { return sameNVRA( lhs.satSolvable(), rhs ); }
227     /** \overload */
228     template <class Derived>
229     inline bool sameNVRA( const Solvable & lhs, const SolvableType<Derived> & rhs )
230     { return sameNVRA( lhs, rhs.satSolvable() ); }
231
232
233     /** \relates SolvableType Compare according to \a kind and \a name. */
234     template <class LDerived, class RDerived>
235     inline int compareByN( const SolvableType<LDerived> & lhs, const SolvableType<RDerived> & rhs )
236     { return compareByN( lhs.satSolvable(), rhs.satSolvable() ); }
237     /** \overload */
238     template <class Derived>
239     inline bool compareByN( const SolvableType<Derived> & lhs, const Solvable & rhs )
240     { return compareByN( lhs.satSolvable(), rhs ); }
241     /** \overload */
242     template <class Derived>
243     inline bool compareByN( const Solvable & lhs, const SolvableType<Derived> & rhs )
244     { return compareByN( lhs, rhs.satSolvable() ); }
245
246
247     /** \relates SolvableType Compare according to \a kind, \a name and \a edition. */
248     template <class LDerived, class RDerived>
249     inline int compareByNVR( const SolvableType<LDerived> & lhs, const SolvableType<RDerived> & rhs )
250     { return compareByNVR( lhs.satSolvable(), rhs.satSolvable() ); }
251     /** \overload */
252     template <class Derived>
253     inline bool compareByNVR( const SolvableType<Derived> & lhs, const Solvable & rhs )
254     { return compareByNVR( lhs.satSolvable(), rhs ); }
255     /** \overload */
256     template <class Derived>
257     inline bool compareByNVR( const Solvable & lhs, const SolvableType<Derived> & rhs )
258     { return compareByNVR( lhs, rhs.satSolvable() ); }
259
260     /** \relates SolvableType Compare according to \a kind, \a name, \a edition and \a arch. */
261     template <class LDerived, class RDerived>
262     inline int compareByNVRA( const SolvableType<LDerived> & lhs, const SolvableType<RDerived> & rhs )
263     { return compareByNVRA( lhs.satSolvable(), rhs.satSolvable() ); }
264     /** \overload */
265     template <class Derived>
266     inline bool compareByNVRA( const SolvableType<Derived> & lhs, const Solvable & rhs )
267     { return compareByNVRA( lhs.satSolvable(), rhs ); }
268     /** \overload */
269     template <class Derived>
270     inline bool compareByNVRA( const Solvable & lhs, const SolvableType<Derived> & rhs )
271     { return compareByNVRA( lhs, rhs.satSolvable() ); }
272
273   } // namespace sat
274   ///////////////////////////////////////////////////////////////////
275 } // namespace zypp
276 ///////////////////////////////////////////////////////////////////
277 #endif // ZYPP_SAT_SOLVABLETYPE_H