| 92 | baseNameAndDigitCountEntry.add(digitsValue); |
| 93 | } |
| 94 | std::string Base::UniqueNameManager::makeUniqueName(std::string_view modelName, std::size_t minDigits) const |
| 95 | { |
| 96 | auto [namePrefix, nameSuffix, digitCount, digitsValue] = decomposeName(modelName); |
| 97 | std::string baseName {namePrefix}; |
| 98 | baseName += nameSuffix; |
| 99 | auto baseNameEntry = uniqueSeeds.find(baseName); |
| 100 | if (baseNameEntry == uniqueSeeds.end()) { |
| 101 | // First use of baseName, just return it with no unique digits |
| 102 | return baseName; |
| 103 | } |
| 104 | // We don't care about the digit count or value of the suggested name, |
| 105 | // we always use at least the most digits ever used before. |
| 106 | digitCount = baseNameEntry->second.size() - 1; |
| 107 | if (digitCount < minDigits) { |
| 108 | // Caller is asking for more digits than we have in any registered name. |
| 109 | // We start the longer digit string at 000...0001 even though we might have shorter strings |
| 110 | // with larger numeric values. |
| 111 | digitCount = minDigits; |
| 112 | digitsValue = UnlimitedUnsigned(1); |
| 113 | } |
| 114 | else { |
| 115 | digitsValue = baseNameEntry->second[digitCount].next(); |
| 116 | } |
| 117 | const std::string digits = digitsValue.toString(); |
| 118 | std::string digitsPadding; |
| 119 | if (digitCount > digits.size()) { |
| 120 | digitsPadding.resize(digitCount - digits.size(), '0'); |
| 121 | } |
| 122 | return std::string {namePrefix}.append(digitsPadding).append(digits).append(nameSuffix); |
| 123 | } |
| 124 | |
| 125 | void Base::UniqueNameManager::removeExactName(std::string_view name) |
| 126 | { |
no test coverage detected