S
Steven T. Hatton
There are probably a zillion ways to do this, but I'm wondering of there's a
C++ convention. I want to have a fixed mapping between keys and values.
It's basically the same thing as a std::map<>, except what I'm talking
about would not create a new element on a miss. This is a traditional
approach I've seen with C and other languages.
string
SectionTypes( Elf32_Word type )
{
string sRet = "UNKNOWN";
switch ( type ) {
case SHT_NULL :
sRet = "NULL";
break;
case SHT_PROGBITS :
sRet = "PROGBITS";
break;
case SHT_SYMTAB :
sRet = "SYMTAB";
break;
case SHT_STRTAB :
sRet = "STRTAB";
break;
case SHT_RELA :
sRet = "RELA";
break;
case SHT_HASH :
sRet = "HASH";
break;
case SHT_DYNAMIC :
sRet = "DYNAMIC";
break;
case SHT_NOTE :
sRet = "NOTE";
break;
case SHT_NOBITS :
sRet = "NOBITS";
break;
case SHT_REL :
sRet = "REL";
break;
case SHT_SHLIB :
sRet = "SHLIB";
break;
case SHT_DYNSYM :
sRet = "DYNSYM";
break;
}
return sRet;
}
If I were to use a switch method, I'd return from the case rather than
falling off the end. Even that seems a bit too clunky for me. std::map<>
is good for what it's designed for, but it doesn't work for fixed sets with
a default for cases where there's no key to match the sample.
I know this is trivial, but it's the kind of thing I find myself fretting
over more than seems necessary. Everytime I encounter the situation I toy
around with a solution, but I've never found the "right fit". Any
suggestions for a nice, concise, flexible way of setting up this kind of
associative mapping.
I could use a set of std:
air<key,value>, and provide a comparator, but
that seems unnecessarily complicated for the situation. Using a std::map<>
and doing a find likewise seems excessive.
C++ convention. I want to have a fixed mapping between keys and values.
It's basically the same thing as a std::map<>, except what I'm talking
about would not create a new element on a miss. This is a traditional
approach I've seen with C and other languages.
string
SectionTypes( Elf32_Word type )
{
string sRet = "UNKNOWN";
switch ( type ) {
case SHT_NULL :
sRet = "NULL";
break;
case SHT_PROGBITS :
sRet = "PROGBITS";
break;
case SHT_SYMTAB :
sRet = "SYMTAB";
break;
case SHT_STRTAB :
sRet = "STRTAB";
break;
case SHT_RELA :
sRet = "RELA";
break;
case SHT_HASH :
sRet = "HASH";
break;
case SHT_DYNAMIC :
sRet = "DYNAMIC";
break;
case SHT_NOTE :
sRet = "NOTE";
break;
case SHT_NOBITS :
sRet = "NOBITS";
break;
case SHT_REL :
sRet = "REL";
break;
case SHT_SHLIB :
sRet = "SHLIB";
break;
case SHT_DYNSYM :
sRet = "DYNSYM";
break;
}
return sRet;
}
If I were to use a switch method, I'd return from the case rather than
falling off the end. Even that seems a bit too clunky for me. std::map<>
is good for what it's designed for, but it doesn't work for fixed sets with
a default for cases where there's no key to match the sample.
I know this is trivial, but it's the kind of thing I find myself fretting
over more than seems necessary. Everytime I encounter the situation I toy
around with a solution, but I've never found the "right fit". Any
suggestions for a nice, concise, flexible way of setting up this kind of
associative mapping.
I could use a set of std:
that seems unnecessarily complicated for the situation. Using a std::map<>
and doing a find likewise seems excessive.