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.

31 lines
704 B

1 year ago
  1. #include "enummap.hpp"
  2. #include <string.h>
  3. using namespace std;
  4. namespace iflytop {
  5. const char* EnumMapValue2Str(const enummap_iterm_t* map, int val) {
  6. for (int i = 0; !map[i].end; i++) {
  7. if (map[i].val == val) {
  8. return map[i].chname;
  9. }
  10. }
  11. return nullptr;
  12. }
  13. int EnumMapStr2Value(const enummap_iterm_t* map, const char* str) {
  14. for (int i = 0; !map[i].end; i++) {
  15. if (strcmp(map[i].chname, str) == 0) {
  16. return map[i].val;
  17. }
  18. }
  19. return -1;
  20. }
  21. list<string> EnumMapStrList(const enummap_iterm_t* map) {
  22. list<string> strlist;
  23. for (int i = 0; !map[i].end; i++) {
  24. if (map[i].chname) strlist.push_back(map[i].chname);
  25. }
  26. return strlist;
  27. }
  28. } // namespace iflytop