Suggestions on a saving/loading system with enumerated info

Currently I'm saving all the enumerated info by writing the enums to file and loading is working fine. The problem is if I later decide to reorder the elements of each enumeration (due to change in ranking taste for the elements, or new elements thought of that I want to place near the beginning, etc...), all the info will be mismatched upon loading. The most extreme example would be my former best friend's profile saved as _0.txt is now written as _1.txt, while my new best friend's profile being read as _0.txt is totally the wrong person. Other kinds of enumerations saved within each person's file are: CountryOfBirth, AcquaintanceCategory, HowTheyMet, MaritalStatus, etc .... all of which will be discombobulated if I decide to reorder the elements.

So unless someone can suggest a better approach, I feel that I need to save all the enumerated info as strings, and then read the strings when loading. Then changing the ordering of enum elements will have no bearing. The two ways I've thought of doing this are:

1) Write a function that converts all the enum elements to string and then another function to convert the string names back to the enum elements, and do this for all enumerations I have being saved. That's a lot of tedious work.

2) Map all the enum elements to string, and then when loading iterate through the map until it->second==stringname, in which case the desired enum element is it->first. This second approach is less coding than the above, but I think it will be a lot slower when loading tons of info.

3) Any better ideas?
Last edited on
Topic archived. No new replies allowed.