1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/detail/PackageImplIf.h
12 #ifndef ZYPP_DETAIL_PACKAGEIMPLIF_H
13 #define ZYPP_DETAIL_PACKAGEIMPLIF_H
17 #include "zypp/detail/ResObjectImplIf.h"
18 #include "zypp/Edition.h"
19 #include "zypp/Arch.h"
20 #include "zypp/Changelog.h"
22 ///////////////////////////////////////////////////////////////////
24 { /////////////////////////////////////////////////////////////////
28 ///////////////////////////////////////////////////////////////////
30 { /////////////////////////////////////////////////////////////////
32 ///////////////////////////////////////////////////////////////////
34 // CLASS NAME : PackageImplIf
36 /** Abstact Package implementation interface.
38 class PackageImplIf : public ResObjectImplIf
41 typedef Package ResType;
45 CheckSum(const std::string & type, const std::string & checksum)
49 std::string type() { return _type; }
50 std::string checksum() { return _checksum; }
53 std::string _checksum;
58 BaseVersion(const Edition & edition,
59 const CheckSum & checksum,
60 const Date & buildtime)
63 , _buildtime(buildtime)
65 Edition edition() const { return _edition; }
66 CheckSum checksum() const { return _checksum; }
67 Date buildtime() const { return _buildtime; }
70 PackageImplIf::CheckSum _checksum;
76 DeltaRpm(const Arch & arch,
77 const std::string & filename,
78 const ByteCount & downloadsize,
79 const CheckSum & checksum,
80 const Date & buildtime,
81 const BaseVersion & base_version)
84 , _downloadsize(downloadsize)
86 , _buildtime(buildtime)
87 , _base_version(base_version)
89 Arch arch() { return _arch; }
90 std::string filename() { return _filename; }
91 ByteCount downloadsize() { return _downloadsize; }
92 CheckSum checksum() { return _checksum; }
93 Date buildtime() { return _buildtime; }
94 BaseVersion baseVersion() { return _base_version; }
97 std::string _filename;
98 ByteCount _downloadsize;
101 BaseVersion _base_version;
106 PatchRpm(const Arch & arch,
107 const std::string & filename,
108 const ByteCount & downloadsize,
109 const CheckSum & checksum,
110 const Date & buildtime,
111 const std::list<BaseVersion> & base_versions)
113 , _filename(filename)
114 , _downloadsize(downloadsize)
115 , _checksum(checksum)
116 , _buildtime(buildtime)
117 , _base_versions(base_versions)
119 Arch arch() { return _arch; }
120 std::string filename() { return _filename; }
121 ByteCount downloadsize() { return _downloadsize; }
122 CheckSum checksum() { return _checksum; }
123 Date buildtime() { return _buildtime; }
124 std::list<BaseVersion> baseVersions() { return _base_versions; }
127 std::string _filename;
128 ByteCount _downloadsize;
131 std::list<BaseVersion> _base_versions;
137 * @short Holds data about how much space will be needed per directory
140 Entry() : _size(0), _files(0) {};
141 Entry(const std::string& path_r,
142 const unsigned size_r = 0,
143 const unsigned files_r = 0)
144 : path(path_r), _size(size_r), _files(files_r)
146 const std::string path;
147 mutable unsigned _size;
148 mutable unsigned _files;
149 friend std::ostream & operator<<( std::ostream & str, const Entry & obj );
151 * Test for equality based on directory name.
153 bool operator==( const Entry & rhs ) const {
154 return path == rhs.path;
157 * Order based on directory name.
159 bool operator<( const Entry & rhs ) const {
160 return path < rhs.path;
163 * Return true if this entry denotes a directory equal to or below rhs._dirname.
165 bool isBelow( const Entry & rhs ) const {
166 // whether _dirname has prefix rhs._dirname
167 return( path.compare( 0, rhs.path.size(), rhs.path ) == 0 );
170 * Return true if this entry denotes a directory equal to or below dirname_r.
172 bool isBelow( const std::string & dirname_r ) const {
173 return isBelow( Entry( dirname_r ) );
179 const Entry & operator=( const Entry & rhs ) const {
183 * Numerical operation based on size and files values.
185 const Entry & operator+=( const Entry & rhs ) const {
187 _files += rhs._files;
191 * Numerical operation based on size and files values.
193 const Entry & operator-=( const Entry & rhs ) const {
195 _files -= rhs._files;
200 typedef std::set<Entry> EntrySet;
206 * Add an entry. If already present, sum up the new entries size and files value.
208 void add( const Entry & newent_r ) {
209 std::pair<EntrySet::iterator,bool> res = _dirs.insert( newent_r );
211 *res.first += newent_r;
215 * Add an entry. If already present, sum up the new entries size and files value.
217 void add( const std::string & dirname_r, const unsigned & size_r = 0, const unsigned & files_r = 0 ) {
218 add( Entry( dirname_r, size_r, files_r ) );
223 unsigned size() const { return _dirs.size(); }
227 void clear() { _dirs.clear(); }
229 * Sum up any entries for dirname_r and its descendants and remove them
230 * on the fly. Return the result.
232 Entry extract( const std::string & dirname_r );
236 typedef EntrySet::iterator iterator;
237 typedef EntrySet::reverse_iterator reverse_iterator;
240 * Forward iterator pointing to the first entry (if any)
242 iterator begin() { return _dirs.begin(); }
244 * Forward iterator pointing behind the last entry.
246 iterator end() { return _dirs.end(); }
248 * Reverse iterator pointing to the last entry (if any)
250 reverse_iterator rbegin() { return _dirs.rbegin(); }
252 * Reverse iterator pointing before the first entry.
254 reverse_iterator rend() { return _dirs.rend(); }
256 typedef EntrySet::const_iterator const_iterator;
257 typedef EntrySet::const_reverse_iterator const_reverse_iterator;
260 * Forward const iterator pointing to the first entry (if any)
262 const_iterator begin() const { return _dirs.begin(); }
264 * Forward const iterator pointing behind the last entry.
266 const_iterator end() const { return _dirs.end(); }
268 * Reverse const iterator pointing to the last entry (if any)
270 const_reverse_iterator rbegin() const { return _dirs.rbegin(); }
272 * Reverse const iterator pointing before the first entry.
274 const_reverse_iterator rend()const { return _dirs.rend(); }
278 friend std::ostream & operator<<( std::ostream & str, const PackageImplIf::DiskUsage & obj );
284 * @short Holds Data about file and file type
292 FileData(const std::string &name,
293 const std::string &type)
294 : name(name), type(type)
300 /** \name Rpm Package Attributes. */
303 virtual Date buildtime() const PURE_VIRTUAL;
305 virtual std::string buildhost() const PURE_VIRTUAL;
307 virtual Date installtime() const PURE_VIRTUAL;
309 virtual std::string distribution() const PURE_VIRTUAL;
311 virtual Vendor vendor() const PURE_VIRTUAL;
313 virtual Label license() const PURE_VIRTUAL;
315 virtual std::string packager() const PURE_VIRTUAL;
317 virtual PackageGroup group() const PURE_VIRTUAL;
319 virtual Changelog changelog() const PURE_VIRTUAL;
320 /** Don't ship it as class Url, because it might be
321 * in fact anything but a legal Url. */
322 virtual std::string url() const PURE_VIRTUAL;
324 virtual std::string os() const PURE_VIRTUAL;
326 virtual Text prein() const PURE_VIRTUAL;
328 virtual Text postin() const PURE_VIRTUAL;
330 virtual Text preun() const PURE_VIRTUAL;
332 virtual Text postun() const PURE_VIRTUAL;
334 virtual ByteCount sourcesize() const PURE_VIRTUAL;
336 virtual ByteCount archivesize() const PURE_VIRTUAL;
338 virtual Text authors() const PURE_VIRTUAL;
340 virtual Text filenames() const PURE_VIRTUAL;
343 /** \name Additional Package Attributes.
344 * \todo review what's actually needed here. Maybe worth grouping
345 * all the package rertieval related stuff in a class. Easier to ship
350 virtual License licenseToConfirm() const PURE_VIRTUAL;
353 virtual std::string sourceloc() const PURE_VIRTUAL;
355 virtual void du( PkgDu & dudata_r ) const PURE_VIRTUAL;
357 virtual std::string location() const PURE_VIRTUAL;
359 virtual unsigned int medianr() const PURE_VIRTUAL;
361 virtual PackageKeywords keywords() const PURE_VIRTUAL;
363 virtual std::string md5sum() const PURE_VIRTUAL;
365 virtual std::string externalUrl() const PURE_VIRTUAL;
367 virtual std::list<Edition> patchRpmBaseVersions() const PURE_VIRTUAL;
369 virtual ByteCount patchRpmSize() const PURE_VIRTUAL;
371 virtual bool forceInstall() const PURE_VIRTUAL;
373 virtual std::string patchRpmMD5() const PURE_VIRTUAL;
375 virtual bool isRemote() const PURE_VIRTUAL;
377 virtual PMError providePkgToInstall( Pathname& path_r ) const PURE_VIRTUAL;
379 virtual PMError provideSrcPkgToInstall( Pathname& path_r ) const PURE_VIRTUAL;
381 virtual constInstSrcPtr source() const PURE_VIRTUAL;
383 virtual std::list<PMPackageDelta> deltas() const PURE_VIRTUAL;
387 ///////////////////////////////////////////////////////////////////
389 /////////////////////////////////////////////////////////////////
390 } // namespace detail
391 ///////////////////////////////////////////////////////////////////
392 /////////////////////////////////////////////////////////////////
394 ///////////////////////////////////////////////////////////////////
395 #endif // ZYPP_DETAIL_PACKAGEIMPLIF_H