
Hi Joaquin, First of all thanks for your time and response. I have it working as follows, but seems I have to recalculate iterators if in case I later on modify group associated with that access point. Is there any way that iterators will know automatically update when I update access point in future to some other group? Let me know if you have come across that one. I am going to look in your code in detail and get back to you in case of any questions. Thanks Priyank // class Access point test class Access_Point { public: Access_Point(int id, int paging_group):id_(id), pg_(paging_group) { } bool by_id(int _id) const { return (_id == id_); } int paging_group(int _pg) const { return (_pg == pg_); } int id() const { return id_; } int pg() const { return pg_; } int pg(int _pg) { pg_ = _pg; } friend ostream& operator << (ostream& _os, const Access_Point& _ap); private: int id_; int pg_; }; ostream& operator << (ostream& _os, const Access_Point& _ap) { _os << "Id: " << _ap.id_ << "Pg: " << _ap.pg_ << endl; return _os; } // tag ids struct hashed_objs { }; struct paging_group { }; // Create multi index container typedef multi_index_container< Access_Point*, indexed_by< hashed_unique< tag<hashed_objs>, const_mem_fun<Access_Point, int, &Access_Point::id> >, ordered_non_unique < tag<paging_group>, const_mem_fun<Access_Point, int, &Access_Point::pg>
Access_Points;
int ACE_MAIN (int, ACE_TCHAR *[]) { // ACCESS POINT CHECK Access_Points pool; Access_Point * a1 = new Access_Point(1, 1); Access_Point * a2 = new Access_Point(2, 1); Access_Point * a3 = new Access_Point(3, 2); Access_Point * a4 = new Access_Point(4, 1); // insert all the access points pool.insert(a1); pool.insert(a2); pool.insert(a3); // get iterator index_iterator<Access_Points, paging_group>::type pg0, pg1; boost::tuples::tie(pg0, pg1) = get<paging_group> (pool).equal_range(1); pool.insert(a4); // print all that is there while (pg0 != pg1) { cout << *(*pg0) << endl; pg0++; } // change paging group from access point 4 a4->pg(2); // NEED TO RECALCULATE ITERATORS boost::tuples::tie(pg0, pg1) = get<paging_group> (pool).equal_range(1); while (pg0 != pg1) { cout << *(*pg0) << endl; pg0++; } // return success return 0; } -----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Joaquin M Lopez Munoz Sent: Monday, April 17, 2006 2:26 PM To: boost-users@lists.boost.org Subject: Re: [Boost-users][multi_index] Sorting object based on some specified criteria !! Patel Priyank-PPATEL1 <priyankpatel <at> motorola.com> writes:
Hi all,
I have following kind of class and having some identifier and group id associated with particular procedure. I want to know if I have to get the procedures relating particular
group for ex. (groupId == 1). How do I do using multiindex container? Can somebody please give me some hint or code if they have done something similar to what I want to do?
Hello Priyank, I'm not sure I've understood what you're after, but let me try anyway: As you'll search for group, you'll need an additional index (the one you've set up is based on process ID). The following has not been compiled, beware typos: struct id {}; struct group {}; typedef multi_index_container< Procedure*, indexed_by< hashed_unique< tag<id>, const_mem_fun<Procedure, int, &Procedure::get_id> > >, hashed_non_unique< tag<group>, const_mem_fun<Procedure, int, &Procedure::get_group> > > >
Procedure_Hashed_Pool; typedef Procedure_Hashed_Pool:: index<id>::type Procedure_By_Id; typedef Procedure_Hashed_Pool:: index<group>::type Procedure_By_Group; (I've decided to make the new index hashed non-unique, you could also have it ordered non-unique if you need the elements to be sorted by group ID --hashing only guarantees fast retrieval.) And now you can simply use equal_range() on this index to do what you want: int gr=...; const Procedure_By_Group& procedure_bg= procedure_pool.get<group>(); std::pair< Procedure_By_Group::iterator, Procedure_By_Group::iterator
p=procedure_bg.equal_range(gr);
p will hold the range of elements with group ID == gr. Is this what you were after? Joaquín M López Muñoz Telefónica, Investigación y Desarrollo _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users