 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
John Grabner Guest
|
Posted: Mon Aug 07, 2006 9:10 am Post subject: How do I make this into a hierachy |
|
|
I have a list of classes. Each class has a list of base classes. How do
I turn that into a hierarchy?
i.e.
Class Base classes
C1 B1
B1 -
C2 C1
C3 B1
C4 -
B2 -
C5 B2
B1 -
C1 -
C2
C3
B2 -
C5
C4
Some classes have multiple base classes.
John.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Victor Bazarov Guest
|
Posted: Tue Aug 08, 2006 12:30 am Post subject: Re: How do I make this into a hierachy |
|
|
John Grabner wrote:
| Quote: | I have a list of classes. Each class has a list of base classes. How
do I turn that into a hierarchy?
i.e.
Class Base classes
C1 B1
B1 -
C2 C1
C3 B1
C4 -
B2 -
C5 B2
B1 -
C1 -
C2
C3
B2 -
C5
C4
Some classes have multiple base classes.
|
I think this is covered in the FAQ 5.2.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
John Grabner Guest
|
Posted: Tue Aug 08, 2006 9:10 am Post subject: Re: How do I make this into a hierachy |
|
|
Victor Bazarov wrote:
| Quote: | John Grabner wrote:
I have a list of classes. Each class has a list of base classes. How
do I turn that into a hierarchy?
i.e.
Class Base classes
C1 B1
C1 B3
B1 -
C2 C1
C3 B1
C4 -
B2 -
C5 B2
B1 -
C1 -
C2
C3
B2 -
C5
B3 - |
C1
| Quote: | C4
Some classes have multiple base classes.
I think this is covered in the FAQ 5.2.
V
This is not a homework assignment. |
I have a multimap consisting of a key, being a class, and the value,
which is its base class; if it has one. I want to print out the class
hierarchy.
What algorithm do I need to do this.
John.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Alf P. Steinbach Guest
|
Posted: Tue Aug 08, 2006 3:39 pm Post subject: Re: How do I make this into a hierachy |
|
|
* John Grabner, in [comp.lang.c++.moderated]:
| Quote: | Victor Bazarov wrote:
I think this is covered in the FAQ 5.2.
This is not a homework assignment.
|
As the responses so far have indicated, the question is at least a
/little/ vague. Please also see FAQ item 5.8.
I'm assuming that the description
| Quote: | I have a multimap consisting of a key, being a class, and the value,
which is its base class; if it has one. I want to print out the class
hierarchy.
What algorithm do I need to do this.
|
means:
Given a multimap
std::multi_map<string, string>
that maps C++ class names to base class names, where a class named n
that does not have any base classes is represented by (n, ""), and where
no other classes have entries with empty value string, how does one turn
that into a corresponding multimap that maps class names to derived
class names, so that a tree (forest, actually) can be easily displayed?
AFAIK the language or standard library offers no direct help in that,
and I think that
* the question doesn't belong in [clc++m] but rather in e.g.
[comp.programming], or perhaps some other group.
Follow-ups set to [comp.programming].
Cheers,
- Alf
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
werasm Guest
|
Posted: Tue Aug 08, 2006 7:42 pm Post subject: Re: How do I make this into a hierachy |
|
|
John Grabner wrote:
| Quote: | I have a list of classes. Each class has a list of base classes. How do
I turn that into a hierarchy?
|
See http://en.wikipedia.org/wiki/Composite_pattern
If I understand you correctly, you may be interested in the Composite
Pattern.
//Defines your interface
struct Base
{
virtual void print() = 0; //perhaps const
};
class Leaf_HierarchA : public Base
{
//Implements print ...
};
class Leaf_HierachB : public Base
{
//Implements print...
};
class Composite : public Base
{
public:
void add( Base& );
void remove( Base& );
virtual void print()
{
//for each item in leaves_, call print...
}
private:
std::list<Base*> leaves_;
};
One does get variations on this implementation, such as making Base
concrete - assuming all leaves will have the possibility of being
composite:
struct Base
{
public:
//...Constructors etc...
void add( Base& );
void remove( Base& );
void print()
{
//For each leave, call doPrint.
}
private:
virtual void doPrint() = 0; //perhaps const - default may throw...
std::list<Base*> leaves_;
};
Cheers,
W
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|