You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
704 B
32 lines
704 B
#include "enummap.hpp"
|
|
|
|
#include <string.h>
|
|
using namespace std;
|
|
|
|
namespace iflytop {
|
|
const char* EnumMapValue2Str(const enummap_iterm_t* map, int val) {
|
|
for (int i = 0; !map[i].end; i++) {
|
|
if (map[i].val == val) {
|
|
return map[i].chname;
|
|
}
|
|
}
|
|
return nullptr;
|
|
}
|
|
int EnumMapStr2Value(const enummap_iterm_t* map, const char* str) {
|
|
for (int i = 0; !map[i].end; i++) {
|
|
if (strcmp(map[i].chname, str) == 0) {
|
|
return map[i].val;
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
list<string> EnumMapStrList(const enummap_iterm_t* map) {
|
|
list<string> strlist;
|
|
for (int i = 0; !map[i].end; i++) {
|
|
if (map[i].chname) strlist.push_back(map[i].chname);
|
|
}
|
|
return strlist;
|
|
}
|
|
|
|
} // namespace iflytop
|