[glom] C++11: Use std::sto*() instead of strto* and ato*().



commit 0db134edcc4346b34296fa973503cb1d16d87ad9
Author: Murray Cumming <murrayc murrayc com>
Date:   Tue Sep 1 12:54:58 2015 +0200

    C++11: Use std::sto*() instead of strto* and ato*().
    
    Avoiding the need to use std::string::c_str().

 glom/libglom/connectionpool_backends/mysql.cc      |    2 +-
 .../connectionpool_backends/mysql_central.cc       |   10 +++++-----
 glom/libglom/connectionpool_backends/postgres.cc   |    2 +-
 .../connectionpool_backends/postgres_central.cc    |   10 +++++-----
 glom/mode_design/dialog_database_preferences.cc    |    4 ++--
 glom/mode_design/layout/dialog_layout_details.cc   |    6 ++----
 .../layout/layout_item_dialogs/box_formatting.cc   |    2 +-
 7 files changed, 17 insertions(+), 19 deletions(-)
---
diff --git a/glom/libglom/connectionpool_backends/mysql.cc b/glom/libglom/connectionpool_backends/mysql.cc
index 6e8b1ac..d384ca5 100644
--- a/glom/libglom/connectionpool_backends/mysql.cc
+++ b/glom/libglom/connectionpool_backends/mysql.cc
@@ -162,7 +162,7 @@ Glib::RefPtr<Gnome::Gda::Connection> MySQL::attempt_connect(const Glib::ustring&
       if(posName != Glib::ustring::npos)
       {
         const auto versionPart = version_text.substr(namePart.size());
-        m_mysql_server_version = strtof(versionPart.c_str(), 0);
+        m_mysql_server_version = std::stof(versionPart);
 
 #ifdef GLOM_CONNECTION_DEBUG
         std::cout << "  MySQL Server version: " << m_mysql_server_version << std::endl;
diff --git a/glom/libglom/connectionpool_backends/mysql_central.cc 
b/glom/libglom/connectionpool_backends/mysql_central.cc
index 91da15b..47c5b6e 100644
--- a/glom/libglom/connectionpool_backends/mysql_central.cc
+++ b/glom/libglom/connectionpool_backends/mysql_central.cc
@@ -98,7 +98,7 @@ Glib::RefPtr<Gnome::Gda::Connection> MySQLCentralHosted::connect(const Glib::ust
   {
     connection = attempt_connect(port, database, username, password, fake_connection);
     connection_possible = true;
-    m_port = atoi(port.c_str());
+    m_port = std::stoi(port);
   }
   catch(const ExceptionConnection& ex)
   {
@@ -107,7 +107,7 @@ Glib::RefPtr<Gnome::Gda::Connection> MySQLCentralHosted::connect(const Glib::ust
     if(ex.get_failure_type() == ExceptionConnection::failure_type::NO_DATABASE)
     {
       connection_possible = true;
-      m_port = atoi(port.c_str());
+      m_port = std::stoi(port);
     }
   }
 
@@ -122,7 +122,7 @@ Glib::RefPtr<Gnome::Gda::Connection> MySQLCentralHosted::connect(const Glib::ust
       {
         connection = attempt_connect(port, database, username, password, fake_connection);
         connection_possible = true;
-        m_port = atoi(port.c_str());
+        m_port = std::stoi(port);
       }
       catch(const ExceptionConnection& ex)
       {
@@ -133,7 +133,7 @@ Glib::RefPtr<Gnome::Gda::Connection> MySQLCentralHosted::connect(const Glib::ust
         if(ex.get_failure_type() == ExceptionConnection::failure_type::NO_DATABASE)
         {
           connection_possible = true;
-          m_port = atoi(port.c_str());
+          m_port = std::stoi(port);
         }
       }
 
@@ -146,7 +146,7 @@ Glib::RefPtr<Gnome::Gda::Connection> MySQLCentralHosted::connect(const Glib::ust
   if(connection)
   {
     //Remember working port:
-    m_port = atoi(port.c_str());
+    m_port = std::stoi(port);
   }
   else
   {
diff --git a/glom/libglom/connectionpool_backends/postgres.cc 
b/glom/libglom/connectionpool_backends/postgres.cc
index a77b0a8..8fb7f18 100644
--- a/glom/libglom/connectionpool_backends/postgres.cc
+++ b/glom/libglom/connectionpool_backends/postgres.cc
@@ -149,7 +149,7 @@ Glib::RefPtr<Gnome::Gda::Connection> Postgres::attempt_connect(const Glib::ustri
       if(posName != Glib::ustring::npos)
       {
         const auto versionPart = version_text.substr(namePart.size());
-        m_postgres_server_version = strtof(versionPart.c_str(), 0);
+        m_postgres_server_version = std::stof(versionPart);
 
 #ifdef GLOM_CONNECTION_DEBUG
         std::cout << "  Postgres Server version: " << m_postgres_server_version << std::endl;
diff --git a/glom/libglom/connectionpool_backends/postgres_central.cc 
b/glom/libglom/connectionpool_backends/postgres_central.cc
index 54e0807..89ec998 100644
--- a/glom/libglom/connectionpool_backends/postgres_central.cc
+++ b/glom/libglom/connectionpool_backends/postgres_central.cc
@@ -97,7 +97,7 @@ Glib::RefPtr<Gnome::Gda::Connection> PostgresCentralHosted::connect(const Glib::
   {
     connection = attempt_connect(port, database, username, password, fake_connection);
     connection_possible = true;
-    m_port = atoi(port.c_str());
+    m_port = std::stoi(port);
   }
   catch(const ExceptionConnection& ex)
   {
@@ -106,7 +106,7 @@ Glib::RefPtr<Gnome::Gda::Connection> PostgresCentralHosted::connect(const Glib::
     if(ex.get_failure_type() == ExceptionConnection::failure_type::NO_DATABASE)
     {
       connection_possible = true;
-      m_port = atoi(port.c_str());
+      m_port = std::stoi(port);
     }
   }
 
@@ -121,7 +121,7 @@ Glib::RefPtr<Gnome::Gda::Connection> PostgresCentralHosted::connect(const Glib::
       {
         connection = attempt_connect(port, database, username, password, fake_connection);
         connection_possible = true;
-        m_port = atoi(port.c_str());
+        m_port = std::stoi(port);
       }
       catch(const ExceptionConnection& ex)
       {
@@ -132,7 +132,7 @@ Glib::RefPtr<Gnome::Gda::Connection> PostgresCentralHosted::connect(const Glib::
         if(ex.get_failure_type() == ExceptionConnection::failure_type::NO_DATABASE)
         {
           connection_possible = true;
-          m_port = atoi(port.c_str());
+          m_port = std::stoi(port);
         }
       }
 
@@ -145,7 +145,7 @@ Glib::RefPtr<Gnome::Gda::Connection> PostgresCentralHosted::connect(const Glib::
   if(connection)
   {
     //Remember working port:
-    m_port = atoi(port.c_str());
+    m_port = std::stoi(port);
   }
   else
   {
diff --git a/glom/mode_design/dialog_database_preferences.cc b/glom/mode_design/dialog_database_preferences.cc
index dbb266a..67582b0 100644
--- a/glom/mode_design/dialog_database_preferences.cc
+++ b/glom/mode_design/dialog_database_preferences.cc
@@ -120,7 +120,7 @@ void Dialog_Database_Preferences::on_treeview_cell_edited_next_value(const Glib:
     Gtk::TreeModel::Row row = *iter;
 
     //Set it in the model:
-    long new_value = atol(new_text.c_str()); //TODO: Careful of locale.
+    const auto new_value = std::stol(new_text); //TODO: Careful of locale.
     row[m_columns.m_col_next_value] = new_value;
 
 
@@ -201,7 +201,7 @@ void Dialog_Database_Preferences::load_from_document()
     row[m_columns.m_col_field] = Conversions::get_text_for_gda_value(Field::glom_field_type::TEXT, 
datamodel->get_value_at(1, i), numeric_format);
 
     //TODO: Careful of locale:
-    row[m_columns.m_col_next_value] = atol(datamodel->get_value_at(2, i).to_string().c_str());
+    row[m_columns.m_col_next_value] = std::stol(datamodel->get_value_at(2, i).to_string());
   }
 
   m_model_autoincrements->set_default_sort_func( sigc::mem_fun(*this, 
&Dialog_Database_Preferences::on_autoincrements_sort) );
diff --git a/glom/mode_design/layout/dialog_layout_details.cc 
b/glom/mode_design/layout/dialog_layout_details.cc
index 75af2b9..1455f36 100644
--- a/glom/mode_design/layout/dialog_layout_details.cc
+++ b/glom/mode_design/layout/dialog_layout_details.cc
@@ -1331,8 +1331,7 @@ void Dialog_Layout_Details::on_treeview_cell_edited_column_width(const Glib::ust
       if(layout_item)
       {
         //Convert the text to a number, using the same logic used by GtkCellRendererText when it stores 
numbers.
-        char* pchEnd = nullptr;
-        const auto new_value = static_cast<guint>( strtod(new_text.c_str(), &pchEnd) );
+        const auto new_value = static_cast<guint>( std::stod(new_text) );
 
         //Store the user's new value in the model:
         layout_item->set_display_width(new_value);
@@ -1366,8 +1365,7 @@ void Dialog_Layout_Details::on_treeview_cell_edited_group_columns(const Glib::us
       //new_value << astream; //Get it out of the stream as the numerical type.
 
       //Convert the text to a number, using the same logic used by GtkCellRendererText when it stores 
numbers.
-      char* pchEnd = nullptr;
-      guint new_value = static_cast<guint>( strtod(new_text.c_str(), &pchEnd) );
+      auto new_value = static_cast<guint>( std::stod(new_text) );
 
       //Don't allow a 0 columns_count:
       if(new_value == 0)
diff --git a/glom/mode_design/layout/layout_item_dialogs/box_formatting.cc 
b/glom/mode_design/layout/layout_item_dialogs/box_formatting.cc
index 70c9f4c..7a877e0 100644
--- a/glom/mode_design/layout/layout_item_dialogs/box_formatting.cc
+++ b/glom/mode_design/layout/layout_item_dialogs/box_formatting.cc
@@ -351,7 +351,7 @@ bool Box_Formatting::get_formatting(Formatting& format) const
   m_format.m_numeric_format.m_decimal_places_restricted = m_checkbox_format_use_decimal_places->get_active();
 
   const auto strDecPlaces = m_entry_format_decimal_places->get_text();
-  m_format.m_numeric_format.m_decimal_places = atoi(strDecPlaces.c_str());
+  m_format.m_numeric_format.m_decimal_places = std::stoi(strDecPlaces);
 
   m_format.m_numeric_format.m_currency_symbol = m_entry_currency_symbol->get_entry()->get_text();
 


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