F
F. GEIGER
Often I have to parse files containing lines of formats like the following:
ItemName::1::100
ItemName is a name, 1 and 100 are the min and max values of a range.
When I parse such lines I split them into substrings, where "::" is the
delimiter. Then I feed them into static methods of classes, that are
concerned with:
CItem::FromString(line); // Eats "ItemName", leaves "1::100" in line
CRange::FromString(line); // Eats "1::100"; line empty now.
While this seems okay in terms of "each class knows best by itself how to do
it", it is not so good, if the format changes somehow. The sample above is a
simplified one and usually much more classes are involved. Think of the
ripple going thru this part of the programm on a change of the format.
How is this done in a better way? When I say better, I think this has to
mean it should follow "from the many to the few" [C++ FAQ].
Many thanks in advance and kind regards
Franz GEIGER
ItemName::1::100
ItemName is a name, 1 and 100 are the min and max values of a range.
When I parse such lines I split them into substrings, where "::" is the
delimiter. Then I feed them into static methods of classes, that are
concerned with:
CItem::FromString(line); // Eats "ItemName", leaves "1::100" in line
CRange::FromString(line); // Eats "1::100"; line empty now.
While this seems okay in terms of "each class knows best by itself how to do
it", it is not so good, if the format changes somehow. The sample above is a
simplified one and usually much more classes are involved. Think of the
ripple going thru this part of the programm on a change of the format.
How is this done in a better way? When I say better, I think this has to
mean it should follow "from the many to the few" [C++ FAQ].
Many thanks in advance and kind regards
Franz GEIGER