00001 #ifndef _PkgSet_h 00002 #define _PkgSet_h 00003 00004 #include <list> 00005 #include <map> 00006 #include <y2util/hash.h> 00007 #include <y2pm/PMSolvablePtr.h> 00008 #include <y2pm/PkgRevRel.h> 00009 00010 inline size_t hashfun( const PkgName & ustr_r ) { 00011 return hashfun( (const Ustring &)ustr_r ); 00012 } 00013 00028 class PkgSet { 00029 public: 00030 typedef std::map<PkgName,PMSolvablePtr> PkgList_type; 00031 typedef PkgList_type::iterator iterator; 00032 typedef PkgList_type::const_iterator const_iterator; 00033 00034 typedef std::list<PkgRevRelation> RevRelList_type; 00035 typedef RevRelList_type::iterator RevRelList_iterator; 00036 typedef RevRelList_type::const_iterator RevRelList_const_iterator; 00037 00038 typedef std::map<PkgName,RevRelList_type> InvRel_type; 00039 typedef InvRel_type::iterator InvRel_iterator; 00040 typedef InvRel_type::const_iterator InvRel_const_iterator; 00041 00042 typedef PMSolvable::PkgRelList_type& (*getAdditionalProvides_callback)( constPMSolvablePtr ptr ); 00043 00044 typedef std::list<constPMSolvablePtr> SolvableList; 00045 00046 private: 00047 // list of pointers to package contained in this set (the pointers go into 00048 // the pool) 00049 PkgList_type contents; 00050 // reverse package relations 00051 InvRel_type _required; 00052 InvRel_type _conflicted; 00053 InvRel_type _provided; 00054 InvRel_type _obsoleted; 00055 00056 getAdditionalProvides_callback _additionalprovides_callback; 00057 00058 public: 00059 // default copy constructor and assigment are ok 00060 00061 PkgSet(); 00062 00063 ~PkgSet(); 00064 00065 bool empty() const; 00066 00067 unsigned size() const; 00068 00074 void add( PMSolvablePtr pkg, bool force = false ); 00075 00081 void remove( PMSolvablePtr pkg ); 00082 00084 void remove( PkgName name ); 00085 00086 /* notification from PkgPool that a pkg has a new provides 00087 <b>obsolete</b> 00088 */ 00089 void new_provides( PMSolvablePtr pkg, const PkgRelation& prov ); 00090 00095 PMSolvablePtr lookup( const PkgName& name ) const; 00096 00097 PMSolvablePtr operator[] ( const PkgName& name ) const { return lookup(name); } 00101 bool includes( const PkgName& name ) const; 00102 00103 // iterator (steps through all contained packages) 00104 iterator begin() { return contents.begin(); } 00105 iterator end() { return contents.end(); } 00106 const_iterator begin() const { return contents.begin(); } 00107 const_iterator end() const { return contents.end(); } 00108 00127 const InvRel_type& required() const { return _required; } 00128 const InvRel_type& conflicted() const { return _conflicted; } 00129 const InvRel_type& provided() const { return _provided; } 00130 const InvRel_type& obsoleted() const { return _obsoleted; } 00131 00132 static const RevRelList_type& getRevRelforPkg(const InvRel_type&, const PkgName&); 00133 00134 // for convenience: directly return an iterator 00135 #define decl_InvRel_iterators(name) \ 00136 InvRel_iterator name##_begin() { \ 00137 return _##name.begin(); } \ 00138 InvRel_const_iterator name##_begin() const { \ 00139 return _##name.begin(); } \ 00140 InvRel_iterator name##_end() { \ 00141 return _##name.end(); } \ 00142 InvRel_const_iterator name##_end() const { \ 00143 return _##name.end(); } 00144 00145 decl_InvRel_iterators(required) 00146 decl_InvRel_iterators(conflicted) 00147 decl_InvRel_iterators(provided) 00148 decl_InvRel_iterators(obsoleted) 00149 00150 00153 void setAdditionalProvidesCallback( getAdditionalProvides_callback callback ) 00154 { 00155 _additionalprovides_callback = callback; 00156 } 00157 00161 getAdditionalProvides_callback AdditionalProvidesCallback() const 00162 { 00163 return _additionalprovides_callback; 00164 } 00165 00166 std::ostream& dumpOn(std::ostream& os); 00167 }; 00168 00169 #endif /* _PkgSet_h */ 00170 00171 00172 // Local Variables: 00173 // tab-width: 4 00174 // End: