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

A

alan.f22

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
 
I

Ian Collins

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 said:
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?
 
A

alan.f22

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 said:
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


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.
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top