Add option --disable-boost to support build without boost
authorPeng Huang <shawn.p.huang@gmail.com>
Mon, 27 Sep 2010 06:09:07 +0000 (14:09 +0800)
committerPeng Huang <shawn.p.huang@gmail.com>
Mon, 27 Sep 2010 06:09:07 +0000 (14:09 +0800)
When build without boost, ibus-pinyin will use smart pointer
from c++0x and use the signal templates embedded instead of
boost::signals2.

BUG=chromium-os:5055
TEST=manual

Review URL: http://codereview.appspot.com/2205044

17 files changed:
configure.ac
src/Makefile.am
src/PYBopomofoEngine.cc
src/PYConfig.cc
src/PYConfig.h
src/PYDatabase.cc
src/PYDatabase.h
src/PYEditor.h
src/PYEngine.cc
src/PYExtEditor.cc
src/PYPhraseEditor.h
src/PYPinyinEngine.cc
src/PYPunctEditor.cc
src/PYPunctEditor.h
src/PYSignal.h
src/PYSpecialPhraseTable.h
src/PYUtil.h

index 3140953..ccb0ef4 100644 (file)
@@ -88,24 +88,6 @@ AC_CHECK_FUNCS([uuid_create], [], [
 
 AM_CONDITIONAL(HAVE_LIBUUID, test x"$HAVE_LIBUUID" = x"yes")
 
-# check boost
-BOOST_REQUIRE([1.39])
-BOOST_FIND_HEADER([boost/signals2.hpp])
-# BOOST_FIND_HEADER([boost/signals2.hpp], [
-#     HAVE_BOOST_SIGNALS2=no
-#     BOOST_SIGNALS([s])
-# ], [
-#     AC_DEFINE(HAVE_BOOST_SIGNALS2_HPP, 1, [Define if found boost.signals2])
-#     HAVE_BOOST_SGINALS2=yes
-# ])
-# 
-# AM_CONDITIONAL(HAVE_BOOST_SIGNALS2, test x"$HAVE_BOOST_SIGNALS2" = x"yes")
-# 
-# check sigc
-# PKG_CHECK_MODULES(SIGC, [
-#     sigc++-2.0
-# ])
-
 # check env
 AC_PATH_PROG(ENV, env)
 AC_SUBST(ENV)
@@ -113,6 +95,21 @@ AC_SUBST(ENV)
 # check python
 AM_PATH_PYTHON([2.5])
 
+# --disble-boost
+AC_ARG_ENABLE(boost,
+    AC_HELP_STRING([--disable-boost],
+        [Do not use boost and use stdc++0x to replace boost.]),
+        [enable_boost=$enableval],
+        [enable_boost=yes]
+)
+if test x"$enable_boost" = x"yes"; then
+    # check boost
+    BOOST_REQUIRE([1.39])
+    BOOST_FIND_HEADER([boost/bind.hpp])
+    BOOST_FIND_HEADER([boost/signals2.hpp])
+fi
+AM_CONDITIONAL(HAVE_BOOST, test x"$enable_boost" = x"yes")
+
 # --enable-opencc
 AC_ARG_ENABLE(opencc,
     AC_HELP_STRING([--enable-opencc],
@@ -203,6 +200,7 @@ AC_MSG_RESULT([
 Build options:
     Version                     $VERSION
     Install prefix              $prefix
+    Use boost                   $enable_boost
     Use opencc                  $enable_opencc
     Build database android      $enable_db_android
     Build database open-phrase  $enable_db_open_phrase
index c18aa07..b215c78 100644 (file)
@@ -117,16 +117,27 @@ ibus_engine_pinyin_SOURCES = \
        $(ibus_engine_pinyin_built_c_sources) \
        $(ibus_engine_pinyin_built_h_sources) \
        $(NULL)
+
+
 ibus_engine_pinyin_CXXFLAGS = \
        @IBUS_CFLAGS@ \
        @SQLITE_CFLAGS@ \
-       @BOOST_CPPFLAGS@ \
        @OPENCC_CFLAGS@ \
        -DGETTEXT_PACKAGE=\"@GETTEXT_PACKAGE@\" \
        -DPKGDATADIR=\"$(pkgdatadir)\" \
        -DLIBEXECDIR=\"$(libexecdir)\" \
        $(NULL)
 
+if HAVE_BOOST
+ibus_engine_pinyin_CXXFLAGS += \
+       @BOOST_CPPFLAGS@ \
+       $(NULL)
+else
+ibus_engine_pinyin_CXXFLAGS += \
+       -std=c++0x \
+       $(NULL)
+endif
+
 ibus_engine_pinyin_LDADD = \
        @IBUS_LIBS@ \
        @SQLITE_LIBS@ \
@@ -154,17 +165,6 @@ if IBUS_BUILD_LUA_EXTENSION
        $(NULL)
 endif
 
-
-# if HAVE_BOOST_SIGNALS2
-# # do nothing
-# else
-# ibus_engine_pinyin_CXXFLAGS += $(LIBUUID_CFLAGS)
-# ibus_engine_pinyin_LDADD += \
-#      $(BOOST_SIGNALS_LDFLAGS) \
-#      $(BOOST_SIGNALS_LIBS) \
-#      $(NULL)
-# endif
-
 BUILT_SOURCES = \
        $(ibus_engine_built_c_sources) \
        $(ibus_engine_built_h_sources) \
index 2e7411e..a46f229 100644 (file)
@@ -53,7 +53,7 @@ BopomofoEngine::BopomofoEngine (IBusEngine *engine)
     m_editors[MODE_EXTENSION].reset (new Editor (m_props, BopomofoConfig::instance ()));
 #endif
 
-    m_props.signalUpdateProperty ().connect (bind (&BopomofoEngine::updateProperty, this, _1));
+    m_props.signalUpdateProperty ().connect (std::bind (&BopomofoEngine::updateProperty, this, _1));
 
     for (i = MODE_INIT; i < MODE_LAST; i++) {
         connectEditorSignals (m_editors[i]);
@@ -220,30 +220,30 @@ void
 BopomofoEngine::connectEditorSignals (EditorPtr editor)
 {
     editor->signalCommitText ().connect (
-        bind (&BopomofoEngine::commitText, this, _1));
+        std::bind (&BopomofoEngine::commitText, this, _1));
 
     editor->signalUpdatePreeditText ().connect (
-        bind (&BopomofoEngine::updatePreeditText, this, _1, _2, _3));
+        std::bind (&BopomofoEngine::updatePreeditText, this, _1, _2, _3));
     editor->signalShowPreeditText ().connect (
-        bind (&BopomofoEngine::showPreeditText, this));
+        std::bind (&BopomofoEngine::showPreeditText, this));
     editor->signalHidePreeditText ().connect (
-        bind (&BopomofoEngine::hidePreeditText, this));
+        std::bind (&BopomofoEngine::hidePreeditText, this));
 
     editor->signalUpdateAuxiliaryText ().connect (
-        bind (&BopomofoEngine::updateAuxiliaryText, this, _1, _2));
+        std::bind (&BopomofoEngine::updateAuxiliaryText, this, _1, _2));
     editor->signalShowAuxiliaryText ().connect (
-        bind (&BopomofoEngine::showAuxiliaryText, this));
+        std::bind (&BopomofoEngine::showAuxiliaryText, this));
     editor->signalHideAuxiliaryText ().connect (
-        bind (&BopomofoEngine::hideAuxiliaryText, this));
+        std::bind (&BopomofoEngine::hideAuxiliaryText, this));
 
     editor->signalUpdateLookupTable ().connect (
-        bind (&BopomofoEngine::updateLookupTable, this, _1, _2));
+        std::bind (&BopomofoEngine::updateLookupTable, this, _1, _2));
     editor->signalUpdateLookupTableFast ().connect (
-        bind (&BopomofoEngine::updateLookupTableFast, this, _1, _2));
+        std::bind (&BopomofoEngine::updateLookupTableFast, this, _1, _2));
     editor->signalShowLookupTable ().connect (
-        bind (&BopomofoEngine::showLookupTable, this));
+        std::bind (&BopomofoEngine::showLookupTable, this));
     editor->signalHideLookupTable ().connect (
-        bind (&BopomofoEngine::hideLookupTable, this));
+        std::bind (&BopomofoEngine::hideLookupTable, this));
 }
 
 };
index 09bb44f..77d619d 100644 (file)
@@ -48,8 +48,8 @@ const gchar * const CONFIG_GUIDE_KEY                 = "GuideKey";
 const gchar * const CONFIG_AUXILIARY_SELECT_KEY_F    = "AuxiliarySelectKey_F";
 const gchar * const CONFIG_AUXILIARY_SELECT_KEY_KP   = "AuxiliarySelectKey_KP";
 
-boost::scoped_ptr<PinyinConfig> PinyinConfig::m_instance;
-boost::scoped_ptr<BopomofoConfig> BopomofoConfig::m_instance;
+std::unique_ptr<PinyinConfig> PinyinConfig::m_instance;
+std::unique_ptr<BopomofoConfig> BopomofoConfig::m_instance;
 
 Config::Config (Bus & bus, const std::string & name)
     : Object (ibus_bus_get_config (bus)),
index 9bbb503..6db9c83 100644 (file)
@@ -22,8 +22,8 @@
 #define __PY_CONFIG_H_
 
 #include <string>
-#include <boost/scoped_ptr.hpp>
 #include <ibus.h>
+#include "PYUtil.h"
 #include "PYObject.h"
 
 namespace PY {
@@ -118,7 +118,7 @@ protected:
                                    const GValue  *value);
 
 private:
-    static boost::scoped_ptr<PinyinConfig> m_instance;
+    static std::unique_ptr<PinyinConfig> m_instance;
 };
 
 /* Bopomof Config */
@@ -136,7 +136,7 @@ protected:
                                    const GValue  *value);
 
 private:
-    static boost::scoped_ptr<BopomofoConfig> m_instance;
+    static std::unique_ptr<BopomofoConfig> m_instance;
 };
 
 };
index 1fd3b86..f15e4c1 100644 (file)
@@ -35,7 +35,7 @@ namespace PY {
 
 #define DB_PREFETCH_LEN     (6)
 
-boost::scoped_ptr<Database> Database::m_instance;
+std::unique_ptr<Database> Database::m_instance;
 
 class Conditions : public std::vector<std::string> {
 public:
index ab90fcf..9d3ac8f 100644 (file)
@@ -21,8 +21,7 @@
 #ifndef __PY_DATABASE_H_
 #define __PY_DATABASE_H_
 
-#include <boost/shared_ptr.hpp>
-#include <boost/scoped_ptr.hpp>
+#include "PYUtil.h"
 #include "PYString.h"
 #include "PYTypes.h"
 #include "PYPhraseArray.h"
@@ -35,7 +34,7 @@ class PinyinArray;
 struct Phrase;
 
 class SQLStmt;
-typedef boost::shared_ptr<SQLStmt> SQLStmtPtr;
+typedef std::shared_ptr<SQLStmt> SQLStmtPtr;
 
 class Database;
 
@@ -92,7 +91,7 @@ private:
     String m_buffer;     /* temp buffer */
 
 private:
-    static boost::scoped_ptr<Database> m_instance;
+    static std::unique_ptr<Database> m_instance;
 };
 
 
index e520d51..cee29fa 100644 (file)
@@ -22,7 +22,6 @@
 #define __PY_EDITOR_H_
 
 #include <glib.h>
-#include <boost/shared_ptr.hpp>
 #include "PYSignal.h"
 #include "PYString.h"
 #include "PYUtil.h"
@@ -35,7 +34,7 @@ class PinyinProperties;
 class Config;
 
 class Editor;
-typedef boost::shared_ptr<Editor> EditorPtr;
+typedef std::shared_ptr<Editor> EditorPtr;
 
 class Editor {
 public:
index 1797e24..7987146 100644 (file)
@@ -19,6 +19,7 @@
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
+#include <cstring>
 #include "PYEngine.h"
 #include "PYPinyinEngine.h"
 #include "PYBopomofoEngine.h"
index d81d9b8..03a903a 100644 (file)
@@ -18,7 +18,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-
+#include <cstring>
 #include <string>
 
 extern "C" {
index 87758c0..2cf0513 100644 (file)
@@ -21,7 +21,7 @@
 #ifndef __PY_PHRASE_EDITOR_H_
 #define __PY_PHRASE_EDITOR_H_
 
-#include <boost/shared_ptr.hpp>
+#include "PYUtil.h"
 #include "PYString.h"
 #include "PYPhraseArray.h"
 #include "PYPinyinArray.h"
@@ -125,7 +125,7 @@ private:
     PinyinArray m_pinyin;
     guint m_cursor;
     PinyinProperties & m_props;
-    boost::shared_ptr<Query> m_query;
+    std::shared_ptr<Query> m_query;
     Config    & m_config;
 };
 
index 1625bc5..9f7c167 100644 (file)
@@ -55,7 +55,7 @@ PinyinEngine::PinyinEngine (IBusEngine *engine)
     m_editors[MODE_EXTENSION].reset (new Editor (m_props, PinyinConfig::instance ()));
 #endif
 
-    m_props.signalUpdateProperty ().connect (bind (&PinyinEngine::updateProperty, this, _1));
+    m_props.signalUpdateProperty ().connect (std::bind (&PinyinEngine::updateProperty, this, _1));
 
     for (i = MODE_INIT; i < MODE_LAST; i++) {
         connectEditorSignals (m_editors[i]);
@@ -264,30 +264,30 @@ void
 PinyinEngine::connectEditorSignals (EditorPtr editor)
 {
     editor->signalCommitText ().connect (
-        bind (&PinyinEngine::commitText, this, _1));
+        std::bind (&PinyinEngine::commitText, this, _1));
 
     editor->signalUpdatePreeditText ().connect (
-        bind (&PinyinEngine::updatePreeditText, this, _1, _2, _3));
+        std::bind (&PinyinEngine::updatePreeditText, this, _1, _2, _3));
     editor->signalShowPreeditText ().connect (
-        bind (&PinyinEngine::showPreeditText, this));
+        std::bind (&PinyinEngine::showPreeditText, this));
     editor->signalHidePreeditText ().connect (
-        bind (&PinyinEngine::hidePreeditText, this));
+        std::bind (&PinyinEngine::hidePreeditText, this));
 
     editor->signalUpdateAuxiliaryText ().connect (
-        bind (&PinyinEngine::updateAuxiliaryText, this, _1, _2));
+        std::bind (&PinyinEngine::updateAuxiliaryText, this, _1, _2));
     editor->signalShowAuxiliaryText ().connect (
-        bind (&PinyinEngine::showAuxiliaryText, this));
+        std::bind (&PinyinEngine::showAuxiliaryText, this));
     editor->signalHideAuxiliaryText ().connect (
-        bind (&PinyinEngine::hideAuxiliaryText, this));
+        std::bind (&PinyinEngine::hideAuxiliaryText, this));
 
     editor->signalUpdateLookupTable ().connect (
-        bind (&PinyinEngine::updateLookupTable, this, _1, _2));
+        std::bind (&PinyinEngine::updateLookupTable, this, _1, _2));
     editor->signalUpdateLookupTableFast ().connect (
-        bind (&PinyinEngine::updateLookupTableFast, this, _1, _2));
+        std::bind (&PinyinEngine::updateLookupTableFast, this, _1, _2));
     editor->signalShowLookupTable ().connect (
-        bind (&PinyinEngine::showLookupTable, this));
+        std::bind (&PinyinEngine::showLookupTable, this));
     editor->signalHideLookupTable ().connect (
-        bind (&PinyinEngine::hideLookupTable, this));
+        std::bind (&PinyinEngine::hideLookupTable, this));
 }
 
 };
index 091d639..302c6e4 100644 (file)
@@ -19,6 +19,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
+#include <algorithm>
 #include "PYConfig.h"
 #include "PYPunctEditor.h"
 
index 0035813..98c81cd 100644 (file)
@@ -22,6 +22,8 @@
 #ifndef __PY_PUNCT_EDITOR_
 #define __PY_PUNCT_EDITOR_
 
+#include <vector>
+
 #include "PYLookupTable.h"
 #include "PYEditor.h"
 
index 6721493..574af98 100644 (file)
 #  include <config.h>
 #endif
 
-#ifdef HAVE_BOOST_SIGNALS2_HPP
-#  include <boost/signals2.hpp>
-#elif HAVE_BOOST_SIGNALS_HPP
-#  include <boost/signals.hpp>
-#else
-#  error "Can not find boost.signals2 or boost.signal"
-#endif
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
 
-#include <boost/bind.hpp>
+#  include <functional>
 
 namespace PY {
 
-using boost::bind;
+using namespace std::placeholders;
 
-#if HAVE_BOOST_SIGNALS2_HPP
-namespace bs2 = boost::signals2;
-template <typename Signature>
-struct signal : public bs2::signal_type <Signature, bs2::keywords::mutex_type<bs2::dummy_mutex> >::type { };
-#elif HAVE_BOOST_SIGNALS_HPP
-using boost::signal;
-#endif
+// implement signal templates
+template<typename R  = void,
+         typename T1 = void,
+         typename T2 = void,
+         typename T3 = void>
+struct signal
+{
+};
 
+template<typename R, typename T1, typename T2, typename T3>
+struct signal< R(), T1, T2, T3>
+{
+    typedef std::function<R()> func_type;
+    void connect (func_type f) { m_func = f; }
+    R operator ()() const { m_func (); }
+private:
+    func_type m_func;
 };
 
-#endif
+template<typename R, typename T1, typename T2, typename T3>
+struct signal< R(T1), T2, T3>
+{
+    typedef std::function<R(T1)> func_type;
+    void connect (func_type f) { m_func = f; }
+    R operator ()(T1 a1) const { return m_func (a1); }
+private:
+    func_type m_func;
+};
+
+template<typename R, typename T1, typename T2, typename T3>
+struct signal< R(T1, T2), T3>
+{
+    typedef std::function<R(T1, T2)> func_type;
+    void connect (func_type f) { m_func = f; }
+    R operator ()(T1 a1, T2 a2) const { return m_func (a1, a2); }
+private:
+    func_type m_func;
+};
+
+template<typename R, typename T1, typename T2, typename T3>
+struct signal< R(T1, T2, T3)>
+{
+    typedef std::function<R(T1, T2, T3)> func_type;
+    void connect (func_type f) {m_func = f; }
+    R operator ()(T1 a1, T2 a2, T3 a3) const { return m_func (a1, a2, a3); }
+private:
+    func_type m_func;
+};
+
+};
+
+#else // __GXX_EXPERIMENTAL_CXX0X__
+
+#  include <boost/signals2.hpp>
+#  include <boost/bind.hpp>
+
+namespace std {
+    // import boost::bind into std namespace
+    using boost::bind;
+};
+
+namespace PY {
+    // use boost::signal2
+    namespace bs2 = boost::signals2;
+    template <typename Signature>
+    struct signal : public bs2::signal_type
+        <Signature, bs2::keywords::mutex_type<bs2::dummy_mutex> >::type { };
+
+};
+
+#endif // __GXX_EXPERIMENTAL_CXX0X__
+#endif // __PY_SIGNAL_H_
+
index ff920b7..a246152 100644 (file)
 #include <string>
 #include <vector>
 #include <glib.h>
-#include <boost/shared_ptr.hpp>
+#include "PYUtil.h"
 
 namespace PY {
 
 class SpecialPhrase;
-typedef boost::shared_ptr<SpecialPhrase> SpecialPhrasePtr;
+typedef std::shared_ptr<SpecialPhrase> SpecialPhrasePtr;
 
 class SpecialPhraseTable {
 private:
index 1e22089..cb5f51b 100644 (file)
 #include <cstdlib>
 #include <string>
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#  include <memory>
+#else
+#  include <boost/shared_ptr.hpp>
+#  include <boost/scoped_ptr.hpp>
+
+namespace std {
+    // import boost::shared_ptr to std namespace
+    using boost::shared_ptr;
+    // import boost::scoped_ptr to std namespace, and rename to unique_ptr
+    // XXX: the unique_ptr can transfer the pointer ownership,
+    //      but scoped_ptr cannot.
+    template<typename T> class unique_ptr : public boost::scoped_ptr<T> {};
+};
+
+#endif
+
 #include <ibus.h>
 
 namespace PY {