00001 #ifndef _PkgRelation_h 00002 #define _PkgRelation_h 00003 00004 #include <list> 00005 00006 #include <y2pm/PkgName.h> 00007 #include <y2pm/PkgEdition.h> 00008 #include <y2pm/PMSolvablePtr.h> 00009 00010 class PkgRelation { 00011 PkgName _name; 00012 rel_op _op; 00013 PkgEdition _edition; 00014 bool _isprereq; // whether this is a prerequirement 00015 public: 00016 PkgRelation( const PkgName& n ) : 00017 _name(n), _op(NONE), _isprereq(false) {}; 00018 PkgRelation( const PkgName& n, rel_op o, const PkgEdition& e ) : 00019 _name(n), _op(o), _edition(e), _isprereq(false) {}; 00020 // default copy constructor and assigment are ok 00021 00022 const PkgName& name() const { return _name; } 00023 rel_op op() const { return _op; } 00024 const PkgEdition& edition() const { return _edition; } 00025 00026 // return true if this relation holds given a package (providing itself) 00027 // or another relation (which is a provides relation) 00028 bool matches( constPMSolvablePtr pkg ) const; 00029 bool matches( const PkgRelation & rel ) const; 00030 00031 bool operator==( const PkgRelation& r2 ) const { 00032 return( _name == r2._name && _op == r2._op && 00033 (_op == NONE || _edition == r2._edition) ); 00034 } 00035 bool operator!=( const PkgRelation& r2 ) const { return !operator==(r2); } 00036 00040 std::string asString() const; 00041 00045 void setPreReq(bool yes) { _isprereq = yes; } 00046 00050 bool isPreReq() const { return _isprereq; } 00051 00055 bool isFileRel() const { return( _name->size() && _name->at( 0 ) == '/' ); } 00056 00060 friend std::ostream& operator<<(std::ostream&, const PkgRelation&); 00061 00062 public: 00063 00068 static std::string toString( const PkgRelation & t ); 00069 00074 static PkgRelation fromString( std::string s ); 00075 00079 static std::list<PkgRelation> parseRelations( const std::string & data_tr ); 00080 00081 private: 00082 00083 static rel_op string2DepCompare( const std::string & str_tr ); 00084 }; 00085 00086 #endif /* _PkgRelation_h */ 00087 00088 00089 // Local Variables: 00090 // tab-width: 4 00091 // End: