[glom] ConnectionPool: Use std::shared_ptr<> for m_instance.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] ConnectionPool: Use std::shared_ptr<> for m_instance.
- Date: Fri, 5 Feb 2016 07:56:13 +0000 (UTC)
commit b1f81a53236c3056c2de13cce95d923aa3b5abab
Author: Murray Cumming <murrayc murrayc com>
Date: Thu Feb 4 22:35:32 2016 +0100
ConnectionPool: Use std::shared_ptr<> for m_instance.
glom/libglom/connectionpool.cc | 9 ++++-----
glom/libglom/connectionpool.h | 16 ++++++++++------
2 files changed, 14 insertions(+), 11 deletions(-)
---
diff --git a/glom/libglom/connectionpool.cc b/glom/libglom/connectionpool.cc
index 2dc2ade..f78bf28 100644
--- a/glom/libglom/connectionpool.cc
+++ b/glom/libglom/connectionpool.cc
@@ -104,7 +104,7 @@ void SharedConnection::close()
}
//init_db_details static data:
-ConnectionPool* ConnectionPool::m_instance = nullptr;
+std::shared_ptr<ConnectionPool> ConnectionPool::m_instance;
ConnectionPool::ConnectionPool()
:
@@ -127,14 +127,14 @@ ConnectionPool::~ConnectionPool()
}
//static
-ConnectionPool* ConnectionPool::get_instance()
+std::shared_ptr<ConnectionPool> ConnectionPool::get_instance()
{
//TODO: Synchronize this for threads?
if(m_instance)
return m_instance;
else
{
- m_instance = new ConnectionPool();
+ m_instance = std::make_shared<ConnectionPool>();
return m_instance;
}
}
@@ -199,8 +199,7 @@ void ConnectionPool::setup_from_document(const std::shared_ptr<const Document>&
void ConnectionPool::delete_instance()
{
- delete m_instance;
- m_instance = nullptr;
+ m_instance.reset();
}
bool ConnectionPool::get_ready_to_connect() const
diff --git a/glom/libglom/connectionpool.h b/glom/libglom/connectionpool.h
index 2c45c52..3835fc9 100644
--- a/glom/libglom/connectionpool.h
+++ b/glom/libglom/connectionpool.h
@@ -85,23 +85,27 @@ class Document;
class ConnectionPool : public sigc::trackable
{
private:
+
+
+public:
+
+ //These are public for use by std::make_shared<>().
+ //TODO: Does this need to be virtual?
ConnectionPool();
+ virtual ~ConnectionPool();
+
ConnectionPool(const ConnectionPool& src) = delete;
ConnectionPool(ConnectionPool&& src) = delete;
ConnectionPool& operator=(const ConnectionPool& src) = delete;
ConnectionPool& operator=(ConnectionPool&& src) = delete;
- virtual ~ConnectionPool();
- //ConnectionPool& operator=(const ConnectionPool& src);
-
-public:
typedef ConnectionPoolBackends::Backend Backend;
typedef Backend::type_vec_const_fields type_vec_const_fields;
/** Get the singleton instance.
* Use delete_instance() when the program quits.
*/
- static ConnectionPool* get_instance();
+ static std::shared_ptr<ConnectionPool> get_instance();
/** Whether the connection is ready to be used.
*/
@@ -348,7 +352,7 @@ private:
private:
- static ConnectionPool* m_instance;
+ static std::shared_ptr<ConnectionPool> m_instance;
SlotGetDocument m_slot_get_document;
type_void_slot m_epc_slot_begin, m_epc_slot_progress, m_epc_slot_done;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]