[glom] C++11: More range-based for loops.



commit 448fc7b2708298016a8a1c7efcb308e447f5dc50
Author: Murray Cumming <murrayc murrayc com>
Date:   Mon Feb 8 18:25:10 2016 +0100

    C++11: More range-based for loops.
    
    With help from clang-modernize-3.7.

 glom/application.cc                                |    3 +-
 glom/base_db.cc                                    |    5 ++-
 glom/import_csv/dialog_import_csv.cc               |    6 ++--
 glom/mode_data/db_adddel/db_adddel.cc              |   25 ++++++++------------
 glom/mode_data/flowtablewithfields.cc              |    7 ++---
 glom/mode_design/fields/box_db_table_definition.cc |    6 ++--
 .../print_layouts/window_print_layout_edit.cc      |    9 ++----
 glom/print_layout/canvas_print_layout.cc           |   14 ++++------
 glom/utils_ui.cc                                   |   19 +++++---------
 9 files changed, 39 insertions(+), 55 deletions(-)
---
diff --git a/glom/application.cc b/glom/application.cc
index 09f8d68..d72df54 100644
--- a/glom/application.cc
+++ b/glom/application.cc
@@ -117,9 +117,8 @@ void Application::on_open(const Gio::Application::type_vec_files& files,
   // The application has been asked to open some files,
   // so let's open a new window for each one.
   //std::cout << "debug: files.size()=" << files.size() << std::endl;
-  for(guint i = 0; i < files.size(); i++)
+  for(const auto& file : files)
   {
-    auto file = files[i];
     if(!file)
     {
       std::cerr << G_STRFUNC << ": file is null." << std::endl;
diff --git a/glom/base_db.cc b/glom/base_db.cc
index 427b4f9..e1ddd49 100644
--- a/glom/base_db.cc
+++ b/glom/base_db.cc
@@ -202,9 +202,10 @@ Base_DB::type_vec_strings Base_DB::util_vecStrings_from_Fields(const type_vec_fi
   //Get vector of field names, suitable for a combo box:
 
   type_vec_strings vecNames;
-  for(type_vec_fields::size_type i = 0; i < fields.size(); ++i)
+  for(const auto& field : fields)
   {
-    vecNames.emplace_back(fields[i]->get_name());
+    if(field)
+      vecNames.emplace_back(field->get_name());
   }
 
   return vecNames;
diff --git a/glom/import_csv/dialog_import_csv.cc b/glom/import_csv/dialog_import_csv.cc
index 78383b4..2e4aab5 100644
--- a/glom/import_csv/dialog_import_csv.cc
+++ b/glom/import_csv/dialog_import_csv.cc
@@ -643,11 +643,11 @@ void Dialog_Import_CSV::on_field_edited(const Glib::ustring& path, const Glib::u
 
   // Lookup field indicated by new_text
   const auto children = m_field_model->children();
-  for(auto field_iter = children.begin(); field_iter != children.end(); ++ field_iter)
+  for(const auto & elem : children)
   {
-    if( (*field_iter)[m_field_columns.m_col_field_name] == new_text)
+    if( (elem)[m_field_columns.m_col_field_name] == new_text)
     {
-      std::shared_ptr<Field> field = (*field_iter)[m_field_columns.m_col_field];
+      std::shared_ptr<Field> field = (elem)[m_field_columns.m_col_field];
       // Check whether another column is already using that field
       auto vec_field_iter = Utils::find(m_fields, field);
       // Reset the old column since two different columns cannot be imported into the same field
diff --git a/glom/mode_data/db_adddel/db_adddel.cc b/glom/mode_data/db_adddel/db_adddel.cc
index 7953d14..2d5b234 100644
--- a/glom/mode_data/db_adddel/db_adddel.cc
+++ b/glom/mode_data/db_adddel/db_adddel.cc
@@ -516,14 +516,14 @@ guint DbAddDel::get_fixed_cell_height()
     m_fixed_cell_height = height_default;
 
     //Look at each column:
-    for(auto iter = m_column_items.begin(); iter != m_column_items.end(); ++iter)
+    for(const auto& item : m_column_items)
     {
       Glib::ustring font_name;
 
-      auto item_withformatting = std::dynamic_pointer_cast<const LayoutItem_WithFormatting>(*iter);
+      const auto item_withformatting = std::dynamic_pointer_cast<const LayoutItem_WithFormatting>(item);
       if(item_withformatting)
       {
-         const auto formatting = item_withformatting->get_formatting_used();
+         const auto& formatting = item_withformatting->get_formatting_used();
          font_name = formatting.get_text_format_font();
       }
 
@@ -691,9 +691,8 @@ void DbAddDel::construct_specified_columns()
   const auto has_expandable_column = get_column_to_expand(column_to_expand);
   //std::cout << "DEBUG: column_to_expand=" << column_to_expand  << ", has=" << has_expandable_column << 
std::endl;
 
-  for(auto iter = m_column_items.begin(); iter != m_column_items.end(); ++iter)
+  for(const auto& layout_item : m_column_items)
   {
-    const auto layout_item = m_column_items[model_column_index]; //TODO: Inefficient.
     if(layout_item) //column_info.m_visible)
     {
       no_columns_used = false;
@@ -1609,18 +1608,14 @@ void DbAddDel::on_treeview_columns_changed()
     //Get the new column order, and save it in m_vecColumnIDs:
     m_vecColumnIDs.clear();
 
-    typedef std::vector<Gtk::TreeViewColumn*> type_vecViewColumns;
-    type_vecViewColumns vecViewColumns = m_TreeView.get_columns();
-
-    for(auto iter = vecViewColumns.begin(); iter != vecViewColumns.end(); ++iter)
+    for(const auto& vecViewColumn : m_TreeView.get_columns())
     {
-      auto pViewColumn = dynamic_cast<DbTreeViewColumnGlom*>(*iter);
-      if(pViewColumn)
-      {
-        const auto column_id = pViewColumn->get_column_id();
-        m_vecColumnIDs.emplace_back(column_id);
+      const auto view_column = dynamic_cast<DbTreeViewColumnGlom*>(vecViewColumn);
+      if(!view_column)
+        continue;
 
-      }
+      const auto column_id = view_column->get_column_id();
+      m_vecColumnIDs.emplace_back(column_id);
     }
 
     //Tell other code that something has changed, so the new column order can be serialized.
diff --git a/glom/mode_data/flowtablewithfields.cc b/glom/mode_data/flowtablewithfields.cc
index 3cf67e3..aa36fc0 100644
--- a/glom/mode_data/flowtablewithfields.cc
+++ b/glom/mode_data/flowtablewithfields.cc
@@ -716,11 +716,10 @@ void FlowTableWithFields::set_other_field_value(const std::shared_ptr<const Layo
 
 Gnome::Gda::Value FlowTableWithFields::get_field_value(const std::shared_ptr<const LayoutItem_Field>& field) 
const
 {
-  type_list_const_widgets list_widgets = get_field(field, true);
-  for(auto iter = list_widgets.begin();
-    iter != list_widgets.end(); ++iter)
+  const type_list_const_widgets list_widgets = get_field(field, true);
+  for(const auto& list_widget : list_widgets)
   {
-    const auto datawidget = dynamic_cast<const DataWidget*>(*iter);
+    const auto datawidget = dynamic_cast<const DataWidget*>(list_widget);
     if(!datawidget)
       continue;
 
diff --git a/glom/mode_design/fields/box_db_table_definition.cc 
b/glom/mode_design/fields/box_db_table_definition.cc
index a5b805f..82891f4 100644
--- a/glom/mode_design/fields/box_db_table_definition.cc
+++ b/glom/mode_design/fields/box_db_table_definition.cc
@@ -74,11 +74,11 @@ void Box_DB_Table_Definition::init()
 
   //Set Type choices:
 
-  Field::type_map_type_names mapFieldTypes = Field::get_usable_type_names();
+  const auto mapFieldTypes = Field::get_usable_type_names();
   AddDel::type_vec_strings vecTypes;
-  for(auto iter = mapFieldTypes.begin(); iter != mapFieldTypes.end();++iter)
+  for(const auto& mapFieldType : mapFieldTypes)
   {
-    const Glib::ustring& name = (*iter).second;
+    const auto& name = (mapFieldType).second;
     vecTypes.emplace_back(name);
   }
 
diff --git a/glom/mode_design/print_layouts/window_print_layout_edit.cc 
b/glom/mode_design/print_layouts/window_print_layout_edit.cc
index 684778b..47c91ff 100644
--- a/glom/mode_design/print_layouts/window_print_layout_edit.cc
+++ b/glom/mode_design/print_layouts/window_print_layout_edit.cc
@@ -1393,8 +1393,6 @@ void Window_PrintLayout_Edit::get_dimensions_of_multiple_selected_items(double&
 
 void Window_PrintLayout_Edit::on_canvas_selection_changed()
 {
-  Canvas_PrintLayout::type_vec_items items = m_canvas.get_selected_items();
-
   //Forget about any previously selected items:
   m_layout_items_selected.clear();
   for(auto item : m_connections_items_selected_moved)
@@ -1403,11 +1401,10 @@ void Window_PrintLayout_Edit::on_canvas_selection_changed()
   }
   m_connections_items_selected_moved.clear();
   
-
-  for(auto iter = items.begin();
-    iter != items.end(); ++iter)
+  const auto items = m_canvas.get_selected_items();
+  for(const auto& base_item : items)
   {
-    auto item = Glib::RefPtr<CanvasLayoutItem>::cast_dynamic(*iter);
+    auto item = Glib::RefPtr<CanvasLayoutItem>::cast_dynamic(base_item);
     if(!item)
       continue;
 
diff --git a/glom/print_layout/canvas_print_layout.cc b/glom/print_layout/canvas_print_layout.cc
index 212abb0..cfebe39 100644
--- a/glom/print_layout/canvas_print_layout.cc
+++ b/glom/print_layout/canvas_print_layout.cc
@@ -94,18 +94,16 @@ void Canvas_PrintLayout::set_print_layout(const Glib::ustring& table_name, const
   //Add the rule lines:
   remove_rules();
 
-  const PrintLayout::type_vec_doubles h_rules = print_layout->get_horizontal_rules();
-  for(auto iter = h_rules.begin();
-    iter != h_rules.end(); ++iter)
+  const auto h_rules = print_layout->get_horizontal_rules();
+  for(const auto& h_rule : h_rules)
   {
-    add_horizontal_rule(*iter);
+    add_horizontal_rule(h_rule);
   }
 
-  const PrintLayout::type_vec_doubles v_rules = print_layout->get_vertical_rules();
-  for(auto iter = v_rules.begin();
-    iter != v_rules.end(); ++iter)
+  const auto v_rules = print_layout->get_vertical_rules();
+  for(const auto& v_rule : v_rules)
   {
-    add_vertical_rule(*iter);
+    add_vertical_rule(v_rule);
   }
 
   //TODO: This needs a number, but that is decided in WindowPrintLayoutEdit: set_grid_gap( 
print_layout->get_show_grid() );
diff --git a/glom/utils_ui.cc b/glom/utils_ui.cc
index bd915d6..89ad327 100644
--- a/glom/utils_ui.cc
+++ b/glom/utils_ui.cc
@@ -583,27 +583,22 @@ void UiUtils::treeview_delete_all_columns(Gtk::TreeView* treeview)
   //Deleting them explicitly is safer and clearer. murrayc.
 
   //Remove all View columns:
-  typedef std::vector<Gtk::TreeView::Column*> type_vec_columns;
-  type_vec_columns vecViewColumns (treeview->get_columns());
-
-  for (type_vec_columns::iterator iter (vecViewColumns.begin ()), columns_end (vecViewColumns.end ());
-    iter != columns_end;
-    ++iter)
+  auto vecViewColumns = treeview->get_columns();
+  for (auto& view_column : vecViewColumns)
   {
-    Gtk::TreeView::Column* pViewColumn (*iter);
-    if(!pViewColumn)
+    if(!view_column)
       continue;
 
     GtkTreeViewColumn* weak_ptr = nullptr;
-    g_object_add_weak_pointer (G_OBJECT (pViewColumn->gobj()), (gpointer*)&weak_ptr);
+    g_object_add_weak_pointer (G_OBJECT (view_column->gobj()), (gpointer*)&weak_ptr);
 
     //Keep the object alive, instead of letting gtk_tree_view_remove_column() delete it by reducing its 
reference to 0,
     //so we can explicitly delete it.
     //This feels safer, considering some strange crashes I've seen when using 
Gtk::TreeView::remove_all_columns(),
     //though that might have been just because we didn't reset m_treeviewcolumn_button. murrayc.
-    pViewColumn->reference();
-    treeview->remove_column(*pViewColumn);
-    delete pViewColumn; //This should cause it to be removed.
+    view_column->reference();
+    treeview->remove_column(*view_column);
+    delete view_column; //This should cause it to be removed.
 
     if(weak_ptr)
     {


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