I'm currently struggling with using STL to create and access a vector of maps. I have seen code to do a map of vectors, but never the other way around. I'm sure this is simple, but I'm pretty new to the STL thing, so any help would be appreciated.
Here is my problem....
I have some data that is something like this:
Name: Test1
Number: 1
Description: This is a test
Name: Test2
Number:2
Length: 5
Description: This is test 2, it has different fields
Name: Test3
Length: 2
Description: This is test3, it has more fields than the rest.
Number: 3
Key: 2345654
Basically, I'm bringing data like this in from an XML file (parsed using TinyXML++ for anyone that's curious with how I'm doing it). The problem here is that fields can change, some entries can have more fields than others, fields may have different names. Basically, this XML database is very dynamic because it represents very dynamic data. So, I need a way to bring this data into C++ so that other elements can be brought into the C++ file and checked against this database. I wanted a method to make sure the data stayed with its respective label and all the data pertaining to one entry stayed together, so I thought of doing something like this:
Vector 1
(Then insert individual maps)
name = Test1
Number =1
.
.
(have other map elements for the first entry here)
.
Vector 2
name= Test2
Number = 2
.
.
.
Vector 3
.
.
.
Vector n
I'm going to use some loops to set the structure up to read in the data, parse it, and store it the maps and then the maps to a vector. However, is this even possible? I've got some code written (I don't have access to it on this machine, but I can post it later on in the day), but of course I'm getting errors.
Once the data is brought into the file, I assumed I could implement some iterators and move through the map elements in each vector element to find what I needed.
I know you all can't give me specific help until I post some code, but I still have a few questions maybe you all can help with.
1) Is this approach even logical/possible?
2) Is there a better method?
3) How would you propose implementing this or a better method?
I also stated that I was parsing this data in using TinyXML++. Does anyone have any links to some good tutorial resources. I've worked through the stuff on the TinyXML++ page, but links to any other resources/sample files would be great.
Bear in mind, I'm pretty new to the STL thing, but I'll do my best to understand help anyone can give. Thank you all.
I got this worked out, guys. Like I said, implementation really wasn't that bad. The hardest part was getting the TinyXML++ iterators where I needed them to be to pull out the necessary information. I'll post the sample code after I get it all commented out in case anyone is ever in my position in the future.