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