00001 #ifndef _PkgEdition_h
00002 #define _PkgEdition_h
00003
00004 #include <ctime>
00005 #include <string>
00006 #include <iosfwd>
00007
00008 enum rel_op { NONE, EQ, NE, LT, LE, GT, GE };
00009 extern const char* op_str[];
00010
00030 class PkgEdition {
00031
00032 public:
00033
00034 enum type_enum { NORMAL, MAXIMUM, UNSPEC };
00035
00036 private:
00037
00038
00039
00040 static const std::string _str_UNSPEC;
00041 static const std::string _str_MAXIMUM;
00042
00043 type_enum _type;
00044 unsigned _epoch;
00045 std::string _version;
00046 std::string _release;
00047 time_t _buildtime;
00048
00049 bool edition_eq( const PkgEdition& e2 ) const;
00050 bool edition_lt( const PkgEdition& e2 ) const;
00051
00055 int rpmvercmp( const std::string & a, const std::string & b ) const;
00056
00081 void xconstruct( type_enum xtype,
00082 unsigned epoch, const std::string & v, const std::string & r,
00083 time_t buildtime );
00084
00085 public:
00086
00091 PkgEdition( type_enum t = NORMAL ) {
00092 xconstruct(t,0,"","",0);
00093 }
00098 PkgEdition( const std::string & v, const std::string & r = "", time_t bt = 0 ) {
00099 xconstruct(NORMAL,0,v,r,bt);
00100 }
00105 PkgEdition( const std::string & v, time_t bt ) {
00106 xconstruct(NORMAL,0,v,"",bt);
00107 }
00112 PkgEdition( unsigned e, const std::string & v, const std::string & r = "", time_t bt = 0 ) {
00113 xconstruct(NORMAL,e,v,r,bt);
00114 }
00119 PkgEdition( unsigned e, const std::string & v, time_t bt ) {
00120 xconstruct(NORMAL,e,v,"",bt);
00121 }
00122
00123 ~PkgEdition() {}
00124
00125 const std::string & version() const {
00126 switch( _type ) {
00127 case MAXIMUM:
00128 return _str_MAXIMUM;
00129 case UNSPEC:
00130 return _str_UNSPEC;
00131 case NORMAL:
00132 break;
00133 }
00134 return _version;
00135 }
00136
00137 const std::string & release() const {
00138 return _release;
00139 }
00140
00141 int epoch() const { return _epoch; }
00142
00143 bool has_epoch() const { return _epoch; }
00144
00145 time_t buildtime() const { return _buildtime; }
00146
00147 bool is_unspecified() const { return _type == UNSPEC; }
00148
00149 bool is_maximum() const { return _type == MAXIMUM; }
00150
00151 bool compare( rel_op op, const PkgEdition& e2 ) const;
00152 bool operator==( const PkgEdition& e2 ) const { return compare( EQ, e2 ); }
00153 bool operator!=( const PkgEdition& e2 ) const { return compare( NE, e2 ); }
00154 bool operator< ( const PkgEdition& e2 ) const { return compare( LT, e2 ); }
00155 bool operator<=( const PkgEdition& e2 ) const { return compare( LE, e2 ); }
00156 bool operator> ( const PkgEdition& e2 ) const { return compare( GT, e2 ); }
00157 bool operator>=( const PkgEdition& e2 ) const { return compare( GE, e2 ); }
00158
00159 std::string asString() const;
00160
00161 friend std::ostream& operator<<( std::ostream&, const PkgEdition& );
00162
00163 public:
00164
00169 static std::string toString( const PkgEdition & t );
00170
00175 static PkgEdition fromString( std::string s );
00176
00177 };
00178
00179 #endif // _PkgEdition_h