provide ResObject::distribution
[platform/upstream/libzypp.git] / zypp / ResObject.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/ResObject.h
10  *
11 */
12 #ifndef ZYPP_RESOBJECT_H
13 #define ZYPP_RESOBJECT_H
14
15 #include "zypp/base/Deprecated.h"
16
17 #include "zypp/Resolvable.h"
18 #include "zypp/Date.h"
19 #include "zypp/Locale.h"
20 #include "zypp/Vendor.h"
21 #include "zypp/ByteCount.h"
22 #include "zypp/DiskUsage.h"
23 #include "zypp/OnMediaLocation.h"
24 #include "zypp/Repository.h"
25
26 #include "zypp/sat/LookupAttr.h"
27 #include "zypp/sat/SolvableSet.h"
28
29 ///////////////////////////////////////////////////////////////////
30 namespace zypp
31 { /////////////////////////////////////////////////////////////////
32
33   ///////////////////////////////////////////////////////////////////
34   //
35   //    CLASS NAME : ResObject
36   //
37   /**
38    * Interface base for resolvable objects (common data).
39    * That is, all data not needed for solving, but common
40    * across all Resolvable kinds.
41    *
42    * \see \ref makeResObject for how to construct ResObjects.
43   */
44   class ResObject : public Resolvable
45   {
46   public:
47     typedef ResObject                Self;
48     typedef ResTraits<Self>          TraitsType;
49     typedef TraitsType::PtrType      Ptr;
50     typedef TraitsType::constPtrType constPtr;
51
52   public:
53     /** \name Locale support.
54      * \see \ref sat::Solvable
55     */
56     //@{
57     /** \see \ref sat::Solvable::supportsLocales */
58     using sat::Solvable::supportsLocales;
59     /** \see \ref sat::Solvable::supportsLocale */
60     using sat::Solvable::supportsLocale;
61     /** \see \ref sat::Solvable::supportsRequestedLocales */
62     using sat::Solvable::supportsRequestedLocales;
63     /** \see \ref sat::Solvable::getSupportedLocales */
64     using sat::Solvable::getSupportedLocales;
65     //@}
66
67   public:
68     /**
69      * \short Short text describing the resolvable.
70      * This attribute is usually displayed in columns.
71      */
72     std::string summary( const Locale & lang_r = Locale() ) const;
73
74     /**
75      * \short Long text describing the resolvable.
76      */
77     std::string description( const Locale & lang_r = Locale() ) const;
78
79     /**
80      * \short Installation Notification
81      *
82      * This text can be used to tell the user some notes
83      * When he selects the resovable for installation.
84      */
85     std::string insnotify( const Locale & lang_r = Locale() ) const;
86
87     /**
88      * \short De-Installation Notification
89      *
90      * This text can be used to tell the user some notes
91      * When he selects the resovable for deinstall.
92      */
93     std::string delnotify( const Locale & lang_r = Locale() ) const;
94
95     /**
96      * \short License or agreement to accept
97      *
98      * Agreement, warning or license the user should
99      * accept before installing the resolvable.
100      */
101     std::string licenseToConfirm( const Locale & lang_r = Locale() ) const;
102
103     /**
104      * \short Vendor
105      *
106      * For example "Novell Inc."
107      */
108     Vendor vendor() const
109     { return Resolvable::vendor().asString(); }
110
111     /** The distribution string.
112      * E.g. \c code-11.
113     */
114     std::string distribution() const;
115
116     /** Installed size. */
117     ByteCount installSize() const;
118     /** \deprecated Use installSize which is more precise.*/
119     ZYPP_DEPRECATED ByteCount installsize() const { return installSize(); }
120     /** \deprecated Use installSize which is more precise. */
121     ZYPP_DEPRECATED ByteCount size() const { return installSize(); }
122
123     /** Size of the rpm package. */
124     ByteCount downloadSize() const;
125
126     /** \see \ref sat::Solvable::repository */
127     using sat::Solvable::repository;
128
129      /** \ref RepoInfo associated with the repository
130       *  providing this resolvable.
131       */
132     RepoInfo repoInfo() const
133     { return repository().info(); }
134
135     /**
136      * Media number where the resolvable is located
137      * 0 if no media access is required.
138      */
139     unsigned mediaNr() const;
140
141     /**
142      * \short build time of the resolvable
143      */
144     Date buildtime() const;
145
146     /**
147      * \short Installation time
148      * 0 if the resolvable is not installed.
149      */
150     Date installtime() const;
151
152     /**
153      * \short Disk usage per directory
154      * A common attribute, although mostly packages require
155      * noticeable disk space. An e.g product could try to reserve
156      * a certain ammount of diskspace by providing DiskUsage data.
157      */
158     const DiskUsage & diskusage() const;
159
160   protected:
161     friend ResObject::Ptr makeResObject( const sat::Solvable & solvable_r );
162     /** Ctor */
163     ResObject( const sat::Solvable & solvable_r );
164     /** Dtor */
165     virtual ~ResObject();
166     /** Helper for stream output */
167     virtual std::ostream & dumpOn( std::ostream & str ) const;
168   };
169   ///////////////////////////////////////////////////////////////////
170
171   /** Create \ref ResObject from \ref sat::Solvable.
172    *
173    * This function creates the apropriate kind of ResObject
174    * depending on the sat::Solvables kind, and returns a smart
175    * pointer to it.
176    *
177    * If the sat::Solvables kind is not convertible, a NULL
178    * pointer is returned.
179    *
180    * \code
181    * sat::Solvable s;
182    * ResObject::Ptr p( makeResObject( s ) );
183    * ResObject::Ptr q( make<ResObject>( s ) );
184    * Package::Ptr   pkg( make<Package>( s ) );
185    * \endcode
186   */
187   ResObject::Ptr makeResObject( const sat::Solvable & solvable_r );
188
189   /** Directly create a certain kind of ResObject from \ref sat::Solvable.
190    *
191    * If the sat::Solvables kind is not appropriate, a NULL
192    * pointer is returned.
193     * \code
194    * sat::Solvable s;
195    * ResObject::Ptr p( makeResObject( s ) );
196    * ResObject::Ptr q( make<ResObject>( s ) );
197    * Package::Ptr   pkg( make<Package>( s ) );
198    * \endcode
199   */
200   template<class _Res>
201   inline typename ResTraits<_Res>::PtrType make( const sat::Solvable & solvable_r )
202   { return( isKind<_Res>( solvable_r ) ? new _Res( solvable_r ) : 0 ); }
203   /** \overload Specialisation for ResObject autodetecting the kind of resolvable. */
204   template<>
205   inline ResObject::Ptr make<ResObject>( const sat::Solvable & solvable_r )
206   { return makeResObject( solvable_r ); }
207
208   /** Convert ResObject::Ptr into Ptr of a certain Kind.
209    * \return \c NULL iff \a p is \c NULL or points to a Resolvable
210    * not of the specified Kind.
211    * \relates ResObject
212    * \code
213    * asKind<Package>(resPtr);
214    * \endcode
215   */
216   template<class _Res>
217   inline typename ResTraits<_Res>::PtrType asKind( const ResObject::Ptr & p )
218   { return dynamic_pointer_cast<_Res>(p); }
219
220   template<class _Res>
221   inline typename ResTraits<_Res>::constPtrType asKind( const ResObject::constPtr & p )
222   { return dynamic_pointer_cast<const _Res>(p); }
223
224   /////////////////////////////////////////////////////////////////
225 } // namespace zypp
226 ///////////////////////////////////////////////////////////////////
227 #endif // ZYPP_RESOBJECT_H