Skip to content

v0.2.54..v0.2.55 changeset ToEnglishTranslateDictionary.cpp

Garret Voltz edited this page Aug 14, 2020 · 1 revision
diff --git a/hoot-core/src/main/cpp/hoot/core/language/ToEnglishTranslateDictionary.cpp b/hoot-core/src/main/cpp/hoot/core/language/ToEnglishTranslateDictionary.cpp
index e69adf3..27577bb 100644
--- a/hoot-core/src/main/cpp/hoot/core/language/ToEnglishTranslateDictionary.cpp
+++ b/hoot-core/src/main/cpp/hoot/core/language/ToEnglishTranslateDictionary.cpp
@@ -22,7 +22,7 @@
  * This will properly maintain the copyright information. DigitalGlobe
  * copyrights will be updated automatically.
  *
- * @copyright Copyright (C) 2015, 2016, 2017, 2018, 2019 DigitalGlobe (http://www.digitalglobe.com/)
+ * @copyright Copyright (C) 2015, 2016, 2017, 2018, 2019, 2020 DigitalGlobe (http://www.digitalglobe.com/)
  */
 
 #include "ToEnglishTranslateDictionary.h"
@@ -45,8 +45,6 @@ namespace pt = boost::property_tree;
 namespace hoot
 {
 
-std::shared_ptr<ToEnglishTranslateDictionary> ToEnglishTranslateDictionary::_theInstance = NULL;
-
 ToEnglishTranslateDictionary::ToEnglishTranslateDictionary() :
 _transliterationCachingEnabled(false)
 {
@@ -60,37 +58,29 @@ _transliterationCachingEnabled(false)
 
   UErrorCode error = U_ZERO_ERROR;
 
-  _titler = Transliterator::createInstance("Any-Title", UTRANS_FORWARD, error);
+  _titler.reset(Transliterator::createInstance("Any-Title", UTRANS_FORWARD, error));
   if (_titler == NULL || error != U_ZERO_ERROR)
   {
     LOG_ERROR("transliterator error code: " << error);
     throw HootException("transliterator error");
   }
 
-  _transliterator =
-    Transliterator::createInstance("Any-Latin; Latin-ASCII", UTRANS_FORWARD, error);
+  _transliterator.reset(
+    Transliterator::createInstance("Any-Latin; Latin-ASCII", UTRANS_FORWARD, error));
   if (_transliterator == NULL || error != U_ZERO_ERROR)
   {
     LOG_ERROR("transliterator error code: " << error);
     throw HootException("transliterator error");
   }
-}
-
-ToEnglishTranslateDictionary::~ToEnglishTranslateDictionary()
-{
-  delete _transliterator;
-  delete _titler;
+  //  Load the dictionary file
+  load(ConfPath::search("dictionary.json"));
 }
 
 ToEnglishTranslateDictionary& ToEnglishTranslateDictionary::getInstance()
 {
-  if (_theInstance == NULL)
-  {
-    QString dictionary = ConfPath::search("dictionary.json");
-    _theInstance.reset(new ToEnglishTranslateDictionary());
-    _theInstance->load(dictionary);
-  }
-  return *_theInstance;
+  //  Local static singleton instance
+  static ToEnglishTranslateDictionary instance;
+  return instance;
 }
 
 bool ToEnglishTranslateDictionary::getFromTransliterationCache(const QString& originalText,
Clone this wiki locally