stl data structure to represent a tree

P

puzzlecracker

I am looking for a data structure or perhaps a container that I can use
to represent linux-like file system (each node in the tree containes
needed fields, i.e. permissions, d/f, etc: for this I am thing of
mapping node to a structure.. any commetns about this).


Any suggestions (other then implementing my own tree)?
Thanks
 
D

Daw

Maybe you can make a structure like

struct FS {
// permissions, d/f etc.
};

and then use some container like

std::vector<FS> nodes;
 
P

puzzlecracker

I am thinking to have something like this:

struct Entry{

union {
std::stringBuffer info; // dont remembe the exact equivalent for
sting buffer :)
std::vector<Entry>;
}type;


};
what is the best way to distinguesh the current content of the union?

thx
 
P

puzzlecracker

I forgot that unions have some issues with nontrivial ctors...

so here my another attempt


struct Entry{

all flags shared by directory and files



};


struct FileEntry:Entry{

string buffer

};



struct DirEntry:Entry{

vector<Entry> ve;

};

I am thing along this lines..


I am also considering forwarding approach... any pro/cons?
 
J

John Harrison

puzzlecracker said:
I forgot that unions have some issues with nontrivial ctors...

so here my another attempt


struct Entry{

all flags shared by directory and files



};


struct FileEntry:Entry{

string buffer

};



struct DirEntry:Entry{

vector<Entry> ve;

};

I am thing along this lines..


I am also considering forwarding approach... any pro/cons?

Your code above suffers from slicing, you need pointers (or possible
smart pointers).

struct DirEntry:Entry{

vector<Entry*> ve;

};

You need to read up on polymorphism, which is what you are heading
towards above.

I'm not sure what you mean by a forwarding approach.

john
 

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,754
Messages
2,569,527
Members
44,999
Latest member
MakersCBDGummiesReview

Latest Threads

Top