On Mon, Feb 28, 2000 at 09:20:11AM +0100, Lars Gullik Bj&resh;nnes wrote:
> | Consider the code of LyXLayout::readLabelType.
> | It uses a LyXLex::lex() for converting the current token (defining the label
> | type) to a number (of type LabelTypeTags), and then it does a big switch
> | for converting the number to a different number (of type LYX_LABEL_TYPES).
> | So why not make the call to LyXLex::lex() return the desired number?
> | Namely,
> |
> | static keyword_item labelTypeTags[] = {
> | { "bibliography", LABEL_BIBLIO },
> | { "centered_top_environment", LABEL_CENTERED_TOP_ENVIRONMENT },
> | ...
> | };
> |
> | void LyXLayout::readLabelType(LyXLex & lexrc)
> | {
> | pushpophelper pph(lexrc, labelTypeTags,
> | sizeof(labelTypeTags)/sizeof(keyword_item));
> | int le = lexrc.lex();
> | if (le == LyXLex::LEX_UNDEF)
> | lexrc.printError("Unknown labeltype tag $$Token'");
> | else
> | labeltype = le;
> | }
>
> And how does the compiler tell you that you now miss some of the enums
> that should/must be handled in the switch/if chain? Because that is
> much of the point of the current code.
>
I don't understand your point.
It is true that the array labelTypeTags[] can miss some of the tags of
enum LYX_LABEL_TYPES, and you don't get a compiler warning if it happens,
but this can also happen in the old code!
In fact, in the old code you define two enums LabelTypeTags and
LYX_LABEL_TYPES which should be the same, but you don't get a compiler
warning if they are not.