S
shane
From searching around, Ive seen this question asked numerous times, but
havent seen a usable answer unfortuantly.
What Im trying to do is something I would have thought would be quite
common, but there just seems to be no information on the topic that I can
find. Basically I need to store a directory structure in memory, from a flat
list of files and paths. ie given:
C:\dir\dir1\abc.txt
C:\dir\toop.txt
C:\temp\acd\test.txt
etc I need to create a directory structure, and represent this in a
tree-view control and give it basic 'explorer' style functionality. I think
I would need to use either map or hash_map, which itself contains a link to
another map. I have started with the following:
typedef stdex::hash_map<std::string, hm> hm;
Obviously thats not really possible, so instead I have:
typedef stdex::hash_map<std::string, void*> hm;
And just use NULL if there are no children, or create a "new" hm if there
are children. The std::string is the full path. I havent really tried this
fully, but I would suspect it would work. For holding the files, I would
probably just use a pair instead, which has both a std::list and a void* to
another hash_map/list.
While I think this would probably work, I get the feeling I am reinventing
the wheel here, yet I havent seen anything like this anywhere else. Which
gives me the impression I am probably doing something wrong Surely there
is an example for holding a hierarchial file directory type structure in
memory somewhere around? All Ive seen is overly complex amateur
implementations of fully fledged tree templates. Can someone give me a hand
with this please ?
Cheers,
Shane
havent seen a usable answer unfortuantly.
What Im trying to do is something I would have thought would be quite
common, but there just seems to be no information on the topic that I can
find. Basically I need to store a directory structure in memory, from a flat
list of files and paths. ie given:
C:\dir\dir1\abc.txt
C:\dir\toop.txt
C:\temp\acd\test.txt
etc I need to create a directory structure, and represent this in a
tree-view control and give it basic 'explorer' style functionality. I think
I would need to use either map or hash_map, which itself contains a link to
another map. I have started with the following:
typedef stdex::hash_map<std::string, hm> hm;
Obviously thats not really possible, so instead I have:
typedef stdex::hash_map<std::string, void*> hm;
And just use NULL if there are no children, or create a "new" hm if there
are children. The std::string is the full path. I havent really tried this
fully, but I would suspect it would work. For holding the files, I would
probably just use a pair instead, which has both a std::list and a void* to
another hash_map/list.
While I think this would probably work, I get the feeling I am reinventing
the wheel here, yet I havent seen anything like this anywhere else. Which
gives me the impression I am probably doing something wrong Surely there
is an example for holding a hierarchial file directory type structure in
memory somewhere around? All Ive seen is overly complex amateur
implementations of fully fledged tree templates. Can someone give me a hand
with this please ?
Cheers,
Shane