I have a class Target
with a "fileType" enum
which holds all kinds of files my parser needs to know about (currently SOURCE, HEADER, RESOURCE). I'd like my Parsing function to be able to do something generic like:
if( token == some_known_fileType )
put_nextToken_in_the_list_for_that_fileType();
else
return an_error();
But there's a catch: I'd like to be able to simply extend the known fileTypes with subclasses of Target
, that extend the enum
in a correct way, see Base enum class inheritance for how I did this. I don't want to modify the above code, but only generically extend the Target half. C++0X may be required and is very welcome.
Thanks!
UPDATE: Upon trying to explain it here and posting some reduced class declarations, I realised my design is broken, and I tried to push the specialization of fileType too deep in my class structure. I wanted only one place to store a full list of all known types, but in trying to do so, I accidentally forced the design to have access to that list in two places at a time. I now realise that the list of all fileTypes should be where the keywords SOURCE, HEADER, etc. are read, and be handled *generically from thereon. I will store a full list in one place, and access that list through a "huge" enum
later on. A std::map<fileType, std::set<std::string> >
pops into my head as a logical choice here, instead of seperately named set
for each specific fileType
. Thanks for the braincandy in your responses though! Any thoughts are still welcome.