| 40 | { |
| 41 | template<typename TypeEnum, typename ElementEnum> |
| 42 | class DataConfig |
| 43 | { |
| 44 | public: |
| 45 | |
| 46 | /** define types that store the configuration */ |
| 47 | typedef std::vector<std::pair<ElementEnum, int>> ConfigType; |
| 48 | typedef struct |
| 49 | { |
| 50 | std::string _Name; |
| 51 | TypeEnum _Type; |
| 52 | ConfigType _Elements; |
| 53 | } InitType; |
| 54 | typedef std::vector<InitType> InitVect; |
| 55 | |
| 56 | /** disable the default constructor construction */ |
| 57 | DataConfig() = delete; |
| 58 | |
| 59 | /** enforce advanced initialization */ |
| 60 | explicit DataConfig(InitVect InitialConfig) |
| 61 | { |
| 62 | for (InitType &Init : InitialConfig) |
| 63 | { |
| 64 | _TypeMap.emplace(Init._Type, Init._Elements); |
| 65 | _NameTypeMap.emplace(Init._Name, Init._Type); |
| 66 | _TypeNameMap.emplace(Init._Type, Init._Name); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | /** destruction */ |
| 71 | virtual ~DataConfig() = default; |
| 72 | |
| 73 | /** query string */ |
| 74 | std::string getName(TypeEnum Type) const |
| 75 | { |
| 76 | return _TypeNameMap.at(Type); |
| 77 | } |
| 78 | |
| 79 | TypeEnum getType(std::string Name) const |
| 80 | { |
| 81 | return _NameTypeMap.at(Name); |
| 82 | } |
| 83 | |
| 84 | /** check type or string */ |
| 85 | bool checkName(std::string Name) const |
| 86 | { |
| 87 | return (_NameTypeMap.count(Name) > 0); |
| 88 | } |
| 89 | |
| 90 | bool checkType(TypeEnum Type) const |
| 91 | { |
| 92 | return (_TypeNameMap.count(Type) > 0); |
| 93 | } |
| 94 | |
| 95 | /** query config */ |
| 96 | const ConfigType &getConfig(std::string ID) const |
| 97 | { |
| 98 | return _TypeMap.at(_NameTypeMap.at(ID)); |
| 99 | } |
nothing calls this directly
no outgoing calls
no test coverage detected