Use boost::scoped_ptr to maintain Config instances.
authorPeng Huang <shawn.p.huang@gmail.com>
Mon, 24 May 2010 06:21:31 +0000 (14:21 +0800)
committerPeng Huang <shawn.p.huang@gmail.com>
Mon, 24 May 2010 06:21:31 +0000 (14:21 +0800)
src/Config.cc
src/Config.h

index 39dfbc6..9933421 100644 (file)
@@ -43,8 +43,8 @@ namespace PY {
 #define STRING_SPECIAL_PHRASES              ("SpecialPhrases")
 #define STRING_BOPOMOFO_KEYBOARD_MAPPING    ("BopomofoKeyboardMapping")
 
-PinyinConfig * PinyinConfig::m_instance = NULL;
-BopomofoConfig * BopomofoConfig::m_instance = NULL;
+boost::scoped_ptr<PinyinConfig> PinyinConfig::m_instance;
+boost::scoped_ptr<BopomofoConfig> BopomofoConfig::m_instance;
 
 Config::Config (Bus & bus, const std::string & name)
     : Object (ibus_bus_get_config (bus)),
@@ -320,7 +320,7 @@ void
 PinyinConfig::init (Bus & bus)
 {
     if (PinyinConfig::m_instance == NULL) {
-        PinyinConfig::m_instance = new PinyinConfig (bus);
+        PinyinConfig::m_instance.reset (new PinyinConfig (bus));
     }
 }
 
@@ -328,7 +328,7 @@ void
 BopomofoConfig::init (Bus & bus)
 {
     if (BopomofoConfig::m_instance == NULL) {
-        BopomofoConfig::m_instance = new BopomofoConfig (bus);
+        BopomofoConfig::m_instance.reset (new BopomofoConfig (bus));
     }
 }
 
index 65a1650..00cdb0c 100644 (file)
@@ -22,6 +22,7 @@
 #define __PY_CONFIG_H_
 
 #include <string>
+#include <boost/scoped_ptr.hpp>
 #include <glib.h>
 #include <glib-object.h>
 #include <ibus.h>
@@ -101,7 +102,7 @@ protected:
     PinyinConfig (Bus & bus, const std::string & name = "Pinyin") : Config (bus, name) { }
 
 private:
-    static PinyinConfig * m_instance;
+    static boost::scoped_ptr<PinyinConfig> m_instance;
 };
 
 /* Bopomof Config */
@@ -114,7 +115,7 @@ protected:
     BopomofoConfig (Bus & bus) : PinyinConfig (bus, "Bopomofo") { }
 
 private:
-    static BopomofoConfig * m_instance;
+    static boost::scoped_ptr<BopomofoConfig> m_instance;
 };
 
 };