Hello,
Not sure if I understood well.
You have on one hand an enumerated type plus a set of this type. That is:
Code:
TBlockType = (mineralsWalkable, mineralsNonBlocking, mineralsRare, etc);
stMinerals = set of TBlockType;
Even if we were to be more accurate with correct nomenclature guide would be this:
Code:
TBlockType = (btWalkable, btNonBlocking, etc);
TMinerals = set of TBlockType;
And you're looking for a way to "automate" the saved and read from a file of this set. And also, you do not look limited to a fixed amount of items, but you can add more types of minerals and not have to alter the file.
If I am right, then I think the technique you're using is not entirely correct.
I think that if you are not fully aware of the amount, and cardinality of items that will TBlockType and / or if you expect this to be a "listed open" then not it is the right kind.
I recommend you to think more in design a list to it so that you can add as many types of minerals as you want.
Then:
1. Design an abstract class called TBlockType
2. Desing as many classes as types descend from this need.
3. Design a class TMineralsList that is responsible for maintaining the list (set) of minerals.
What remains to be implemented, and for reading and saving the file based on the listing. I can suggest you to do based on the Factory pattern.
To keep the set in the file, you could do something like XML:
<set>
NameOfClass1;
NameOfClass2;
...
NameOfClassN;
</set>
Then to read the file just read the name of the classes and proceed with a "materialization" of this and create an instance.
The other way around (save), we scan the list of objects (minerals), determine the name of the class and stored on disk.
Regards,
P.S: Sorry for my bad English.
Bookmarks