Converts the class name map into a fixed mapping of index to name
| 60 | { |
| 61 | // Converts the class name map into a fixed mapping of index to name |
| 62 | void SetClassNames(const std::vector<std::string> &class_names, |
| 63 | ExtractorCallbacks::ClassesMap &classes_map, |
| 64 | ProfileProperties &profile_properties) |
| 65 | { |
| 66 | // if we get a list of class names we can validate if we set invalid classes |
| 67 | // and add classes that were never reference |
| 68 | if (!class_names.empty()) |
| 69 | { |
| 70 | // add class names that were never used explicitly on a way |
| 71 | // this makes sure we can correctly validate unknown class names later |
| 72 | for (const auto &name : class_names) |
| 73 | { |
| 74 | if (!isValidClassName(name)) |
| 75 | { |
| 76 | throw util::exception("Invalid class name " + name + " only [a-Z0-9] allowed."); |
| 77 | } |
| 78 | |
| 79 | auto iter = classes_map.find(name); |
| 80 | if (iter == classes_map.end()) |
| 81 | { |
| 82 | auto index = classes_map.size(); |
| 83 | if (index > MAX_CLASS_INDEX) |
| 84 | { |
| 85 | throw util::exception("Maximum number of classes is " + |
| 86 | std::to_string(MAX_CLASS_INDEX + 1)); |
| 87 | } |
| 88 | |
| 89 | classes_map[name] = getClassData(index); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | // check if class names are only from the list supplied by the user |
| 94 | for (const auto &pair : classes_map) |
| 95 | { |
| 96 | auto iter = std::find(class_names.begin(), class_names.end(), pair.first); |
| 97 | if (iter == class_names.end()) |
| 98 | { |
| 99 | throw util::exception("Profile used unknown class name: " + pair.first); |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | for (const auto &pair : classes_map) |
| 105 | { |
| 106 | auto range = getClassIndexes(pair.second); |
| 107 | BOOST_ASSERT(range.size() == 1); |
| 108 | profile_properties.SetClassName(range.front(), pair.first); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | // Converts the class name list to a mask list |
| 113 | void SetExcludableClasses(const ExtractorCallbacks::ClassesMap &classes_map, |
no test coverage detected