extending an stl container and iterator to also find groups of elements

Discussion in 'C++' started by alan.f22@gmail.com, Aug 18, 2007.

  1. Guest

    HI

    First off, thanks for taking the time to read this.

    I have an class inheritance hierachy say:
    base class "E" and a bunch of derived classes (from "E") "A",
    "P", and "S"

    I have an STL vector (might change to a list) std::vector<E> which is
    populated by
    A's, P's, and S's

    Certain sequences of A's, P's and S's can be grouped to form other
    classes (composite):
    class M consists of one P and one S
    class C consists of one A and any number of M's

    What I am looking for is a way to extend/modify the STL container/
    iterator to:
    Allow me to iterate though the single vector using different types of
    iterators:
    i.e. vector<E*>::iterator, vector<M*>::iterator, vector<C*>::iterator,
    vector<A*>::iterator

    Basicly I'm looking to be able to iterate a single vector/list in a
    number of different ways so I don't have to maintain multiple vectors/
    lists for each of the composite types and specific operations I have
    to perform.


    Thanks for any advice and input
    - A
     
    , Aug 18, 2007
    #1
    1. Advertising

  2. Ian Collins Guest

    Re: extending an stl container and iterator to also find groups ofelements

    wrote:
    > HI
    >
    > First off, thanks for taking the time to read this.
    >
    > I have an class inheritance hierachy say:
    > base class "E" and a bunch of derived classes (from "E") "A",
    > "P", and "S"
    >
    > I have an STL vector (might change to a list) std::vector<E> which is
    > populated by
    > A's, P's, and S's
    >

    I doubt that, all a vector of E can hold is E objects. Did you intend
    to write std::vector<E*>?

    > Certain sequences of A's, P's and S's can be grouped to form other
    > classes (composite):
    > class M consists of one P and one S
    > class C consists of one A and any number of M's
    >

    Explain "consists of". Are you using multiple inheritance with virtual
    bases or does an M have a P and an S as members?

    > What I am looking for is a way to extend/modify the STL container/
    > iterator to:
    > Allow me to iterate though the single vector using different types of
    > iterators:
    > i.e. vector<E*>::iterator, vector<M*>::iterator, vector<C*>::iterator,
    > vector<A*>::iterator
    >

    If you want to do this, there is probably something broken in your design.

    > Basicly I'm looking to be able to iterate a single vector/list in a
    > number of different ways so I don't have to maintain multiple vectors/
    > lists for each of the composite types and specific operations I have
    > to perform.
    >

    What problem are you trying to solve this way that you can't solve
    through polymorphism and virtual methods?

    --
    Ian Collins.
     
    Ian Collins, Aug 18, 2007
    #2
    1. Advertising

  3. Guest

    On Aug 17, 7:40 pm, Ian Collins <> wrote:
    > wrote:
    > > HI

    >
    > > First off, thanks for taking the time to read this.

    >
    > > I have an class inheritance hierachy say:
    > > base class "E" and a bunch of derived classes (from "E") "A",
    > > "P", and "S"

    >
    > > I have an STL vector (might change to a list) std::vector<E> which is
    > > populated by
    > > A's, P's, and S's

    >
    > I doubt that, all a vector of E can hold is E objects. Did you intend
    > to write std::vector<E*>?
    >


    yeah that was a typo ... should be std::vector<E*>

    > > Certain sequences of A's, P's and S's can be grouped to form other
    > > classes (composite):
    > > class M consists of one P and one S
    > > class C consists of one A and any number of M's

    >
    > Explain "consists of". Are you using multiple inheritance with virtual
    > bases or does an M have a P and an S as members?
    >


    they are composites ...M has a P and S as members

    so for example in the vector sequence it may look like ...

    A P S P S S P A

    which could be grouped as

    A M M M A

    or

    C C



    > > What I am looking for is a way to extend/modify the STL container/
    > > iterator to:
    > > Allow me to iterate though the single vector using different types of
    > > iterators:
    > > i.e. vector<E*>::iterator, vector<M*>::iterator, vector<C*>::iterator,
    > > vector<A*>::iterator

    >
    > If you want to do this, there is probably something broken in your design.


    yeah maybe ... i'm trying to work with legacy code and trying use what
    is existing as much as possible, and not totally blow it up and start
    all over.

    >
    > > Basicly I'm looking to be able to iterate a single vector/list in a
    > > number of different ways so I don't have to maintain multiple vectors/
    > > lists for each of the composite types and specific operations I have
    > > to perform.

    >
    > What problem are you trying to solve this way that you can't solve
    > through polymorphism and virtual methods?
    >


    The problem is that I have a number of methods for each of the classes
    which already exist. Its more of a issue with the composite
    groupings, accessing the elements, and maintaining the sequence order
    through possible insertions and deletions at each level, than it is an
    inheritance/polymorphism/virtual method issue.

    Again I can use multiple lists for each composite level ... the E* (A
    P S) level, the M level, and the C level but would rather use one list
    and have multiple iterators.


    Thx again

    Alan
    > --
    > Ian Collins.
     
    , Aug 18, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vivi Orunitia
    Replies:
    11
    Views:
    4,481
    Martijn Lievaart
    Feb 4, 2004
  2. forester
    Replies:
    16
    Views:
    719
    Howard Hinnant
    Aug 25, 2005
  3. Replies:
    4
    Views:
    805
    Daniel T.
    Feb 16, 2006
  4. Christoph  Heindl

    STL inherit from container<T>::iterator

    Christoph Heindl, Apr 3, 2006, in forum: C++
    Replies:
    2
    Views:
    574
    Christoph Heindl
    Apr 4, 2006
  5. gallows
    Replies:
    3
    Views:
    824
    gallows
    Mar 5, 2007
Loading...

Share This Page