Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

PkgEdition.h

Go to the documentation of this file.
00001 #ifndef _PkgEdition_h
00002 #define _PkgEdition_h
00003 
00004 #include <ctime>
00005 #include <string>
00006 #include <iosfwd>
00007 
00009 
00010 enum rel_op { NONE, EQ, NE, LT, LE, GT, GE };
00011 
00016 extern rel_op
00017 str2rel_op( const std::string & str_r );
00018 
00019 extern std::string
00020 asString( rel_op op_r );
00021 
00022 extern std::ostream &
00023 operator<<( std::ostream & str, rel_op obj );
00024 
00026 
00046 class PkgEdition {
00047 
00048   public:
00049 
00050     enum type_enum { NORMAL, MAXIMUM, UNSPEC };
00051 
00052   private:
00053 
00054     // Use a 'version-release' form for these strings.
00055     // (i.e. exactly one '-')
00056     static const std::string _str_UNSPEC;
00057     static const std::string _str_MAXIMUM;
00058 
00059     type_enum   _type;
00060     unsigned    _epoch;
00061     std::string _version;
00062     std::string _release;
00063     time_t      _buildtime;
00064 
00065     bool edition_eq( const PkgEdition& e2 ) const;
00066     bool edition_lt( const PkgEdition& e2 ) const;
00067 
00071     int rpmvercmp( const std::string & a, const std::string & b ) const;
00072 
00097     void xconstruct( type_enum xtype,
00098                      unsigned epoch, const std::string & v, const std::string & r,
00099                      time_t buildtime );
00100 
00101   public:
00102 
00107     PkgEdition( type_enum t = NORMAL ) {
00108       xconstruct(t,0,"","",0);
00109     }
00114     PkgEdition( const std::string & v, const std::string & r = "", time_t bt = 0 ) {
00115       xconstruct(NORMAL,0,v,r,bt);
00116     }
00121     PkgEdition( const std::string & v, time_t bt ) {
00122       xconstruct(NORMAL,0,v,"",bt);
00123     }
00128     PkgEdition( unsigned e, const std::string & v, const std::string & r = "", time_t bt = 0 ) {
00129       xconstruct(NORMAL,e,v,r,bt);
00130     }
00135     PkgEdition( unsigned e, const std::string & v, time_t bt ) {
00136       xconstruct(NORMAL,e,v,"",bt);
00137     }
00138 
00139     ~PkgEdition() {}
00140 
00141     const std::string & version() const {
00142       switch( _type ) {
00143       case MAXIMUM:
00144         return _str_MAXIMUM;
00145       case UNSPEC:
00146         return _str_UNSPEC;
00147       case NORMAL:
00148         break;
00149       }
00150       return _version;
00151     }
00152 
00153     const std::string & release() const {
00154       return _release;
00155     }
00156 
00157     int epoch() const { return _epoch; }
00158 
00159     bool has_epoch() const { return _epoch; }
00160 
00161     time_t buildtime() const { return _buildtime; }
00162 
00163     bool is_unspecified() const { return _type == UNSPEC; }
00164 
00165     bool is_maximum() const { return _type == MAXIMUM; }
00166 
00167     bool compare( rel_op op, const PkgEdition& e2 ) const;
00168     bool operator==( const PkgEdition& e2 ) const { return compare( EQ, e2 ); }
00169     bool operator!=( const PkgEdition& e2 ) const { return compare( NE, e2 ); }
00170     bool operator< ( const PkgEdition& e2 ) const { return compare( LT, e2 ); }
00171     bool operator<=( const PkgEdition& e2 ) const { return compare( LE, e2 ); }
00172     bool operator> ( const PkgEdition& e2 ) const { return compare( GT, e2 ); }
00173     bool operator>=( const PkgEdition& e2 ) const { return compare( GE, e2 ); }
00174 
00175     std::string asString() const;
00176 
00177     friend std::ostream& operator<<( std::ostream&, const PkgEdition& );
00178 
00179   public:
00180 
00185     static std::string toString( const PkgEdition & t );
00186 
00191     static PkgEdition fromString( std::string s );
00192 
00193 };
00194 
00195 #endif  // _PkgEdition_h

Generated on Mon Sep 12 21:52:13 2005 for yast2-packagemanager by  doxygen 1.4.4