[glom] ConnectionPool: Use std::shared_ptr<> for m_field_types.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] ConnectionPool: Use std::shared_ptr<> for m_field_types.
- Date: Fri, 5 Feb 2016 07:56:33 +0000 (UTC)
commit 16bc9123929a8d63289d9c9430f0d59f5691d6a5
Author: Murray Cumming <murrayc murrayc com>
Date: Thu Feb 4 23:25:23 2016 +0100
ConnectionPool: Use std::shared_ptr<> for m_field_types.
glom/libglom/connectionpool.cc | 18 +++++++-----------
glom/libglom/connectionpool.h | 4 ++--
glom/libglom/data_structure/field.cc | 20 ++++++++++----------
3 files changed, 19 insertions(+), 23 deletions(-)
---
diff --git a/glom/libglom/connectionpool.cc b/glom/libglom/connectionpool.cc
index 5acd38a..4efa75b 100644
--- a/glom/libglom/connectionpool.cc
+++ b/glom/libglom/connectionpool.cc
@@ -112,7 +112,6 @@ ConnectionPool::ConnectionPool()
m_dialog_epc_progress(nullptr),
m_sharedconnection_refcount(0),
m_ready_to_connect(false),
- m_pFieldTypes(nullptr),
m_show_debug_output(false),
m_auto_server_shutdown(true),
m_fake_connection(false)
@@ -121,8 +120,6 @@ ConnectionPool::ConnectionPool()
ConnectionPool::~ConnectionPool()
{
- delete m_pFieldTypes;
- m_pFieldTypes = nullptr;
}
//static
@@ -372,8 +369,8 @@ std::shared_ptr<SharedConnection> ConnectionPool::connect()
// Connection succeeded
// Create the fieldtypes member if it has not already been done:
- if(!m_pFieldTypes)
- m_pFieldTypes = new FieldTypes(m_refGdaConnection);
+ if(!m_field_types)
+ m_field_types = std::make_shared<FieldTypes>(m_refGdaConnection);
#ifndef G_OS_WIN32
//Let other clients discover this server via avahi:
@@ -504,13 +501,13 @@ Glib::ustring ConnectionPool::get_database() const
return m_database;
}
-const FieldTypes* ConnectionPool::get_field_types() const
+std::shared_ptr<const FieldTypes> ConnectionPool::get_field_types() const
{
//TODO: Investigate this:
- //if(!m_pFieldTypes)
- // std::cerr << G_STRFUNC << ": m_pFieldTypes is null but this should never happen." << std::endl;
+ //if(!m_field_types)
+ // std::cerr << G_STRFUNC << ": m_field_types is null but this should never happen." << std::endl;
- return m_pFieldTypes;
+ return m_field_types;
}
Gnome::Gda::SqlOperatorType ConnectionPool::get_string_find_operator() const
@@ -532,8 +529,7 @@ void ConnectionPool::invalidate_connection()
m_refGdaConnection.reset();
m_sharedconnection_refcount = 0;
- delete m_pFieldTypes;
- m_pFieldTypes = nullptr;
+ m_field_types.reset();
}
void ConnectionPool::on_sharedconnection_finished()
diff --git a/glom/libglom/connectionpool.h b/glom/libglom/connectionpool.h
index 1ead068..475b5e1 100644
--- a/glom/libglom/connectionpool.h
+++ b/glom/libglom/connectionpool.h
@@ -197,7 +197,7 @@ public:
Glib::ustring get_password() const;
Glib::ustring get_database() const;
- const FieldTypes* get_field_types() const;
+ std::shared_ptr<const FieldTypes> get_field_types() const;
Gnome::Gda::SqlOperatorType get_string_find_operator() const;
typedef Backend::InitErrors InitErrors;
@@ -342,7 +342,7 @@ private:
bool m_ready_to_connect;
Glib::ustring m_user, m_password, m_database;
- FieldTypes* m_pFieldTypes;
+ std::shared_ptr<FieldTypes> m_field_types;
bool m_show_debug_output, m_auto_server_shutdown;
bool m_fake_connection;
diff --git a/glom/libglom/data_structure/field.cc b/glom/libglom/data_structure/field.cc
index 3ea56f1..2e584ff 100644
--- a/glom/libglom/data_structure/field.cc
+++ b/glom/libglom/data_structure/field.cc
@@ -132,7 +132,7 @@ Glib::RefPtr<const Gnome::Gda::Column> Field::get_field_info() const
return m_field_info;
}
-static const FieldTypes* get_field_types()
+static std::shared_ptr<const FieldTypes> get_field_types()
{
auto connection_pool = ConnectionPool::get_instance();
if(!connection_pool)
@@ -161,12 +161,12 @@ void Field::set_field_info(const Glib::RefPtr<Gnome::Gda::Column>& fieldinfo)
{
cur_type = get_gda_type_for_glom_type(glom_type);
- const auto pFieldTypes = get_field_types();
+ const auto field_types = get_field_types();
- if(pFieldTypes)
+ if(field_types)
{
while(cur_type != new_type && cur_type != G_TYPE_NONE)
- cur_type = pFieldTypes->get_fallback_type_for_gdavaluetype(cur_type);
+ cur_type = field_types->get_fallback_type_for_gdavaluetype(cur_type);
}
}
@@ -188,13 +188,13 @@ void Field::set_field_info(const Glib::RefPtr<Gnome::Gda::Column>& fieldinfo)
GType Field::get_gda_data_type_with_fallback(const Gnome::Gda::Value& value)
{
auto cur_type = get_gda_type_for_glom_type(get_glom_type());
- const auto pFieldTypes = get_field_types();
+ const auto field_types = get_field_types();
// Take into account that value might be one of the fallback types
- if(pFieldTypes)
+ if(field_types)
{
while(cur_type != value.get_value_type() && cur_type != G_TYPE_NONE)
- cur_type = pFieldTypes->get_fallback_type_for_gdavaluetype(cur_type);
+ cur_type = field_types->get_fallback_type_for_gdavaluetype(cur_type);
}
return cur_type;
@@ -538,11 +538,11 @@ Glib::ustring Field::get_sql_type() const
auto pConnectionPool = ConnectionPool::get_instance();
if(pConnectionPool)
{
- const auto pFieldTypes = pConnectionPool->get_field_types();
- if(pFieldTypes)
+ const auto field_types = pConnectionPool->get_field_types();
+ if(field_types)
{
const auto fieldType = m_field_info->get_g_type();
- strType = pFieldTypes->get_string_name_for_gdavaluetype(fieldType);
+ strType = field_types->get_string_name_for_gdavaluetype(fieldType);
}
else
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]