Boost logo

Boost Users :

From: Joaquin M Lopez Munoz (joaquin_at_[hidden])
Date: 2006-04-17 15:26:14


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 list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net