00001 /*---------------------------------------------------------------------\ 00002 | | 00003 | __ __ ____ _____ ____ | 00004 | \ \ / /_ _/ ___|_ _|___ \ | 00005 | \ V / _` \___ \ | | __) | | 00006 | | | (_| |___) || | / __/ | 00007 | |_|\__,_|____/ |_| |_____| | 00008 | | 00009 | core system | 00010 | (C) SuSE GmbH | 00011 \----------------------------------------------------------------------/ 00012 00013 File: PkgIdent.h 00014 00015 Author: Michael Andres <ma@suse.de> 00016 Maintainer: Michael Andres <ma@suse.de> 00017 00018 Purpose: 00019 00020 /-*/ 00021 #ifndef PkgIdent_h 00022 #define PkgIdent_h 00023 00024 #include <iosfwd> 00025 #include <string> 00026 00027 #include <y2pm/PkgName.h> 00028 #include <y2pm/PkgEdition.h> 00029 #include <y2pm/PkgArch.h> 00030 #include <y2pm/PMSolvablePtr.h> 00031 00033 // 00034 // CLASS NAME : PkgIdent 00038 class PkgIdent { 00039 00040 friend std::ostream & operator<<( std::ostream & str, const PkgIdent & obj ); 00041 00042 private: 00043 00044 PkgName _name; 00045 PkgEdition _edition; 00046 PkgArch _arch; 00047 00048 public: 00049 00050 PkgIdent() {} 00051 00052 PkgIdent( constPMSolvablePtr slv_r ); 00053 00054 PkgIdent( const PkgName & name_r, const PkgEdition & edition_r, const PkgArch & arch_r ) 00055 : _name( name_r ) 00056 , _edition( edition_r ) 00057 , _arch( arch_r ) 00058 {} 00059 00060 virtual ~PkgIdent() {} 00061 00062 public: 00063 00064 const PkgName & name() const { return _name; } 00065 const PkgEdition & edition() const { return _edition; } 00066 const std::string & version() const { return _edition.version(); } 00067 const std::string & release() const { return _edition.release(); } 00068 const PkgArch & arch() const { return _arch; } 00069 00073 std::string nameEd() const { return _name.asString() + '-' + _edition.asString(); } 00074 00078 std::string nameEdArch() const { return nameEd() + '.' + _arch.asString(); } 00079 00080 public: 00081 00086 friend bool std::less<PkgIdent>::operator()( const PkgIdent & lhs, const PkgIdent & rhs ) const; 00087 }; 00088 00090 // 00091 // 00092 // METHOD NAME : std::less<PkgIdent>::operator() 00093 // METHOD TYPE : bool 00094 // 00095 // Order to be used by associative std::container (set/map): 00096 // Lexicographic by _name, _edition then _arch. 00097 // 00098 inline bool std::less<PkgIdent>::operator()( const PkgIdent & lhs, const PkgIdent & rhs ) const 00099 { 00100 int r = lhs.name()->compare( rhs.name() ); 00101 if ( r != 0 ) 00102 return( r < 0 ); 00103 r = lhs.version().compare( rhs.version() ); 00104 if ( r != 0 ) 00105 return( r < 0 ); 00106 r = lhs.release().compare( rhs.release() ); 00107 if ( r != 0 ) 00108 return( r < 0 ); 00109 return( lhs.arch()->compare( rhs.arch() ) < 0 ); 00110 00111 } 00112 00114 00115 #endif // PkgIdent_h