You're probably right that templates and such would be overkill for these kinds of files. Most of my error checking isn't needed for these files, either, but they're there in case someone does something silly.
The files would look something like this. These are what would be the definition lines for the files, which I can't remember off the top of my head, and am too lazy to look up. But you certainly get the idea. All other lines of the file just fill in the data that would go in each column. Easy to read, easy to split up, etc.
Code:
Filetype One
Name;ID;Start Year; Rank 1 Year; Rank 2 Year; Rank 3 Year; Traits;Type;......
Filetype Two
ID;Position;Start Year;Death Year;Position;Personality;.....
This is not the whole of the story, however. In type two, we can have the same name defined twice, and they will refer to the same guy. Because the previous game treated every entry as its own person, you could have one version of the guy die while all others of him live. So I had to handle the case where we have another definition of the guy. The Position and Personality must be kept together.
In both cases, I defined a struct for the filetype, which a variable for each bit of information that we want to read.
e.g.
Code:
struct type_one {
int startYear;
std::string name;
std::string type;
......
}
For the second type, its class has a map member varialbe where the key is the name of the guy, and the value is the struct. I use the find() function to find anyone with the same name. If he already exists, we add our copy's position and personality into a list with a small struct type (just two strings). If not, we add a new guy to our map. I collect all of the definitions in the file and then write them all at once.
The number of lines to read varies quite a bit. The smallest file is two lines (with one guy defined), but the largest I've encountered had like 2800 lines and 1905 individual people defined. For the largest file it takes, in my estimation, less than a second or two to read, parse, and write. I'm sure there are ways to speed up the program buy
The first type can suffice with any sort of collection type because every line is its own definition. I used maps, for the moment, so that I could define the name as a key and have it sort for me. I could write a comparison operator for my struct so that I can use other collection types, however.
I don't have to check for name collisions. Just load all the data we need and go. I could get away with writing each definition to a file as it's parsed, but for now I read the whole file and then write out at one time. This helps modders, as the map sorts everything by name. Where multiple copies of the same name occur, we differentiate them by their types. If a name is repeated and has the same type, the old one is destroyed and overwritten. This is because it is about 99.999% likely that the modder was using the second definition to model things, like differing skill over time.
For the moment, I just went with the simple generic handler class with two children, one for each type. I was just wondering if someone could have thought of some more advanced or elegant way of handling this.