void EntityDefinitionManager::updateGroups() { clearGroups(); using GroupMap = std::map<String, EntityDefinitionList>; GroupMap groupMap; for (size_t i = 0; i < m_definitions.size(); ++i) { EntityDefinition* definition = m_definitions[i]; const String groupName = definition->groupName(); groupMap[groupName].push_back(definition); } for (const auto& entry : groupMap) { const String& groupName = entry.first; const EntityDefinitionList& definitions = entry.second; m_groups.push_back(EntityDefinitionGroup(groupName, definitions)); } }
EntityDefinitionManager::EntityDefinitionGroups EntityDefinitionManager::groups(EntityDefinition::Type type, SortOrder order) { EntityDefinitionGroups groups; EntityDefinitionList list = definitions(type, order); EntityDefinitionList ungrouped; EntityDefinitionList::const_iterator it, end; for (it = list.begin(), end = list.end(); it != end; ++it) { EntityDefinition* definition = *it; const String groupName = definition->groupName(); if (groupName.empty()) ungrouped.push_back(definition); else groups[groupName].push_back(definition); } for (it = ungrouped.begin(), end = ungrouped.end(); it != end; ++it) { EntityDefinition* definition = *it; const String shortName = Utility::capitalize(definition->shortName()); EntityDefinitionGroups::iterator groupIt = groups.find(shortName); if (groupIt == groups.end()) groups["Misc"].push_back(definition); else groupIt->second.push_back(definition); } EntityDefinitionGroups::iterator groupIt, groupEnd; for (groupIt = groups.begin(), groupEnd = groups.end(); groupIt != groupEnd; ++groupIt) { EntityDefinitionList& definitions = groupIt->second; if (order == Usage) std::sort(definitions.begin(), definitions.end(), CompareEntityDefinitionsByUsage()); else std::sort(definitions.begin(), definitions.end(), CompareEntityDefinitionsByName(true)); } return groups; }