514ee155666feedfb497dc18432e058abac5d9ad
[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
54     /** Convert \c this into a Ptr of a certain Kind.
55      * This is a convenience to access type specific
56      * attributes.
57      * \return \c NULL if \c this is not of the specified kind.
58      * \code
59      *  PoolItem pi;
60      *  Package::constPtr pkg = pi->asKind<Package>();
61      *
62      *  if ( pi->isKind<Package>() )
63      *     DBG << pi->asKind<Package>()->keywords() << endl;
64      * \endcode
65      */
66     template<class _Res>
67     inline typename ResTraits<_Res>::constPtrType asKind() const;
68
69     template<class _Res>
70     inline typename ResTraits<_Res>::PtrType asKind();
71
72   public:
73     /** \name Locale support.
74      * \see \ref sat::Solvable
75      */
76     //@{
77     /** \see \ref sat::Solvable::supportsLocales */
78     bool supportsLocales() const
79     { return sat::Solvable::supportsLocales(); }
80
81     /** \see \ref sat::Solvable::supportsLocale */
82     bool supportsLocale( const Locale & locale_r ) const
83     { return sat::Solvable::supportsLocale( locale_r ); }
84
85     bool supportsLocale( const LocaleSet & locales_r ) const
86     { return sat::Solvable::supportsLocale( locales_r ); }
87
88     /** \see \ref sat::Solvable::supportsRequestedLocales */
89     bool supportsRequestedLocales() const
90     { return sat::Solvable::supportsRequestedLocales(); }
91
92     /** \see \ref sat::Solvable::getSupportedLocales */
93     LocaleSet getSupportedLocales() const
94     { return sat::Solvable::getSupportedLocales(); }
95     //@}
96
97   public:
98     /**
99      * \short Short text describing the resolvable.
100      * This attribute is usually displayed in columns.
101      */
102     std::string summary( const Locale & lang_r = Locale() ) const;
103
104     /**
105      * \short Long text describing the resolvable.
106      */
107     std::string description( const Locale & lang_r = Locale() ) const;
108
109     /**
110      * \short Installation Notification
111      *
112      * This text can be used to tell the user some notes
113      * When he selects the resovable for installation.
114      */
115     std::string insnotify( const Locale & lang_r = Locale() ) const;
116
117     /**
118      * \short De-Installation Notification
119      *
120      * This text can be used to tell the user some notes
121      * When he selects the resovable for deinstall.
122      */
123     std::string delnotify( const Locale & lang_r = Locale() ) const;
124
125     /**
126      * \short License or agreement to accept
127      *
128      * Agreement, warning or license the user should
129      * accept before installing the resolvable.
130      */
131     std::string licenseToConfirm( const Locale & lang_r = Locale() ) const;
132
133     /**
134      * \short Vendor
135      *
136      * For example "Novell Inc."
137      */
138     Vendor vendor() const
139     { return Resolvable::vendor().asString(); }
140
141     /** The distribution string.
142      * E.g. \c code-11.
143     */
144     std::string distribution() const;
145
146     /**
147      * The Common Platform Enumeration name
148      * for this product.
149      *
150      * See http://cpe.mitre.org
151      */
152     std::string cpeId() const;
153
154     /** Installed size. */
155     ByteCount installSize() const;
156     /** \deprecated Use installSize which is more precise.*/
157     ZYPP_DEPRECATED ByteCount installsize() const { return installSize(); }
158     /** \deprecated Use installSize which is more precise. */
159     ZYPP_DEPRECATED ByteCount size() const { return installSize(); }
160
161     /** Size of the rpm package. */
162     ByteCount downloadSize() const;
163
164     /** \see \ref sat::Solvable::repository */
165     Repository repository() const
166     { return sat::Solvable::repository(); }
167
168      /** \ref RepoInfo associated with the repository
169       *  providing this resolvable.
170       */
171     RepoInfo repoInfo() const
172     { return repository().info(); }
173
174     /**
175      * Media number where the resolvable is located
176      * 0 if no media access is required.
177      */
178     unsigned mediaNr() const;
179
180     /**
181      * \short build time of the resolvable
182      */
183     Date buildtime() const;
184
185     /**
186      * \short Installation time
187      * 0 if the resolvable is not installed.
188      */
189     Date installtime() const;
190
191     /**
192      * \short Disk usage per directory
193      * A common attribute, although mostly packages require
194      * noticeable disk space. An e.g product could try to reserve
195      * a certain ammount of diskspace by providing DiskUsage data.
196      */
197     const DiskUsage & diskusage() const;
198
199   protected:
200     friend ResObject::Ptr makeResObject( const sat::Solvable & solvable_r );
201     /** Ctor */
202     ResObject( const sat::Solvable & solvable_r );
203     /** Dtor */
204     virtual ~ResObject();
205     /** Helper for stream output */
206     virtual std::ostream & dumpOn( std::ostream & str ) const;
207   };
208   ///////////////////////////////////////////////////////////////////
209
210   /** Create \ref ResObject from \ref sat::Solvable.
211    *
212    * This function creates the apropriate kind of ResObject
213    * depending on the sat::Solvables kind, and returns a smart
214    * pointer to it.
215    *
216    * If the sat::Solvables kind is not convertible, a NULL
217    * pointer is returned.
218    *
219    * \code
220    * sat::Solvable s;
221    * ResObject::Ptr p( makeResObject( s ) );
222    * ResObject::Ptr q( make<ResObject>( s ) );
223    * Package::Ptr   pkg( make<Package>( s ) );
224    * \endcode
225   */
226   ResObject::Ptr makeResObject( const sat::Solvable & solvable_r );
227
228   /** Directly create a certain kind of ResObject from \ref sat::Solvable.
229    *
230    * If the sat::Solvables kind is not appropriate, a NULL
231    * pointer is returned.
232     * \code
233    * sat::Solvable s;
234    * ResObject::Ptr p( makeResObject( s ) );
235    * ResObject::Ptr q( make<ResObject>( s ) );
236    * Package::Ptr   pkg( make<Package>( s ) );
237    * \endcode
238   */
239   template<class _Res>
240   inline typename ResTraits<_Res>::PtrType make( const sat::Solvable & solvable_r )
241   { return( isKind<_Res>( solvable_r ) ? new _Res( solvable_r ) : 0 ); }
242   /** \overload Specialisation for ResObject autodetecting the kind of resolvable. */
243   template<>
244   inline ResObject::Ptr make<ResObject>( const sat::Solvable & solvable_r )
245   { return makeResObject( solvable_r ); }
246
247   /** Convert ResObject::Ptr into Ptr of a certain Kind.
248    * \return \c NULL iff \a p is \c NULL or points to a Resolvable
249    * not of the specified Kind.
250    * \relates ResObject
251    * \code
252    * asKind<Package>(resPtr);
253    * \endcode
254   */
255   template<class _Res>
256   inline typename ResTraits<_Res>::PtrType asKind( const ResObject::Ptr & p )
257   { return dynamic_pointer_cast<_Res>(p); }
258
259   template<class _Res>
260   inline typename ResTraits<_Res>::constPtrType asKind( const ResObject::constPtr & p )
261   { return dynamic_pointer_cast<const _Res>(p); }
262
263   template<class _Res>
264   inline typename ResTraits<_Res>::constPtrType ResObject::asKind() const
265   { return make<_Res>( *this ); }
266
267   template<class _Res>
268   inline typename ResTraits<_Res>::PtrType ResObject::asKind()
269   { return make<_Res>( *this ); }
270
271   /////////////////////////////////////////////////////////////////
272 } // namespace zypp
273 ///////////////////////////////////////////////////////////////////
274 #endif // ZYPP_RESOBJECT_H