Imported Upstream version 16.4.0
[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().template 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              onSystemByAuto() const                  { return satSolvable().onSystemByAuto(); }
81       bool              identIsAutoInstalled() const            { return satSolvable().identIsAutoInstalled(); }
82       bool              multiversionInstall() const             { return satSolvable().multiversionInstall(); }
83
84       Date              buildtime() const                       { return satSolvable().buildtime(); }
85       Date              installtime() const                     { return satSolvable().installtime(); }
86
87       std::string       asString() const                        { return satSolvable().asString(); }
88       std::string       asUserString() const                    { return satSolvable().asUserString(); }
89
90       bool              identical( const Solvable & rhs ) const { return satSolvable().identical( rhs ); }
91       template <class RDerived>
92       bool              identical( const SolvableType<RDerived> & rhs ) const   { return satSolvable().identical( rhs.satSolvable() ); }
93
94       bool              sameNVRA( const Solvable &rhs ) const   { return satSolvable().sameNVRA( rhs ); }
95       template <class RDerived>
96       bool              sameNVRA( const SolvableType<RDerived> & rhs ) const    { return satSolvable().sameNVRA( rhs.satSolvable() ); }
97
98       Capabilities      provides() const                        { return satSolvable().provides(); }
99       Capabilities      requires() const                        { return satSolvable().requires(); }
100       Capabilities      conflicts() const                       { return satSolvable().conflicts(); }
101       Capabilities      obsoletes() const                       { return satSolvable().obsoletes(); }
102       Capabilities      recommends() const                      { return satSolvable().recommends(); }
103       Capabilities      suggests() const                        { return satSolvable().suggests(); }
104       Capabilities      enhances() const                        { return satSolvable().enhances(); }
105       Capabilities      supplements() const                     { return satSolvable().supplements(); }
106       Capabilities      prerequires() const                     { return satSolvable().prerequires(); }
107       Capabilities      dep( Dep which_r ) const                { return satSolvable().dep(which_r); }
108       Capabilities      operator[]( Dep which_r ) const         { return satSolvable()[which_r]; }
109
110       CapabilitySet     providesNamespace( const std::string & namespace_r ) const      { return satSolvable().providesNamespace( namespace_r ); }
111       CapabilitySet     valuesOfNamespace( const std::string & namespace_r ) const      { return satSolvable().valuesOfNamespace( namespace_r ); }
112
113       bool              supportsLocales() const                 { return satSolvable().supportsLocales(); }
114       bool              supportsLocale( const Locale & locale_r ) const { return satSolvable().supportsLocale( locale_r ); }
115       bool              supportsLocale( const LocaleSet & locales_r ) const     { return satSolvable().supportsLocale( locales_r ); }
116       bool              supportsRequestedLocales() const        { return satSolvable().supportsRequestedLocales(); }
117       LocaleSet         getSupportedLocales() const             { return satSolvable().getSupportedLocales(); }
118
119       CpeId             cpeId() const                           { return satSolvable().cpeId(); }
120       unsigned          mediaNr() const                         { return satSolvable().mediaNr(); }
121       ByteCount         installSize() const                     { return satSolvable().installSize(); }
122       ByteCount         downloadSize() const                    { return satSolvable().downloadSize(); }
123       std::string       distribution() const                    { return satSolvable().distribution(); }
124
125       std::string       summary( const Locale & lang_r = Locale() ) const       { return satSolvable().summary( lang_r ); }
126       std::string       description( const Locale & lang_r = Locale() ) const   { return satSolvable().description( lang_r ); }
127       std::string       insnotify( const Locale & lang_r = Locale() ) const     { return satSolvable().insnotify( lang_r ); }
128       std::string       delnotify( const Locale & lang_r = Locale() ) const     { return satSolvable().delnotify( lang_r ); }
129       std::string       licenseToConfirm( const Locale & lang_r = Locale() ) const      { return satSolvable().licenseToConfirm( lang_r ); }
130       bool              needToAcceptLicense() const             { return satSolvable().needToAcceptLicense(); }
131
132     public:
133       std::string       lookupStrAttribute( const SolvAttr & attr ) const       { return satSolvable().lookupStrAttribute( attr ); }
134       std::string       lookupStrAttribute( const SolvAttr & attr, const Locale & lang_r ) const        { return satSolvable().lookupStrAttribute( attr, lang_r ); }
135       bool              lookupBoolAttribute( const SolvAttr & attr ) const      { return satSolvable().lookupBoolAttribute( attr ); }
136       detail::IdType    lookupIdAttribute( const SolvAttr & attr ) const        { return satSolvable().lookupIdAttribute( attr ); }
137       unsigned long long lookupNumAttribute( const SolvAttr & attr ) const      { return satSolvable().lookupNumAttribute( attr ); }
138       unsigned long long lookupNumAttribute( const SolvAttr & attr, unsigned long long notfound_r ) const       { return satSolvable().lookupNumAttribute( attr, notfound_r ); }
139       CheckSum          lookupCheckSumAttribute( const SolvAttr & attr ) const  { return satSolvable().lookupCheckSumAttribute( attr ); }
140       OnMediaLocation   lookupLocation() const                  { return satSolvable().lookupLocation(); }
141       Solvable::IdType  id() const                                      { return satSolvable().id(); }
142
143     protected:
144       SolvableType() {}
145       SolvableType( const SolvableType & ) {}
146       void operator=( const SolvableType & ) {}
147 #ifndef SWIG
148       SolvableType( SolvableType && ) {}
149       void operator=( SolvableType && ) {}
150 #endif
151       ~SolvableType() {}
152     };
153
154     /** \relates SolvableType Stream output */
155     template <class Derived>
156     inline std::ostream & operator<<( std::ostream & str, const SolvableType<Derived> & obj )
157     { return str << obj.satSolvable(); }
158
159     /** \relates SolvableType More verbose stream output including dependencies */
160     template <class Derived>
161     inline std::ostream & dumpOn( std::ostream & str, const SolvableType<Derived> & obj )
162     { return dumpOn( str, obj.satSolvable() ); }
163
164     /** \relates SolvableType Equal*/
165     template <class LDerived, class RDerived>
166     inline bool operator==( const SolvableType<LDerived> & lhs, const SolvableType<RDerived> & rhs )
167     { return lhs.satSolvable() == rhs.satSolvable(); }
168     /** \overload */
169     template <class Derived>
170     inline bool operator==( const SolvableType<Derived> & lhs, const Solvable & rhs )
171     { return lhs.satSolvable() == rhs; }
172     /** \overload */
173     template <class Derived>
174     inline bool operator==( const Solvable & lhs, const SolvableType<Derived> & rhs )
175     { return lhs == rhs.satSolvable(); }
176
177     /** \relates SolvableType NotEqual */
178     template <class LDerived, class RDerived>
179     inline bool operator!=( const SolvableType<LDerived> & lhs, const SolvableType<RDerived> & rhs )
180     { return lhs.satSolvable() != rhs.satSolvable(); }
181     /** \overload */
182     template <class Derived>
183     inline bool operator!=( const SolvableType<Derived> & lhs, const Solvable & rhs )
184     { return lhs.satSolvable() != rhs; }
185     /** \overload */
186     template <class Derived>
187     inline bool operator!=( const Solvable & lhs, const SolvableType<Derived> & rhs )
188     { return lhs != rhs.satSolvable(); }
189
190     /** \relates SolvableType Less*/
191     template <class LDerived, class RDerived>
192     inline bool operator<( const SolvableType<LDerived> & lhs, const SolvableType<RDerived> & rhs )
193     { return lhs.satSolvable() < rhs.satSolvable(); }
194     /** \overload */
195     template <class Derived>
196     inline bool operator<( const SolvableType<Derived> & lhs, const Solvable & rhs )
197     { return lhs.satSolvable() < rhs; }
198     /** \overload */
199     template <class Derived>
200     inline bool operator<( const Solvable & lhs, const SolvableType<Derived> & rhs )
201     { return lhs < rhs.satSolvable(); }
202
203     /** \relates SolvableType Test whether the \ref Solvable is of a certain \ref ResKind. */
204     template<class TRes, class Derived>
205     inline bool isKind( const SolvableType<Derived> & solvable_r )
206     { return isKind<TRes>( solvable_r.satSolvable() ); }
207
208     /** \relates SolvableType Test for same content. */
209     template <class LDerived, class RDerived>
210     inline bool identical( const SolvableType<LDerived> & lhs, const SolvableType<RDerived> & rhs )
211     { return identical( lhs.satSolvable(), rhs.satSolvable() ); }
212     /** \overload */
213     template <class Derived>
214     inline bool identical( const SolvableType<Derived> & lhs, const Solvable & rhs )
215     { return identical( lhs.satSolvable(), rhs ); }
216     /** \overload */
217     template <class Derived>
218     inline bool identical( const Solvable & lhs, const SolvableType<Derived> & rhs )
219     { return identical( lhs, rhs.satSolvable() ); }
220
221     /** \relates SolvableType Test for same name version release and arch. */
222     template <class LDerived, class RDerived>
223     inline bool sameNVRA( const SolvableType<LDerived> & lhs, const SolvableType<RDerived> & rhs )
224     { return sameNVRA( lhs.satSolvable(), rhs.satSolvable() ); }
225     /** \overload */
226     template <class Derived>
227     inline bool sameNVRA( const SolvableType<Derived> & lhs, const Solvable & rhs )
228     { return sameNVRA( lhs.satSolvable(), rhs ); }
229     /** \overload */
230     template <class Derived>
231     inline bool sameNVRA( const Solvable & lhs, const SolvableType<Derived> & rhs )
232     { return sameNVRA( lhs, rhs.satSolvable() ); }
233
234
235     /** \relates SolvableType Compare according to \a kind and \a name. */
236     template <class LDerived, class RDerived>
237     inline int compareByN( const SolvableType<LDerived> & lhs, const SolvableType<RDerived> & rhs )
238     { return compareByN( lhs.satSolvable(), rhs.satSolvable() ); }
239     /** \overload */
240     template <class Derived>
241     inline bool compareByN( const SolvableType<Derived> & lhs, const Solvable & rhs )
242     { return compareByN( lhs.satSolvable(), rhs ); }
243     /** \overload */
244     template <class Derived>
245     inline bool compareByN( const Solvable & lhs, const SolvableType<Derived> & rhs )
246     { return compareByN( lhs, rhs.satSolvable() ); }
247
248
249     /** \relates SolvableType Compare according to \a kind, \a name and \a edition. */
250     template <class LDerived, class RDerived>
251     inline int compareByNVR( const SolvableType<LDerived> & lhs, const SolvableType<RDerived> & rhs )
252     { return compareByNVR( lhs.satSolvable(), rhs.satSolvable() ); }
253     /** \overload */
254     template <class Derived>
255     inline bool compareByNVR( const SolvableType<Derived> & lhs, const Solvable & rhs )
256     { return compareByNVR( lhs.satSolvable(), rhs ); }
257     /** \overload */
258     template <class Derived>
259     inline bool compareByNVR( const Solvable & lhs, const SolvableType<Derived> & rhs )
260     { return compareByNVR( lhs, rhs.satSolvable() ); }
261
262     /** \relates SolvableType Compare according to \a kind, \a name, \a edition and \a arch. */
263     template <class LDerived, class RDerived>
264     inline int compareByNVRA( const SolvableType<LDerived> & lhs, const SolvableType<RDerived> & rhs )
265     { return compareByNVRA( lhs.satSolvable(), rhs.satSolvable() ); }
266     /** \overload */
267     template <class Derived>
268     inline bool compareByNVRA( const SolvableType<Derived> & lhs, const Solvable & rhs )
269     { return compareByNVRA( lhs.satSolvable(), rhs ); }
270     /** \overload */
271     template <class Derived>
272     inline bool compareByNVRA( const Solvable & lhs, const SolvableType<Derived> & rhs )
273     { return compareByNVRA( lhs, rhs.satSolvable() ); }
274
275   } // namespace sat
276   ///////////////////////////////////////////////////////////////////
277 } // namespace zypp
278 ///////////////////////////////////////////////////////////////////
279 #endif // ZYPP_SAT_SOLVABLETYPE_H