[glom] C++11: More use of auto.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] C++11: More use of auto.
- Date: Fri, 3 Jul 2015 06:36:43 +0000 (UTC)
commit 2e76dce1c0ed3a5d9bcb5c9b85611ad581e01741
Author: Murray Cumming <murrayc murrayc com>
Date: Thu Jul 2 17:33:34 2015 +0200
C++11: More use of auto.
glom/bakery/dialog_offersave.cc | 2 +-
glom/import_csv/csv_parser.cc | 10 ++++----
glom/import_csv/dialog_import_csv.cc | 22 ++++++++++----------
glom/import_csv/dialog_import_csv_progress.cc | 8 +++---
glom/libglom/connectionpool_backends/mysql.cc | 4 +-
.../connectionpool_backends/postgres_self.cc | 2 +-
6 files changed, 24 insertions(+), 24 deletions(-)
---
diff --git a/glom/bakery/dialog_offersave.cc b/glom/bakery/dialog_offersave.cc
index 7cf642a..cbbd2c5 100644
--- a/glom/bakery/dialog_offersave.cc
+++ b/glom/bakery/dialog_offersave.cc
@@ -53,7 +53,7 @@ Dialog_OfferSave::Dialog_OfferSave(const Glib::ustring& file_uri)
set_secondary_text(get_confirmation_message(file_uri));
add_button(_("Discard"), BUTTON_Discard);
- Gtk::Button* cancel_button = add_button(_("_Cancel"), BUTTON_Cancel);
+ auto cancel_button = add_button(_("_Cancel"), BUTTON_Cancel);
add_button(_("_Save"), BUTTON_Save);
// Otherwise Discard has focus initially which seems inconvenient:
diff --git a/glom/import_csv/csv_parser.cc b/glom/import_csv/csv_parser.cc
index 1e35241..58a9f5c 100644
--- a/glom/import_csv/csv_parser.cc
+++ b/glom/import_csv/csv_parser.cc
@@ -290,10 +290,10 @@ bool CsvParser::on_idle_parse()
static const guint CONVERT_BUFFER_SIZE = 1024;
const char* inbuffer = &m_raw[m_input_position];
- char* inbuf = const_cast<char*>(inbuffer);
+ auto inbuf = const_cast<char*>(inbuffer);
g_return_val_if_fail(m_input_position <= m_raw.size(), true);
- gsize inbytes = m_raw.size() - m_input_position;
+ auto inbytes = m_raw.size() - m_input_position;
char outbuffer[CONVERT_BUFFER_SIZE];
char* outbuf = outbuffer;
@@ -473,13 +473,13 @@ void CsvParser::do_line_scanned(const Glib::ustring& line, guint line_number)
return;
m_rows.push_back(CsvParser::type_row_strings());
- type_row_strings& row = m_rows.back();
+ auto& row = m_rows.back();
Glib::ustring field;
//Gtk::TreeModelColumnRecord record;
// Parse first field:
- Glib::ustring::const_iterator line_iter = CsvParser::advance_field(line.begin(), line.end(), field);
+ auto line_iter = CsvParser::advance_field(line.begin(), line.end(), field);
row.push_back(field);
// Parse more fields:
@@ -564,7 +564,7 @@ void CsvParser::on_file_query_info(const Glib::RefPtr<Gio::AsyncResult>& result,
{
try
{
- Glib::RefPtr<Gio::FileInfo> info = source->query_info_finish(result);
+ auto info = source->query_info_finish(result);
if(info)
signal_have_display_name().emit(info->get_display_name());
}
diff --git a/glom/import_csv/dialog_import_csv.cc b/glom/import_csv/dialog_import_csv.cc
index 4dd415c..be38f91 100644
--- a/glom/import_csv/dialog_import_csv.cc
+++ b/glom/import_csv/dialog_import_csv.cc
@@ -115,7 +115,7 @@ Dialog_Import_CSV::Dialog_Import_CSV(BaseObjectType* cobject, const Glib::RefPtr
row[m_encoding_columns.m_col_charset] = encoding.get_charset();
}
- Gtk::CellRendererText* renderer = Gtk::manage(new Gtk::CellRendererText);
+ auto renderer = Gtk::manage(new Gtk::CellRendererText);
m_encoding_combo->set_model(m_encoding_model);
m_encoding_combo->pack_start(*renderer);
m_encoding_combo->set_cell_data_func(*renderer, sigc::bind(sigc::mem_fun(*this,
&Dialog_Import_CSV::encoding_data_func), sigc::ref(*renderer)));
@@ -178,7 +178,7 @@ void Dialog_Import_CSV::import(const Glib::ustring& uri, const Glib::ustring& in
{
clear();
- Document* document = get_document();
+ auto document = get_document();
if(!document)
{
show_error_dialog(_("No Document Available"), _("You need to open a document to import the data into a
table."));
@@ -424,7 +424,7 @@ void Dialog_Import_CSV::begin_parse()
if(m_auto_detect_encoding != -1)
{
const char* encoding_charset = AUTODETECT_ENCODINGS_CHARSETS[m_auto_detect_encoding];
- const Glib::ustring encoding_name = FileEncodings::get_name_of_charset(encoding_charset);
+ const auto encoding_name = FileEncodings::get_name_of_charset(encoding_charset);
m_encoding_info->set_text(Glib::ustring::compose(_("Encoding detected as: %1"),
encoding_display(encoding_name, encoding_charset)));
}
else
@@ -509,8 +509,8 @@ void Dialog_Import_CSV::setup_sample_model(const CsvParser::type_row_strings& ro
m_fields.resize(row.size());
// Start with a column showing the line number.
- Gtk::CellRendererText* text = Gtk::manage(new Gtk::CellRendererText);
- Gtk::TreeViewColumn* col = Gtk::manage(new Gtk::TreeViewColumn(_("Line")));
+ auto text = Gtk::manage(new Gtk::CellRendererText);
+ auto col = Gtk::manage(new Gtk::TreeViewColumn(_("Line")));
col->pack_start(*text, false);
col->set_cell_data_func(*text, sigc::mem_fun(*this, &Dialog_Import_CSV::line_data_func));
m_sample_view->append_column(*col);
@@ -527,7 +527,7 @@ void Dialog_Import_CSV::setup_sample_model(const CsvParser::type_row_strings& ro
Gtk::TreeViewColumn* Dialog_Import_CSV::create_sample_column(const Glib::ustring& title, guint index)
{
Gtk::TreeViewColumn* col = new Gtk::TreeViewColumn(title);
- Gtk::CellRendererCombo* cell = create_sample_cell(index);
+ auto cell = create_sample_cell(index);
col->pack_start(*Gtk::manage(cell), true);
col->set_cell_data_func(*cell, sigc::bind(sigc::mem_fun(*this, &Dialog_Import_CSV::field_data_func),
index));
col->set_sizing(Gtk::TREE_VIEW_COLUMN_AUTOSIZE);
@@ -548,7 +548,7 @@ Gtk::CellRendererCombo* Dialog_Import_CSV::create_sample_cell(guint index)
void Dialog_Import_CSV::line_data_func(Gtk::CellRenderer* renderer, const Gtk::TreeModel::iterator& iter)
{
const int row = (*iter)[m_sample_columns.m_col_row];
- Gtk::CellRendererText* renderer_text = dynamic_cast<Gtk::CellRendererText*>(renderer);
+ auto renderer_text = dynamic_cast<Gtk::CellRendererText*>(renderer);
if(!renderer_text)
throw std::logic_error("CellRenderer is not a CellRendererText in line_data_func");
@@ -561,7 +561,7 @@ void Dialog_Import_CSV::line_data_func(Gtk::CellRenderer* renderer, const Gtk::T
void Dialog_Import_CSV::field_data_func(Gtk::CellRenderer* renderer, const Gtk::TreeModel::iterator& iter,
guint column_number)
{
const int row = (*iter)[m_sample_columns.m_col_row];
- Gtk::CellRendererCombo* renderer_combo = dynamic_cast<Gtk::CellRendererCombo*>(renderer);
+ auto renderer_combo = dynamic_cast<Gtk::CellRendererCombo*>(renderer);
if(!renderer_combo) throw std::logic_error("CellRenderer is not a CellRendererCombo in field_data_func");
Glib::ustring text;
@@ -588,7 +588,7 @@ void Dialog_Import_CSV::field_data_func(Gtk::CellRenderer* renderer, const Gtk::
if(row != -1) // && static_cast<unsigned int>(row) < m_parser->get_rows_count())
{
- const Glib::ustring& orig_text = m_parser->get_data(row, column_number);
+ const auto orig_text = m_parser->get_data(row, column_number);
if(field)
{
@@ -596,7 +596,7 @@ void Dialog_Import_CSV::field_data_func(Gtk::CellRenderer* renderer, const Gtk::
{
/* Exported data is always stored in postgres format */
bool success = false;
- const Gnome::Gda::Value value = field->from_file_format(orig_text, success);
+ const auto value = field->from_file_format(orig_text, success);
if(!success)
text = _("<Import Failure>");
else
@@ -685,7 +685,7 @@ void Dialog_Import_CSV::validate_primary_key()
{
// Allow the import button to be pressed when the value for the primary key
// has been chosen:
- std::shared_ptr<Field> primary_key = get_field_primary_key_for_table(get_target_table_name());
+ auto primary_key = get_field_primary_key_for_table(get_target_table_name());
bool primary_key_selected = false;
if(primary_key && !primary_key->get_auto_increment())
diff --git a/glom/import_csv/dialog_import_csv_progress.cc b/glom/import_csv/dialog_import_csv_progress.cc
index df82dd5..a3b2733 100644
--- a/glom/import_csv/dialog_import_csv_progress.cc
+++ b/glom/import_csv/dialog_import_csv_progress.cc
@@ -188,14 +188,14 @@ bool Dialog_Import_CSV_Progress::on_idle_import()
// We always assume exported data is in standard CSV format, since
// we export it this way.
bool success = false;
- Gnome::Gda::Value value = field->from_file_format(str, success);
+ auto value = field->from_file_format(str, success);
if(success)
{
// Make the value empty if the value is not unique.
if(field->get_unique_key())
{
- std::shared_ptr<LayoutItem_Field> layout_item = std::make_shared<LayoutItem_Field>();
+ auto layout_item = std::make_shared<LayoutItem_Field>();
layout_item->set_full_field_details(field);
if(!get_field_value_is_unique(m_table_name, layout_item, value))
{
@@ -225,8 +225,8 @@ bool Dialog_Import_CSV_Progress::on_idle_import()
else
{
// No auto-increment primary key: Check for uniqueness
- Gnome::Gda::Value primary_key_value = m_current_row_values[m_field_primary_key->get_name()];
- std::shared_ptr<LayoutItem_Field> layout_item = std::make_shared<LayoutItem_Field>();
+ auto primary_key_value = m_current_row_values[m_field_primary_key->get_name()];
+ auto layout_item = std::make_shared<LayoutItem_Field>();
layout_item->set_full_field_details(m_field_primary_key);
if(!get_field_value_is_unique(m_table_name, layout_item, primary_key_value))
diff --git a/glom/libglom/connectionpool_backends/mysql.cc b/glom/libglom/connectionpool_backends/mysql.cc
index 145712a..43dce00 100644
--- a/glom/libglom/connectionpool_backends/mysql.cc
+++ b/glom/libglom/connectionpool_backends/mysql.cc
@@ -482,7 +482,7 @@ std::string MySQL::get_path_to_mysql_executable(const std::string& program, bool
// share/mysqlql which would be nice to separate the mysql stuff
// from the other shared data. We can perhaps still change this later by
// building mysql with another prefix than /local/pgsql.
- gchar* installation_directory = g_win32_get_package_installation_directory_of_module(0);
+ auto installation_directory = g_win32_get_package_installation_directory_of_module(0);
std::string test;
try
@@ -530,7 +530,7 @@ std::string MySQL::get_path_to_mysql_executable(const std::string& program, bool
Glib::ustring MySQL::port_as_string(unsigned int port_num)
{
Glib::ustring result;
- char* cresult = g_strdup_printf("%u", port_num);
+ auto cresult = g_strdup_printf("%u", port_num);
if(cresult)
result = cresult;
g_free(cresult);
diff --git a/glom/libglom/connectionpool_backends/postgres_self.cc
b/glom/libglom/connectionpool_backends/postgres_self.cc
index 6154178..582a06c 100644
--- a/glom/libglom/connectionpool_backends/postgres_self.cc
+++ b/glom/libglom/connectionpool_backends/postgres_self.cc
@@ -436,7 +436,7 @@ void PostgresSelfHosted::show_active_connections()
builder->select_add_field("*", "pg_stat_activity");
builder->select_add_target("pg_stat_activity");
- Glib::RefPtr<Gnome::Gda::Connection> gda_connection = connect(m_saved_database_name, m_saved_username,
m_saved_password);
+ auto gda_connection = connect(m_saved_database_name, m_saved_username, m_saved_password);
if(!gda_connection)
std::cerr << G_STRFUNC << ": connection failed." << std::endl;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]