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