844cbae31e4cd27b26c9735b4eca5c06ae7c6c4b
[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/TranslatedText.h"
27
28 ///////////////////////////////////////////////////////////////////
29 namespace zypp
30 { /////////////////////////////////////////////////////////////////
31
32   ///////////////////////////////////////////////////////////////////
33   //
34   //    CLASS NAME : ResObject
35   //
36   /**
37    * Interface base for resolvable objects (common data).
38    * That is, all data not needed for solving, but common
39    * across all Resolvable kinds.
40    *
41    * \see \ref makeResObject for how to construct ResObjects.
42   */
43   class ResObject : public Resolvable
44   {
45   public:
46     typedef ResObject                Self;
47     typedef ResTraits<Self>          TraitsType;
48     typedef TraitsType::PtrType      Ptr;
49     typedef TraitsType::constPtrType constPtr;
50
51   public:
52     /** \name Locale support.
53      * \see \ref sat::Solvable
54     */
55     //@{
56     /** \see \ref sat::Solvable::supportsLocales */
57     using sat::Solvable::supportsLocales;
58     /** \see \ref sat::Solvable::supportsLocale */
59     using sat::Solvable::supportsLocale;
60     /** \see \ref sat::Solvable::supportsRequestedLocales */
61     using sat::Solvable::supportsRequestedLocales;
62     /** \see \ref sat::Solvable::getSupportedLocales */
63     using sat::Solvable::getSupportedLocales;
64     //@}
65
66   public:
67
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     /** Installed size. */
112     ByteCount installsize() const;
113     /** \deprecated Use installsize which is more precise. */
114     ZYPP_DEPRECATED ByteCount size() const
115     { return installsize(); }
116
117     /** Size of the rpm package. */
118     ByteCount downloadSize() const;
119
120     /** \see \ref sat::Solvable::repository */
121     using sat::Solvable::repository;
122
123      /** \ref RepoInfo associated with the repository
124       *  providing this resolvable.
125       */
126     RepoInfo repoInfo() const
127     { return repository().info(); }
128
129     /**
130      * Media number where the resolvable is located
131      * 0 if no media access is required.
132      */
133     unsigned mediaNr() const;
134
135     /**
136      * \TODO FIXME what is this?
137      * Flag in the metadata indicating this should be
138      * installed unsing '-i' (not -U).
139      */
140     bool installOnly() const;
141
142     /**
143      * \short build time of the resolvable
144      */
145     Date buildtime() const;
146
147     /**
148      * \short Installation time
149      * 0 if the resolvable is not installed.
150      */
151     Date installtime() const;
152
153     /**
154      * \short Disk usage per directory
155      * A common attribute, although mostly packages require
156      * noticeable disk space. An e.g product could try to reserve
157      * a certain ammount of diskspace by providing DiskUsage data.
158      */
159     const DiskUsage & diskusage() const;
160
161   protected:
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