1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/ResObject.h
12 #ifndef ZYPP_RESOBJECT_H
13 #define ZYPP_RESOBJECT_H
15 #include "zypp/APIConfig.h"
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/OnMediaLocation.h"
23 #include "zypp/Repository.h"
24 #include "zypp/CpeId.h"
26 #include "zypp/sat/LookupAttr.h"
27 #include "zypp/sat/SolvableSet.h"
29 ///////////////////////////////////////////////////////////////////
31 { /////////////////////////////////////////////////////////////////
33 ///////////////////////////////////////////////////////////////////
35 // CLASS NAME : ResObject
38 * Interface base for resolvable objects (common data).
39 * That is, all data not needed for solving, but common
40 * across all Resolvable kinds.
42 * \see \ref makeResObject for how to construct ResObjects.
44 class ResObject : public Resolvable
47 typedef ResObject Self;
48 typedef ResTraits<Self> TraitsType;
49 typedef TraitsType::PtrType Ptr;
50 typedef TraitsType::constPtrType constPtr;
54 /** Convert \c this into a Ptr of a certain Kind.
55 * This is a convenience to access type specific
57 * \return \c NULL if \c this is not of the specified kind.
60 * Package::constPtr pkg = pi->asKind<Package>();
62 * if ( pi->isKind<Package>() )
63 * DBG << pi->asKind<Package>()->keywords() << endl;
67 inline typename ResTraits<_Res>::constPtrType asKind() const;
70 inline typename ResTraits<_Res>::PtrType asKind();
73 /** \name Locale support.
74 * \see \ref sat::Solvable
77 /** \see \ref sat::Solvable::supportsLocales */
78 bool supportsLocales() const
79 { return sat::Solvable::supportsLocales(); }
81 /** \see \ref sat::Solvable::supportsLocale */
82 bool supportsLocale( const Locale & locale_r ) const
83 { return sat::Solvable::supportsLocale( locale_r ); }
85 bool supportsLocale( const LocaleSet & locales_r ) const
86 { return sat::Solvable::supportsLocale( locales_r ); }
88 /** \see \ref sat::Solvable::supportsRequestedLocales */
89 bool supportsRequestedLocales() const
90 { return sat::Solvable::supportsRequestedLocales(); }
92 /** \see \ref sat::Solvable::getSupportedLocales */
93 LocaleSet getSupportedLocales() const
94 { return sat::Solvable::getSupportedLocales(); }
99 * \short Short text describing the resolvable.
100 * This attribute is usually displayed in columns.
102 std::string summary( const Locale & lang_r = Locale() ) const;
105 * \short Long text describing the resolvable.
107 std::string description( const Locale & lang_r = Locale() ) const;
110 * \short Installation Notification
112 * This text can be used to tell the user some notes
113 * When he selects the resovable for installation.
115 std::string insnotify( const Locale & lang_r = Locale() ) const;
118 * \short De-Installation Notification
120 * This text can be used to tell the user some notes
121 * When he selects the resovable for deinstall.
123 std::string delnotify( const Locale & lang_r = Locale() ) const;
126 * \short License or agreement to accept
128 * Agreement, warning or license the user should
129 * accept before installing the resolvable.
131 std::string licenseToConfirm( const Locale & lang_r = Locale() ) const;
134 * \short Acceptance of Product License needed?
136 * Returns whether a product license has to be accepted
137 * (no acceptance is needed for openSUSE)
139 bool needToAcceptLicense() const;
144 * For example "Novell Inc."
146 Vendor vendor() const
147 { return Resolvable::vendor().asString(); }
149 /** The distribution string.
152 std::string distribution() const;
154 /** The Common Platform Enumeration name for this product. */
157 /** Installed (unpacked) size.
158 * This is just a total number. Many objects provide even more detailed
159 * disk usage data. You can use \ref DiskUsageCounter to find out
160 * how objects data are distributed across partitions/directories.
162 * // Load directory set into ducounter
163 * DiskUsageCounter ducounter( { "/", "/usr", "/var" } );
165 * // see how noch space the packages use
166 * for ( const PoolItem & pi : pool )
168 * cout << pi << ducounter.disk_usage( pi ) << endl;
169 * // I__s_(7)GeoIP-1.4.8-3.1.2.x86_64(@System) {
170 * // dir:[/] [ bs: 0 B ts: 0 B us: 0 B (+-: 1.0 KiB)]
171 * // dir:[/usr] [ bs: 0 B ts: 0 B us: 0 B (+-: 133.0 KiB)]
172 * // dir:[/var] [ bs: 0 B ts: 0 B us: 0 B (+-: 1.1 MiB)]
176 * \see \ref DiskUsageCounter
178 ByteCount installSize() const;
180 /** Download size. */
181 ByteCount downloadSize() const;
183 /** \see \ref sat::Solvable::repository */
184 Repository repository() const
185 { return sat::Solvable::repository(); }
187 /** \ref RepoInfo associated with the repository
188 * providing this resolvable.
190 RepoInfo repoInfo() const
191 { return repository().info(); }
194 * Media number where the resolvable is located
195 * 0 if no media access is required.
197 unsigned mediaNr() const;
200 * \short build time of the resolvable
202 Date buildtime() const;
205 * \short Installation time
206 * 0 if the resolvable is not installed.
208 Date installtime() const;
211 friend ResObject::Ptr makeResObject( const sat::Solvable & solvable_r );
213 ResObject( const sat::Solvable & solvable_r );
215 virtual ~ResObject();
216 /** Helper for stream output */
217 virtual std::ostream & dumpOn( std::ostream & str ) const;
219 ///////////////////////////////////////////////////////////////////
221 /** Create \ref ResObject from \ref sat::Solvable.
223 * This function creates the apropriate kind of ResObject
224 * depending on the sat::Solvables kind, and returns a smart
227 * If the sat::Solvables kind is not convertible, a NULL
228 * pointer is returned.
232 * ResObject::Ptr p( makeResObject( s ) );
233 * ResObject::Ptr q( make<ResObject>( s ) );
234 * Package::Ptr pkg( make<Package>( s ) );
237 ResObject::Ptr makeResObject( const sat::Solvable & solvable_r );
239 /** Directly create a certain kind of ResObject from \ref sat::Solvable.
241 * If the sat::Solvables kind is not appropriate, a NULL
242 * pointer is returned.
245 * ResObject::Ptr p( makeResObject( s ) );
246 * ResObject::Ptr q( make<ResObject>( s ) );
247 * Package::Ptr pkg( make<Package>( s ) );
249 * \todo make<> was a poor choice (AFAIR because gcc had some trouble with
250 * asKind<>(sat::Solvable)). Remove it in favour of asKind<>(sat::Solvable)
253 inline typename ResTraits<_Res>::PtrType make( const sat::Solvable & solvable_r )
254 { return( isKind<_Res>( solvable_r ) ? new _Res( solvable_r ) : 0 ); }
255 /** \overload Specialisation for ResObject autodetecting the kind of resolvable. */
257 inline ResObject::Ptr make<ResObject>( const sat::Solvable & solvable_r )
258 { return makeResObject( solvable_r ); }
260 /** Directly create a certain kind of ResObject from \ref sat::Solvable. */
262 inline typename ResTraits<_Res>::PtrType asKind( const sat::Solvable & solvable_r )
263 { return make<_Res>( solvable_r ); }
265 /** Convert ResObject::Ptr into Ptr of a certain Kind.
266 * \return \c NULL iff \a p is \c NULL or points to a Resolvable
267 * not of the specified Kind.
270 * asKind<Package>(resPtr);
274 inline typename ResTraits<_Res>::PtrType asKind( const ResObject::Ptr & p )
275 { return dynamic_pointer_cast<_Res>(p); }
278 inline typename ResTraits<_Res>::constPtrType asKind( const ResObject::constPtr & p )
279 { return dynamic_pointer_cast<const _Res>(p); }
282 inline typename ResTraits<_Res>::constPtrType ResObject::asKind() const
283 { return dynamic_cast<const _Res *>( this ); }
286 inline typename ResTraits<_Res>::PtrType ResObject::asKind()
287 { return dynamic_cast<_Res *>( this ); }
289 /////////////////////////////////////////////////////////////////
291 ///////////////////////////////////////////////////////////////////
292 #endif // ZYPP_RESOBJECT_H