- Fix some Patch and Pattern attributes.
[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     /**
70      * \short Short text describing the resolvable.
71      * This attribute is usually displayed in columns.
72      */
73     std::string summary( const Locale & lang_r = Locale() ) const;
74
75     /**
76      * \short Long text describing the resolvable.
77      */
78     std::string description( const Locale & lang_r = Locale() ) const;
79
80     /**
81      * \short Installation Notification
82      *
83      * This text can be used to tell the user some notes
84      * When he selects the resovable for installation.
85      */
86     std::string insnotify( const Locale & lang_r = Locale() ) const;
87
88     /**
89      * \short De-Installation Notification
90      *
91      * This text can be used to tell the user some notes
92      * When he selects the resovable for deinstall.
93      */
94     std::string delnotify( const Locale & lang_r = Locale() ) const;
95
96     /**
97      * \short License or agreement to accept
98      *
99      * Agreement, warning or license the user should
100      * accept before installing the resolvable.
101      */
102     std::string licenseToConfirm( const Locale & lang_r = Locale() ) const;
103
104     /**
105      * \short Vendor
106      *
107      * For Example "Novell Inc."
108      */
109     Vendor vendor() const
110     { return Resolvable::vendor().asString(); }
111
112     /** Installed size. */
113     ByteCount installsize() const;
114     /** \deprecated Use installsize which is more precise. */
115     ZYPP_DEPRECATED ByteCount size() const
116     { return installsize(); }
117
118     /** Size of the rpm package. */
119     ByteCount downloadSize() const;
120
121     /** \see \ref sat::Solvable::repository */
122     using sat::Solvable::repository;
123
124      /** \ref RepoInfo associated with the repository
125       *  providing this resolvable.
126       */
127     RepoInfo repoInfo() const
128     { return repository().info(); }
129
130     /**
131      * Media number where the resolvable is located
132      * 0 if no media access is required.
133      */
134     unsigned mediaNr() const;
135
136     /**
137      * \TODO FIXME what is this?
138      * Flag in the metadata indicating this should be
139      * installed unsing '-i' (not -U).
140      */
141     bool installOnly() const;
142
143     /**
144      * \short build time of the resolvable
145      */
146     Date buildtime() const;
147
148     /**
149      * \short Installation time
150      * 0 if the resolvable is not installed.
151      */
152     Date installtime() const;
153
154     /**
155      * \short Disk usage per directory
156      * A common attribute, although mostly packages require
157      * noticeable disk space. An e.g product could try to reserve
158      * a certain ammount of diskspace by providing DiskUsage data.
159      */
160     const DiskUsage & diskusage() const;
161
162   protected:
163     /** Ctor */
164     ResObject( const sat::Solvable & solvable_r );
165     /** Dtor */
166     virtual ~ResObject();
167     /** Helper for stream output */
168     virtual std::ostream & dumpOn( std::ostream & str ) const;
169   };
170   ///////////////////////////////////////////////////////////////////
171
172   /** Create \ref ResObject from \ref sat::Solvable.
173    *
174    * This function creates the apropriate kind of ResObject
175    * depending on the sat::Solvables kind, and returns a smart
176    * pointer to it.
177    *
178    * If the sat::Solvables kind is not convertible, a NULL
179    * pointer is returned.
180    *
181    * \code
182    * sat::Solvable s;
183    * ResObject::Ptr p( makeResObject( s ) );
184    * ResObject::Ptr q( make<ResObject>( s ) );
185    * Package::Ptr   pkg( make<Package>( s ) );
186    * \endcode
187   */
188   ResObject::Ptr makeResObject( const sat::Solvable & solvable_r );
189
190   /** Directly create a certain kind of ResObject from \ref sat::Solvable.
191    *
192    * If the sat::Solvables kind is not appropriate, a NULL
193    * pointer is returned.
194     * \code
195    * sat::Solvable s;
196    * ResObject::Ptr p( makeResObject( s ) );
197    * ResObject::Ptr q( make<ResObject>( s ) );
198    * Package::Ptr   pkg( make<Package>( s ) );
199    * \endcode
200   */
201   template<class _Res>
202   inline typename ResTraits<_Res>::PtrType make( const sat::Solvable & solvable_r )
203   { return( isKind<_Res>( solvable_r ) ? new _Res( solvable_r ) : 0 ); }
204   /** \overload Specialisation for ResObject autodetecting the kind of resolvable. */
205   template<>
206   inline ResObject::Ptr make<ResObject>( const sat::Solvable & solvable_r )
207   { return makeResObject( solvable_r ); }
208
209   /** Convert ResObject::Ptr into Ptr of a certain Kind.
210    * \return \c NULL iff \a p is \c NULL or points to a Resolvable
211    * not of the specified Kind.
212    * \relates ResObject
213    * \code
214    * asKind<Package>(resPtr);
215    * \endcode
216   */
217   template<class _Res>
218   inline typename ResTraits<_Res>::PtrType asKind( const ResObject::Ptr & p )
219   { return dynamic_pointer_cast<_Res>(p); }
220
221   template<class _Res>
222   inline typename ResTraits<_Res>::constPtrType asKind( const ResObject::constPtr & p )
223   { return dynamic_pointer_cast<const _Res>(p); }
224
225   /////////////////////////////////////////////////////////////////
226 } // namespace zypp
227 ///////////////////////////////////////////////////////////////////
228 #endif // ZYPP_RESOBJECT_H