Searches for the type associated with the given string and returns it. A string containing the name of the type. @returns The type that resolves to the given name.
| 139 | /// </param> |
| 140 | /// @returns The type that resolves to the given name. |
| 141 | static T getType(std::string name) |
| 142 | { |
| 143 | // Mapping of strings to types |
| 144 | static const typeMapT typeMap( typeMapInit() ); |
| 145 | |
| 146 | // erase-remove idiom, eliminates spaces and underscores from the string to search |
| 147 | name.erase( std::remove_if(name.begin(), name.end(), [](char const &c){ return isspace(c) || c == '_'; }), name.end() ); |
| 148 | |
| 149 | // Make lowercase |
| 150 | std::transform(name.begin(), name.end(), name.begin(), |
| 151 | [](std::string::const_reference c) { return static_cast<char>(std::tolower(c)); } |
| 152 | ); |
| 153 | |
| 154 | // Find the type |
| 155 | auto it = typeMap.find(name); |
| 156 | if ( it != typeMap.end() ) |
| 157 | return it->second; |
| 158 | |
| 159 | // Return unknown if it wasn't found |
| 160 | return T(UnknownId); |
| 161 | }; |
| 162 | }; |
| 163 | |
| 164 | } |
no test coverage detected