[glom/c++11] C++11: Use std::function instead of sigc::slot.



commit 20194ff9acd6f337c8c7b6a6250e896ecec57137
Author: Murray Cumming <murrayc murrayc com>
Date:   Fri Jul 5 15:55:52 2013 +0200

    C++11: Use std::function instead of sigc::slot.

 glom/appwindow.cc                                |   10 +++++-----
 glom/frame_glom.cc                               |    2 +-
 glom/glom_create_from_example.cc                 |    2 +-
 glom/libglom/connectionpool.h                    |    4 ++--
 glom/libglom/connectionpool_backends/backend.h   |    3 ++-
 glom/libglom/db_utils.cc                         |    4 ++--
 glom/libglom/db_utils.h                          |    4 ++--
 glom/libglom/document/document.h                 |    3 ++-
 glom/libglom/python_embed/py_glom_ui_callbacks.h |   10 +++++-----
 glom/libglom/spawn_with_feedback.h               |    4 ++--
 glom/python_embed/python_ui_callbacks.cc         |   10 +++++-----
 tests/python/test_python_execute_script.cc       |   10 +++++-----
 tests/test_selfhosting_utils.cc                  |    4 ++--
 13 files changed, 36 insertions(+), 34 deletions(-)
---
diff --git a/glom/appwindow.cc b/glom/appwindow.cc
index bd9efdb..2663793 100644
--- a/glom/appwindow.cc
+++ b/glom/appwindow.cc
@@ -108,9 +108,9 @@ AppWindow::AppWindow(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>&
   ConnectionPool* connection_pool = ConnectionPool::get_instance();
   if(!connection_pool)
     connection_pool->set_avahi_publish_callbacks(
-      sigc::mem_fun(*this, &AppWindow::on_connection_avahi_begin),
-      sigc::mem_fun(*this, &AppWindow::on_connection_avahi_progress),
-      sigc::mem_fun(*this, &AppWindow::on_connection_avahi_done) );
+      sigc::bind(&AppWindow::on_connection_avahi_begin, this),
+      sigc::bind(&AppWindow::on_connection_avahi_progress, this),
+      sigc::bind(&AppWindow::on_connection_avahi_done, this) );
 #endif
 #endif // !GLOM_ENABLE_CLIENT_ONLY
 
@@ -1129,7 +1129,7 @@ bool AppWindow::on_document_load()
     else
     {
 #ifndef GLOM_ENABLE_CLIENT_ONLY
-      connection_pool->set_get_document_func( sigc::mem_fun(*this, 
&AppWindow::on_connection_pool_get_document) );
+      connection_pool->set_get_document_func( std::bind(&AppWindow::on_connection_pool_get_document, this) );
 #endif
 
       connection_pool->set_ready_to_connect(true); //connect_to_server() will now attempt the connection-> 
Shared instances of m_Connection will also be usable.
@@ -1545,7 +1545,7 @@ void AppWindow::existing_or_new_new()
    //Tell the connection pool about the document:
    ConnectionPool* connection_pool = ConnectionPool::get_instance();
    if(connection_pool)
-     connection_pool->set_get_document_func( sigc::mem_fun(*this, 
&AppWindow::on_connection_pool_get_document) );
+     connection_pool->set_get_document_func( std::bind(&AppWindow::on_connection_pool_get_document, this) );
 
     const bool connected = m_pFrame->connection_request_password_and_choose_new_database_name();
     if(!connected)
diff --git a/glom/frame_glom.cc b/glom/frame_glom.cc
index 93836b0..1c465eb 100644
--- a/glom/frame_glom.cc
+++ b/glom/frame_glom.cc
@@ -2294,7 +2294,7 @@ bool Frame_Glom::create_database(const Glib::ustring& database_name, const Glib:
   {
     BusyCursor busycursor(*pWindowApp);
 
-    sigc::slot<void> onProgress; //TODO: Show visual feedback.
+    std::function<void()> onProgress; //TODO: Show visual feedback.
     result = DbUtils::create_database(get_document(), database_name, title, onProgress);
   }
 
diff --git a/glom/glom_create_from_example.cc b/glom/glom_create_from_example.cc
index 20b9e02..77fa082 100644
--- a/glom/glom_create_from_example.cc
+++ b/glom/glom_create_from_example.cc
@@ -511,7 +511,7 @@ int main(int argc, char* argv[])
   }
   g_assert(started == Glom::ConnectionPool::Backend::STARTUPERROR_NONE);
 
-  const bool recreated = Glom::DbUtils::recreate_database_from_document(&document, 
sigc::ptr_fun(&on_recreate_progress) );
+  const bool recreated = Glom::DbUtils::recreate_database_from_document(&document, &on_recreate_progress);
   if(!recreated)
     cleanup();
   g_assert(recreated);
diff --git a/glom/libglom/connectionpool.h b/glom/libglom/connectionpool.h
index 6d27aea..568b451 100644
--- a/glom/libglom/connectionpool.h
+++ b/glom/libglom/connectionpool.h
@@ -111,7 +111,7 @@ public:
   /// Delete the singleton so it doesn't show up as leaked memory in, for instance, valgrind.
   static void delete_instance();
 
-  typedef sigc::slot<void> type_void_slot;
+  typedef std::function<void()> type_void_slot;
 
 #ifndef G_OS_WIN32
   /** Set callbacks that will be called to show UI while starting to advertise
@@ -283,7 +283,7 @@ public:
    * This callback avoids Connection having to link to AppWindow,
    * and avoids us worrying about whether a previously-set document (via a set_document() method) is still 
valid.
    */
-  typedef sigc::slot<Document*> SlotGetDocument;
+  typedef std::function<Document*()> SlotGetDocument;
   void set_get_document_func(const SlotGetDocument& slot);
 
 #ifndef G_OS_WIN32
diff --git a/glom/libglom/connectionpool_backends/backend.h b/glom/libglom/connectionpool_backends/backend.h
index 66716ff..7422645 100644
--- a/glom/libglom/connectionpool_backends/backend.h
+++ b/glom/libglom/connectionpool_backends/backend.h
@@ -27,6 +27,7 @@
 #include <libglom/data_structure/field.h>
 
 #include <memory>
+#include <functional>
 
 namespace Glom
 {
@@ -119,7 +120,7 @@ protected:
   /** This callback should show UI to indicate that work is still happening.
    * For instance, a pulsing ProgressBar.
    */
-  typedef sigc::slot<void> SlotProgress;
+  typedef std::function<void()> SlotProgress;
 
   /** This method is called for one-time initialization of the database
    * storage. There is no need to implement this function if the data is centrally
diff --git a/glom/libglom/db_utils.cc b/glom/libglom/db_utils.cc
index 296e200..cd71ce8 100644
--- a/glom/libglom/db_utils.cc
+++ b/glom/libglom/db_utils.cc
@@ -101,7 +101,7 @@ static bool update_gda_metastore_for_table(const Glib::ustring& table_name)
   return true;
 }
 
-bool create_database(Document* document, const Glib::ustring& database_name, const Glib::ustring& title, 
const sigc::slot<void>& progress)
+bool create_database(Document* document, const Glib::ustring& database_name, const Glib::ustring& title, 
const std::function<void()>& progress)
 {
 #if 1
   // This seems to increase the chance that the database creation does not
@@ -207,7 +207,7 @@ bool create_database(Document* document, const Glib::ustring& database_name, con
   }
 }
 
-bool recreate_database_from_document(Document* document, const sigc::slot<void>& progress)
+bool recreate_database_from_document(Document* document, const std::function<void()>& progress)
 {
   ConnectionPool* connection_pool = ConnectionPool::get_instance();
   if(!connection_pool)
diff --git a/glom/libglom/db_utils.h b/glom/libglom/db_utils.h
index d59ab74..b224ccd 100644
--- a/glom/libglom/db_utils.h
+++ b/glom/libglom/db_utils.h
@@ -33,13 +33,13 @@ namespace DbUtils
 /**
  * This also saves the connection port in the document if self-hosting.
  */
-bool create_database(Document* document, const Glib::ustring& database_name, const Glib::ustring& title, 
const sigc::slot<void>& progress);
+bool create_database(Document* document, const Glib::ustring& database_name, const Glib::ustring& title, 
const std::function<void()>& progress);
 
 //TODO: Use this in Glom::AppWindow?
 /** Create the database on an already-connected server.
  * This also saves some details in the document.
  */
-bool recreate_database_from_document(Document* document, const sigc::slot<void>& progress);
+bool recreate_database_from_document(Document* document, const std::function<void()>& progress);
 
 /** This creates the standard tables if necessary,
  * filling them with some information from the document.
diff --git a/glom/libglom/document/document.h b/glom/libglom/document/document.h
index d33c031..3807dcd 100644
--- a/glom/libglom/document/document.h
+++ b/glom/libglom/document/document.h
@@ -42,6 +42,7 @@
 #include <vector>
 #include <map>
 #include <limits> // for numeric_limits
+#include <functional>
 
 namespace Gtk
 {
@@ -453,7 +454,7 @@ public:
   /** This callback should show UI to indicate that work is still happening.
    * For instance, a pulsing ProgressBar.
    */
-  typedef sigc::slot<void> SlotProgress;
+  typedef std::function<void()> SlotProgress;
   
   /** Save a copy of the document as a backup.
    * This document (and its URI) will not be changed.
diff --git a/glom/libglom/python_embed/py_glom_ui_callbacks.h 
b/glom/libglom/python_embed/py_glom_ui_callbacks.h
index a4c7af3..65f5580 100644
--- a/glom/libglom/python_embed/py_glom_ui_callbacks.h
+++ b/glom/libglom/python_embed/py_glom_ui_callbacks.h
@@ -39,28 +39,28 @@ public:
   /** For example,
    * void on_show_table_details(const Glib::ustring& table_name, const Gnome::Gda::Value& primary_key_value);
    */
-  sigc::slot<void, const Glib::ustring&, const Gnome::Gda::Value&> m_slot_show_table_details;
+  std::function<void(const Glib::ustring&, const Gnome::Gda::Value&)> m_slot_show_table_details;
 
    /** For example,
    * void on_show_table_list(const Glib::ustring& table_name);
    */
-  sigc::slot<void, const Glib::ustring&> m_slot_show_table_list;
+  std::function<void(const Glib::ustring&)> m_slot_show_table_list;
 
    /** For example,
    * void on_print_report(const Glib::ustring& report_name);
    */
-  sigc::slot<void, const Glib::ustring&> m_slot_print_report;
+  std::function<void(const Glib::ustring&)> m_slot_print_report;
 
    /** For example,
    * void on_print_layout();
    */
-  sigc::slot<void> m_slot_print_layout;
+  std::function<void()> m_slot_print_layout;
 
   /** For example,
    * void on_start_new_record();
    * Use an empty Value for auto-created fields.
    */
-  sigc::slot<void> m_slot_start_new_record;
+  std::function<void()> m_slot_start_new_record;
 };
 
 } //namespace Glom
diff --git a/glom/libglom/spawn_with_feedback.h b/glom/libglom/spawn_with_feedback.h
index d45251a..e59e78a 100644
--- a/glom/libglom/spawn_with_feedback.h
+++ b/glom/libglom/spawn_with_feedback.h
@@ -22,7 +22,7 @@
 #define GLOM_SPAWN_WITH_FEEDBACK_H
 
 #include <glibmm/ustring.h>
-#include <sigc++/sigc++.h>
+#include <functional>
 
 namespace Glom
 {
@@ -33,7 +33,7 @@ namespace Spawn
 /** This callback should show UI to indicate that work is still happening.
  * For instance, a pulsing ProgressBar.
  */
-typedef sigc::slot<void> SlotProgress;
+typedef std::function<void()> SlotProgress;
 
 /** Execute a command-line command, and wait for it to return.
  * @param command The command-line command.
diff --git a/glom/python_embed/python_ui_callbacks.cc b/glom/python_embed/python_ui_callbacks.cc
index 497b1f1..8af82ce 100644
--- a/glom/python_embed/python_ui_callbacks.cc
+++ b/glom/python_embed/python_ui_callbacks.cc
@@ -27,15 +27,15 @@ namespace Glom
 AppPythonUICallbacks::AppPythonUICallbacks()
 {
   m_slot_show_table_details =
-    sigc::mem_fun(*this, &AppPythonUICallbacks::on_show_table_details);
+    std::bind(&AppPythonUICallbacks::on_show_table_details, this, std::placeholders::_1, 
std::placeholders::_2);
   m_slot_show_table_list =
-    sigc::mem_fun(*this, &AppPythonUICallbacks::on_show_table_list);
+    std::bind(&AppPythonUICallbacks::on_show_table_list, this, std::placeholders::_1);
   m_slot_print_report =
-    sigc::mem_fun(*this, &AppPythonUICallbacks::on_print_report);
+    std::bind(&AppPythonUICallbacks::on_print_report, this, std::placeholders::_1);
   m_slot_print_layout =
-    sigc::mem_fun(*this, &AppPythonUICallbacks::on_print_layout);
+    std::bind(&AppPythonUICallbacks::on_print_layout, this);
   m_slot_start_new_record =
-    sigc::mem_fun(*this, &AppPythonUICallbacks::on_start_new_record);
+    std::bind(&AppPythonUICallbacks::on_start_new_record, this);
 }
 
 void AppPythonUICallbacks::on_show_table_details(const Glib::ustring& table_name, const Gnome::Gda::Value& 
primary_key_value)
diff --git a/tests/python/test_python_execute_script.cc b/tests/python/test_python_execute_script.cc
index e9c1436..c8063fe 100644
--- a/tests/python/test_python_execute_script.cc
+++ b/tests/python/test_python_execute_script.cc
@@ -69,15 +69,15 @@ int main()
 
   Glom::PythonUICallbacks callbacks;
   callbacks.m_slot_show_table_list =
-    sigc::ptr_fun(&on_script_ui_show_table_list);
+    &on_script_ui_show_table_list;
   callbacks.m_slot_show_table_details =
-    sigc::ptr_fun(&on_script_ui_show_table_details);
+    &on_script_ui_show_table_details;
   callbacks.m_slot_print_report =
-    sigc::ptr_fun(&on_script_ui_print_report);
+    &on_script_ui_print_report;
   callbacks.m_slot_print_layout =
-    sigc::ptr_fun(&on_script_ui_print_layout);
+    &on_script_ui_print_layout;
   callbacks.m_slot_start_new_record =
-    sigc::ptr_fun(&on_script_ui_start_new_record);
+    &on_script_ui_start_new_record;
 
   //Execute a python script:
   Glib::ustring error_message;
diff --git a/tests/test_selfhosting_utils.cc b/tests/test_selfhosting_utils.cc
index d9fcbc7..cc91673 100644
--- a/tests/test_selfhosting_utils.cc
+++ b/tests/test_selfhosting_utils.cc
@@ -254,7 +254,7 @@ bool test_create_and_selfhost_new_database(Glom::Document& document, Glom::Docum
 
   //Create a database:
   const bool created = Glom::DbUtils::create_database(&document, db_name,
-    "test title", sigc::ptr_fun(&on_db_creation_progress));
+    "test title", &on_db_creation_progress);
   if(!created)
   {
     std::cerr << "DbUtils::create_database() failed." << std::endl;
@@ -357,7 +357,7 @@ bool test_create_and_selfhost_from_uri(const Glib::ustring& example_file_uri, Gl
     return false;
   }
 
-  const bool recreated = Glom::DbUtils::recreate_database_from_document(&document, 
sigc::ptr_fun(&on_recreate_progress) );
+  const bool recreated = Glom::DbUtils::recreate_database_from_document(&document, &on_recreate_progress );
   if(!recreated)
     test_selfhosting_cleanup();
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]