lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi] Nearly duplicative rate-table enums


From: Greg Chicares
Subject: [lmi] Nearly duplicative rate-table enums
Date: Wed, 7 Feb 2018 17:11:32 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2

Vadim--'rate_table.cpp' has these two enums:

// This enum defines the indices of all the known fields in soa_fields array,
// its elements are consecutive.
enum enum_soa_field
    {e_field_table_name
    ,e_field_table_number
...
    ,e_field_hash_value
    };

// This enum defines the field record types used in the binary SOA format and
// exists mostly to allow writing a switch on the record type in a readable way.
enum
    {e_record_table_name          =  1
    ,e_record_table_number        =  2
...
    ,e_record_hash_value          = 18
    ,e_record_end_table           = 9999
    };

...which are almost equivalent, except:
 - one has 'field' in its enumerators; the other has 'record'
 - one has a name; the other is anonymous
 - one's enumerators are defaulted; the other has explicit values
 - only one includes an end-of-table enumerator

Why do it that way, instead of combining those into a single enum
with the union of all the useful features of both?

The last two 'switch' statements are the only ones that use these
enums. The switch condition is of enumerative type in the last
    switch(field)
but not in the second-to-last
    switch(record_type)
and I wonder whether that "switch(record_type)" would be better as
    switch(static_cast<SOMETHING>(record_type))
where we'd have to give a name to the anonymous enum. But if we do
that, why not just merge the enums?



reply via email to

[Prev in Thread] Current Thread [Next in Thread]