|
@ -0,0 +1,48 @@ |
|
|
|
|
|
//
|
|
|
|
|
|
// Created by zwsd
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
#include <fstream>
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
#include <list>
|
|
|
|
|
|
#include <map>
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
#include <set>
|
|
|
|
|
|
#include <sstream>
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
#include <typeindex>
|
|
|
|
|
|
#include <typeinfo>
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
|
|
namespace iflytop { |
|
|
|
|
|
namespace core { |
|
|
|
|
|
using namespace std; |
|
|
|
|
|
template <typename T> |
|
|
|
|
|
class EnumConverter { |
|
|
|
|
|
public: |
|
|
|
|
|
map<string, T> _e2str; |
|
|
|
|
|
map<T, string> _str2e; |
|
|
|
|
|
EnumConverter(map<string, T> table) : _e2str(table) { |
|
|
|
|
|
for (auto it = table.begin(); it != table.end(); it++) { |
|
|
|
|
|
_str2e[it->second] = it->first; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
string e2str(T e) { //
|
|
|
|
|
|
auto it = _str2e.find(e); |
|
|
|
|
|
if (it != _str2e.end()) { |
|
|
|
|
|
return it->second; |
|
|
|
|
|
} |
|
|
|
|
|
return "unkown"; |
|
|
|
|
|
}; |
|
|
|
|
|
T str2e(string s) { |
|
|
|
|
|
auto it = _e2str.find(s); |
|
|
|
|
|
if (it != _e2str.end()) { |
|
|
|
|
|
return it->second; |
|
|
|
|
|
} |
|
|
|
|
|
return (T)-1; |
|
|
|
|
|
}; |
|
|
|
|
|
}; |
|
|
|
|
|
} // namespace core
|
|
|
|
|
|
} // namespace iflytop
|