[glom/c++11v2: 3/3] C++11: Use std::function instead of sigc::slot.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom/c++11v2: 3/3] C++11: Use std::function instead of sigc::slot.
- Date: Tue, 30 Jun 2015 18:12:57 +0000 (UTC)
commit bfc14b42493dfc208413af8e79198dda2585975b
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 383868d..9bf1b70 100644
--- a/glom/appwindow.cc
+++ b/glom/appwindow.cc
@@ -134,9 +134,9 @@ AppWindow::AppWindow(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>&
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
@@ -1001,7 +1001,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.
@@ -1424,7 +1424,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 c533912..d3a3af0 100644
--- a/glom/frame_glom.cc
+++ b/glom/frame_glom.cc
@@ -2387,7 +2387,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 2162937..025cfba 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 0084f41..885c061 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 bad9bb6..a02d465 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
{
@@ -121,7 +122,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 940071c..3b22710 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 4c1ced0..cd7b4ca 100644
--- a/glom/libglom/db_utils.h
+++ b/glom/libglom/db_utils.h
@@ -34,13 +34,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 8fb6403..9702f86 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
{
@@ -455,7 +456,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 db01343..08894d4 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 8e082e4..9f576eb 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 << G_STRFUNC << ": DbUtils::create_database() failed." << std::endl;
@@ -379,7 +379,7 @@ bool test_create_and_selfhost_from_data(const Glib::ustring& example_file_conten
return false;
}
- document.set_allow_autosave(false); //To simplify things and to not depend implicitly on autosave.
+ const bool recreated = Glom::DbUtils::recreate_database_from_document(&document, &on_recreate_progress );
int failure_code = 0;
const bool test = document.load_from_data((const guchar*)example_file_contents.c_str(),
example_file_contents.bytes(), failure_code);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]