diff --git a/inflection/src/inflection/dialog/CommonConceptFactoryImpl.cpp b/inflection/src/inflection/dialog/CommonConceptFactoryImpl.cpp index ef37c49e..d1d4b5a6 100644 --- a/inflection/src/inflection/dialog/CommonConceptFactoryImpl.cpp +++ b/inflection/src/inflection/dialog/CommonConceptFactoryImpl.cpp @@ -210,10 +210,9 @@ SpeakableString* CommonConceptFactoryImpl::quantify(const NumberConcept& number, { ::std::unique_ptr formattedNumber; if (semanticFeatureForNumberConcept != nullptr) { - auto speakableFeatureValue = npc(semanticConcept)->getFeatureValue(*npc(semanticFeatureForNumberConcept)); - if (speakableFeatureValue != nullptr) { - auto rulename = semanticFeatureToNumberConceptName.find(npc(speakableFeatureValue)->getPrint()); - delete speakableFeatureValue; + ::std::unique_ptr speakableFeatureValue(npc(semanticConcept)->getFeatureValue(*npc(semanticFeatureForNumberConcept))); + if (speakableFeatureValue.get() != nullptr) { + auto rulename = semanticFeatureToNumberConceptName.find(speakableFeatureValue->getPrint()); if (rulename != semanticFeatureToNumberConceptName.end()) { formattedNumber.reset(new SpeakableString(number.asSpokenWords(rulename->second))); } diff --git a/inflection/src/inflection/dialog/DefinitenessDisplayFunction.cpp b/inflection/src/inflection/dialog/DefinitenessDisplayFunction.cpp index cb934c06..469514a2 100644 --- a/inflection/src/inflection/dialog/DefinitenessDisplayFunction.cpp +++ b/inflection/src/inflection/dialog/DefinitenessDisplayFunction.cpp @@ -79,13 +79,13 @@ int32_t DefinitenessDisplayFunction::getArticlePrefixLength(DisplayValue* origin DisplayValue* DefinitenessDisplayFunction::replaceDisplayValue(DisplayValue* originalDisplayValue, const SpeakableString& string) const { - auto displayValueConstraints(npc(originalDisplayValue)->getConstraintMap()); + ::std::unique_ptr value(npc(originalDisplayValue)); + auto displayValueConstraints(value->getConstraintMap()); if (!string.speakEqualsPrint()) { displayValueConstraints[*npc(speakFeature)] = string.getSpeak(); } - auto newValue = new DisplayValue(string.getPrint(), displayValueConstraints); - delete originalDisplayValue; - return newValue; + value.reset(new DisplayValue(string.getPrint(), displayValueConstraints)); + return value.release(); } DisplayValue* diff --git a/inflection/src/inflection/dialog/SemanticConceptList.cpp b/inflection/src/inflection/dialog/SemanticConceptList.cpp index b14271af..b56c0784 100644 --- a/inflection/src/inflection/dialog/SemanticConceptList.cpp +++ b/inflection/src/inflection/dialog/SemanticConceptList.cpp @@ -126,12 +126,11 @@ std::u16string SemanticConceptList::toString() const if (previousConcept != nullptr) { displayValue += comma; } - auto conceptResult = npc(conceptObj)->toSpeakableString(); - if (conceptResult != nullptr) { - displayValue += *npc(conceptResult); + ::std::unique_ptr<::inflection::dialog::SpeakableString> conceptResult(npc(conceptObj)->toSpeakableString()); + if (conceptResult.get() != nullptr) { + displayValue += *conceptResult; } previousConcept = conceptObj; - delete conceptResult; } return u"[" + displayValue.getPrint() + u"]"; } diff --git a/inflection/src/inflection/dictionary/DictionaryMetaData_MMappedDictionary.cpp b/inflection/src/inflection/dictionary/DictionaryMetaData_MMappedDictionary.cpp index cd17da25..e7da3675 100644 --- a/inflection/src/inflection/dictionary/DictionaryMetaData_MMappedDictionary.cpp +++ b/inflection/src/inflection/dictionary/DictionaryMetaData_MMappedDictionary.cpp @@ -45,8 +45,6 @@ DictionaryMetaData_MMappedDictionary::DictionaryMetaData_MMappedDictionary(::inf DictionaryMetaData_MMappedDictionary::~DictionaryMetaData_MMappedDictionary() { - delete inflector; - delete memoryMappedRegion; } const ::inflection::util::ULocale& DictionaryMetaData_MMappedDictionary::getLocale() const @@ -189,11 +187,11 @@ bool DictionaryMetaData_MMappedDictionary::getWordPropertyValues(::std::vector<: return true; } - const bool useInflectionTrieForKeys = (inflector != nullptr) && (propertyNameIdentifier == inflectionKeyIdentifier); + const bool useInflectionTrieForKeys = (inflector.get() != nullptr) && (propertyNameIdentifier == inflectionKeyIdentifier); for (const auto propertyIdentifier: propertyIdentifiers) { npc(result)->emplace_back(useInflectionTrieForKeys - ? npc(inflector)->mmappedDictionary.identifierToInflectionPatternTrie.getKey(propertyIdentifier) + ? inflector->mmappedDictionary.identifierToInflectionPatternTrie.getKey(propertyIdentifier) : propertyValuesStringContainer.getString(propertyIdentifier)); } diff --git a/inflection/src/inflection/dictionary/DictionaryMetaData_MMappedDictionary.hpp b/inflection/src/inflection/dictionary/DictionaryMetaData_MMappedDictionary.hpp index e9b88906..78f531d4 100644 --- a/inflection/src/inflection/dictionary/DictionaryMetaData_MMappedDictionary.hpp +++ b/inflection/src/inflection/dictionary/DictionaryMetaData_MMappedDictionary.hpp @@ -70,8 +70,8 @@ class INFLECTION_INTERNAL_API inflection::dictionary::DictionaryMetaData_MMapped ::inflection::dictionary::metadata::StringArrayContainer propertyNameToKeyId { }; ::inflection::dictionary::metadata::StringContainer propertyValuesStringContainer { }; ::inflection::dictionary::metadata::CompressedArray propertyValueMaps {::std::vector()}; - ::inflection::dictionary::Inflector* inflector { }; - ::inflection::util::MemoryMappedFile* memoryMappedRegion { }; + ::std::unique_ptr<::inflection::dictionary::Inflector> inflector { }; + ::std::unique_ptr<::inflection::util::MemoryMappedFile> memoryMappedRegion { }; int32_t inflectionKeyIdentifier { -1 }; int32_t bitsPropertyValueMapKeyMask { }; int32_t bitsPropertyValueMapKeySize { }; diff --git a/inflection/src/inflection/dictionary/Inflector.cpp b/inflection/src/inflection/dictionary/Inflector.cpp index 72f74a73..806c2111 100644 --- a/inflection/src/inflection/dictionary/Inflector.cpp +++ b/inflection/src/inflection/dictionary/Inflector.cpp @@ -13,7 +13,7 @@ namespace inflection::dictionary { const Inflector& Inflector::getInflector(const ::inflection::util::ULocale &locale) { - const Inflector* result = npc(DictionaryMetaData::createDictionary(locale))->dictionary->inflector; + const Inflector* result = npc(DictionaryMetaData::createDictionary(locale))->dictionary->inflector.get(); if (result == nullptr) { throw ::inflection::exception::NullPointerException(inflection::util::StringViewUtils::to_u16string("Inflector not found for " + locale.getName())); } diff --git a/inflection/src/inflection/dictionary/Inflector.hpp b/inflection/src/inflection/dictionary/Inflector.hpp index 44a57142..1e202ec0 100644 --- a/inflection/src/inflection/dictionary/Inflector.hpp +++ b/inflection/src/inflection/dictionary/Inflector.hpp @@ -33,6 +33,7 @@ class inflection::dictionary::Inflector private: explicit Inflector(inflection::util::MemoryMappedFile& memoryMappedFile, const ::std::u16string& sourcePath, const ::inflection::dictionary::DictionaryMetaData_MMappedDictionary &dictionary); +public: ~Inflector() override; private: diff --git a/inflection/src/inflection/lang/StringFilterUtil.cpp b/inflection/src/inflection/lang/StringFilterUtil.cpp index 68bdd24e..dd095729 100644 --- a/inflection/src/inflection/lang/StringFilterUtil.cpp +++ b/inflection/src/inflection/lang/StringFilterUtil.cpp @@ -117,18 +117,18 @@ static ::std::map* S return setSingletons_; } -const icu4cxx::UnicodeSet* StringFilterUtil::getSetSingleton(::icu4cxx::UnicodeSet* set) +const icu4cxx::UnicodeSet* StringFilterUtil::getSetSingleton(::icu4cxx::UnicodeSet* input) { // TODO: this code probably doesn't work that well anymore. We should check the caching again. auto setSingletons = SET_SINGLETONS(); const icu4cxx::UnicodeSet* singleton; - auto singletonCache = npc(setSingletons)->find(set); + ::std::unique_ptr<::icu4cxx::UnicodeSet> set(input); + auto singletonCache = npc(setSingletons)->find(set.get()); if (singletonCache == npc(setSingletons)->end()) { - singleton = ::inflection::util::UnicodeSetUtils::freeze(set); + singleton = ::inflection::util::UnicodeSetUtils::freeze(set.release()); npc(setSingletons)->emplace(singleton, singleton); } else { - delete set; singleton = singletonCache->second; } return singleton;