Commit e5519f1c authored by Murray Cumming's avatar Murray Cumming
Browse files

C++11: Use for range loops.

This changes most for loops that used iterator (not const_iterator).
parent b2c57958
......@@ -1233,10 +1233,8 @@ void AppWindow::update_table_sensitive_ui()
if(m_pFrame)
has_table = !m_pFrame->get_shown_table_name().empty();
for(type_listActions::iterator iter = m_listTableSensitiveActions.begin(); iter != m_listTableSensitiveActions.end(); ++iter)
{
Glib::RefPtr<Gio::SimpleAction> action = *iter;
for(const auto& action : m_listTableSensitiveActions)
{
bool sensitive = has_table;
const bool is_developer_item =
......@@ -1253,9 +1251,8 @@ void AppWindow::update_userlevel_ui()
AppState::userlevels userlevel = get_userlevel();
//Disable/Enable developer actions:
for(type_listActions::iterator iter = m_listDeveloperActions.begin(); iter != m_listDeveloperActions.end(); ++iter)
for(const auto& action : m_listDeveloperActions)
{
Glib::RefPtr<Gio::SimpleAction> action = *iter;
action->set_enabled( userlevel == AppState::USERLEVEL_DEVELOPER );
}
......@@ -1837,7 +1834,7 @@ void AppWindow::add_developer_action(const Glib::RefPtr<Gio::SimpleAction>& refA
void AppWindow::remove_developer_action(const Glib::RefPtr<Gio::SimpleAction>& refAction)
{
for(type_listActions::iterator iter = m_listDeveloperActions.begin(); iter != m_listDeveloperActions.end(); ++iter)
for(auto iter = m_listDeveloperActions.begin(); iter != m_listDeveloperActions.end(); ++iter)
{
if(*iter == refAction)
{
......
......@@ -597,16 +597,15 @@ std::shared_ptr<Field> Base_DB::get_field_primary_key_for_table(const Glib::ustr
//TODO_Performance: Cache this result?
Document::type_vec_fields fields = document->get_table_fields(table_name);
//std::cout << "debug: " << G_STRFUNC << ": table=" << table_name << ", fields count=" << fields.size() << std::endl;
for(Document::type_vec_fields::iterator iter = fields.begin(); iter != fields.end(); ++iter)
for(const auto& field : fields)
{
std::shared_ptr<Field> field = *iter;
if(!field)
continue;
//std::cout << " field=" << field->get_name() << std::endl;
if(field->get_primary_key())
return *iter;
return field;
}
}
......@@ -620,10 +619,8 @@ void Base_DB::get_table_fields_to_show_for_sequence_add_group(const Glib::ustrin
//g_warning("Box_Data::get_table_fields_to_show_for_sequence_add_group(): table_name=%s, all_db_fields.size()=%d, group->name=%s", table_name.c_str(), all_db_fields.size(), group->get_name().c_str());
LayoutGroup::type_list_items items = group->get_items();
for(LayoutGroup::type_list_items::iterator iterItems = items.begin(); iterItems != items.end(); ++iterItems)
for(const auto& item : items)
{
std::shared_ptr<LayoutItem> item = *iterItems;
std::shared_ptr<LayoutItem_Field> item_field = std::dynamic_pointer_cast<LayoutItem_Field>(item);
if(item_field)
{
......
......@@ -182,16 +182,16 @@ void Box_Reports::save_to_document()
std::vector<Glib::ustring> listReports = get_document()->get_report_names(m_table_name);
bool modified = false;
for(Gtk::TreeModel::iterator iter = m_AddDel.get_model()->children().begin(); iter != m_AddDel.get_model()->children().end(); ++iter)
for(const auto& item : m_AddDel.get_model()->children())
{
const auto report_name = m_AddDel.get_value(iter, m_colReportName);
const auto report_name = m_AddDel.get_value(item, m_colReportName);
if(!report_name.empty() && std::find(listReports.begin(), listReports.end(), report_name) == listReports.end())
{
std::shared_ptr<Report> report(new Report());
report->set_name(report_name);
report->set_title( m_AddDel.get_value(iter, m_colTitle) , AppWindow::get_current_locale()); //TODO: Translations: Store the original in the TreeView.
report->set_title( m_AddDel.get_value(item, m_colTitle) , AppWindow::get_current_locale()); //TODO: Translations: Store the original in the TreeView.
get_document()->set_report(m_table_name, report);
modified = true;
......
......@@ -301,8 +301,8 @@ Dialog_ExistingOrNew::~Dialog_ExistingOrNew()
if(!m_iter_existing_network_dummy.get())
{
const auto children = m_iter_existing_network->children();
for(Gtk::TreeModel::iterator iter = children.begin(); iter != children.end(); ++ iter)
epc_service_info_unref((*iter)[m_existing_columns.m_col_service_info]);
for(const auto& item : children)
epc_service_info_unref(item[m_existing_columns.m_col_service_info]);
}
#endif
......@@ -739,7 +739,7 @@ void Dialog_ExistingOrNew::on_service_removed(const Glib::ustring& name, const G
{
// Find the entry with the given name
const auto children = m_iter_existing_network->children();
for(Gtk::TreeModel::iterator iter = children.begin(); iter != children.end(); ++ iter)
for(auto iter = children.begin(); iter != children.end(); ++ iter)
{
if((*iter)[m_existing_columns.m_col_service_name] == name)
{
......
......@@ -206,10 +206,8 @@ int main(int argc, char* argv[])
}
const auto original_locale_id = document.get_translation_original_locale();
for(std::vector<Glib::ustring>::const_iterator iter = locales.begin();
iter != locales.end(); ++iter)
for(const auto& locale_id : locales)
{
const Glib::ustring locale_id = *iter;
if(locale_id == original_locale_id)
continue;
......
......@@ -643,7 +643,7 @@ void Dialog_Import_CSV::on_field_edited(const Glib::ustring& path, const Glib::u
// Lookup field indicated by new_text
const Gtk::TreeNodeChildren& children = m_field_model->children();
for(Gtk::TreeModel::iterator field_iter = children.begin(); field_iter != children.end(); ++ field_iter)
for(auto field_iter = children.begin(); field_iter != children.end(); ++ field_iter)
{
if( (*field_iter)[m_field_columns.m_col_field_name] == new_text)
{
......@@ -660,7 +660,7 @@ void Dialog_Import_CSV::on_field_edited(const Glib::ustring& path, const Glib::u
// Create a TreeModel::Path with initial index 0. We need a TreeModel::Path for the row_changed() call
Gtk::TreeModel::Path path("0");
for(Gtk::TreeModel::iterator sample_iter = sample_children.begin(); sample_iter != sample_children.end(); ++ sample_iter)
for(auto sample_iter = sample_children.begin(); sample_iter != sample_children.end(); ++ sample_iter)
{
if(sample_iter != iter)
m_sample_model->row_changed(path, sample_iter);
......@@ -696,9 +696,9 @@ void Dialog_Import_CSV::validate_primary_key()
primary_key_selected = false;
if(!m_parser->get_rows_empty())
{
for(type_vec_fields::iterator iter = m_fields.begin(); iter != m_fields.end(); ++ iter)
for(const auto& field : m_fields)
{
if(*iter == primary_key)
if(field == primary_key) //TODO: Is this just comparing shared_ptr?
{
primary_key_selected = true;
break;
......
......@@ -580,15 +580,14 @@ bool ConnectionPool::handle_error_cerr_only()
if(!list_errors.empty())
{
Glib::ustring error_details;
for(type_list_errors::iterator iter = list_errors.begin(); iter != list_errors.end(); ++iter)
for(const auto& event : list_errors)
{
Glib::RefPtr<Gnome::Gda::ConnectionEvent> event = *iter;
if(event && (event->get_event_type() == Gnome::Gda::CONNECTION_EVENT_ERROR))
{
if(!error_details.empty())
error_details += '\n'; //Add newline after each error.
error_details += (*iter)->get_description();
error_details += event->get_description();
std::cerr << G_STRFUNC << ": Internal error (Database): " << error_details << std::endl;
}
}
......
......@@ -797,11 +797,11 @@ Field::glom_field_type Field::get_type_for_ui_name(const Glib::ustring& glom_typ
{
glom_field_type result = TYPE_INVALID;
for(type_map_type_names::iterator iter = m_map_type_names_ui.begin(); iter != m_map_type_names_ui.end(); ++iter)
for(const auto& the_pair : m_map_type_names_ui)
{
if(iter->second == glom_type)
if(the_pair.second == glom_type)
{
result = iter->first;
result = the_pair.first;
break;
}
}
......
......@@ -301,9 +301,8 @@ void LayoutGroup::remove_field(const Glib::ustring& parent_table_name, const Gli
void LayoutGroup::change_related_field_item_name(const Glib::ustring& table_name, const Glib::ustring& field_name, const Glib::ustring& field_name_new)
{
//Look at each item:
for(LayoutGroup::type_list_items::iterator iterItem = m_list_items.begin(); iterItem != m_list_items.end(); ++iterItem)
for(const auto& item : m_list_items)
{
auto item = *iterItem;
auto field_item = std::dynamic_pointer_cast<LayoutItem_Field>(item);
if(field_item)
{
......@@ -332,9 +331,8 @@ void LayoutGroup::change_related_field_item_name(const Glib::ustring& table_name
void LayoutGroup::change_field_item_name(const Glib::ustring& table_name, const Glib::ustring& field_name, const Glib::ustring& field_name_new)
{
//Look at each item:
for(LayoutGroup::type_list_items::iterator iterItem = m_list_items.begin(); iterItem != m_list_items.end(); ++iterItem)
for(const auto& item : m_list_items)
{
auto item = *iterItem;
std::shared_ptr<LayoutItem_Field> field_item =
std::dynamic_pointer_cast<LayoutItem_Field>(item);
......@@ -382,7 +380,7 @@ void LayoutGroup::change_field_item_name(const Glib::ustring& table_name, const
void LayoutGroup::change_relationship_name(const Glib::ustring& table_name, const Glib::ustring& name, const Glib::ustring& name_new)
{
//Look at each item:
for(LayoutGroup::type_list_items::iterator iterItem = m_list_items.begin(); iterItem != m_list_items.end(); ++iterItem)
for(const auto& item : m_list_items)
{
auto field_item = dynamic_cast<LayoutItem_Field*>(*iterItem);
if(field_item)
......
......@@ -87,9 +87,8 @@ void LayoutItem_Portal::change_related_field_item_name(const Glib::ustring& tabl
void LayoutItem_Portal::change_field_item_name(const Glib::ustring& table_name, const Glib::ustring& field_name, const Glib::ustring& field_name_new)
{
//Look at each item:
for(LayoutGroup::type_list_items::iterator iterItem = m_list_items.begin(); iterItem != m_list_items.end(); ++iterItem)
for(const auto& item : m_list_items)
{
auto item = *iterItem;
auto field_item = std::dynamic_pointer_cast<LayoutItem_Field>(item);
if(field_item)
{
......
......@@ -978,9 +978,8 @@ type_vec_fields get_fields_for_table(const Document* document, const Glib::ustri
//Look at each field in the database:
/*
for(type_vec_fields::iterator iter = fieldsDocument.begin(); iter != fieldsDocument.end(); ++iter)
for(const auto& field : fieldsDocument)
{
std::shared_ptr<Field> field = *iter;
const auto field_name = field->get_name();
//Get the field info from the database:
......@@ -1011,7 +1010,7 @@ type_vec_fields get_fields_for_table(const Document* document, const Glib::ustri
}
//Add any fields that are in the database, but not in the document:
for(type_vec_fields::iterator iter = fieldsDatabase.begin(); iter != fieldsDatabase.end(); ++iter)
for(const auto& item : fieldsDatabase)
{
const auto field_name = (*iter)->get_name();
......
......@@ -177,9 +177,8 @@ void Document_XML::add_indenting_white_space_to_node(xmlpp::Node* node, const Gl
//Remove any previous indenting:
{
auto list = node->get_children();
for(xmlpp::Node::NodeList::iterator iter = list.begin(); iter != list.end(); ++iter)
for(const auto& child : list)
{
auto child = *iter;
if(!child)
continue;
......@@ -204,9 +203,8 @@ void Document_XML::add_indenting_white_space_to_node(xmlpp::Node* node, const Gl
bool had_children = false;
auto node_as_element = dynamic_cast<xmlpp::Element*>(node);
auto list = node_as_element->get_children();
for(xmlpp::Node::NodeList::iterator iter = list.begin(); iter != list.end(); ++iter)
for(const auto& child : list)
{
auto child = *iter;
if(!child)
continue;
......
......@@ -69,9 +69,8 @@ public:
View<T_Document>::set_document(pDocument);
//Change the document in the child views.
for(typename type_vec_views::iterator iter = m_vecViews.begin(); iter != m_vecViews.end(); ++iter)
for(const auto& pView : m_vecViews)
{
type_view* pView = *iter;
if(pView)
pView->set_document(pDocument);
}
......@@ -80,9 +79,8 @@ public:
virtual void load_from_document()
{
//Delegate to the child views:
for(typename type_vec_views::iterator iter = m_vecViews.begin(); iter != m_vecViews.end(); ++iter)
for(const auto& pView : m_vecViews)
{
type_view* pView = *iter;
if(pView)
pView->load_from_document();
}
......@@ -91,9 +89,8 @@ public:
virtual void save_to_document()
{
//Delegate to the child views:
for(typename type_vec_views::iterator iter = m_vecViews.begin(); iter != m_vecViews.end(); ++iter)
for(const auto& pView : m_vecViews)
{
type_view* pView = *iter;
if(pView)
pView->save_to_document();
}
......
This diff is collapsed.
......@@ -49,10 +49,8 @@ bool ReportBuilder::report_build_headerfooter(const FoundSet& found_set, xmlpp::
//Add child parts:
type_vecLayoutItems itemsToGet;
for(LayoutGroup::type_list_items::iterator iterChildren = group->m_list_items.begin(); iterChildren != group->m_list_items.end(); ++iterChildren)
for(const auto& item : group->m_list_items)
{
std::shared_ptr<LayoutItem> item = *iterChildren;
std::shared_ptr<LayoutItem_Text> item_text = std::dynamic_pointer_cast<LayoutItem_Text>(item);
if(item_text)
{
......@@ -113,10 +111,8 @@ bool ReportBuilder::report_build_summary(const FoundSet& found_set, xmlpp::Eleme
//Get fields
type_vecLayoutItems itemsToGet;
for(LayoutGroup::type_list_items::iterator iterChildren = summary->m_list_items.begin(); iterChildren != summary->m_list_items.end(); ++iterChildren)
for(const auto& item : summary->m_list_items)
{
std::shared_ptr<LayoutItem> item = *iterChildren;
std::shared_ptr<LayoutItem_GroupBy> pGroupBy = std::dynamic_pointer_cast<LayoutItem_GroupBy>(item);
if(pGroupBy)
{
......@@ -171,10 +167,8 @@ bool ReportBuilder::report_build_groupby_children(const FoundSet& found_set, xml
{
//Get data and add child rows:
type_vecLayoutItems itemsToGet;
for(LayoutGroup::type_list_items::iterator iterChildren = group_by->m_list_items.begin(); iterChildren != group_by->m_list_items.end(); ++iterChildren)
for(const auto& item : group_by->m_list_items)
{
std::shared_ptr<LayoutItem> item = *iterChildren;
std::shared_ptr<LayoutItem_GroupBy> pGroupBy = std::dynamic_pointer_cast<LayoutItem_GroupBy>(item);
if(pGroupBy)
{
......@@ -283,9 +277,8 @@ bool ReportBuilder::report_build_groupby(const FoundSet& found_set_parent, xmlpp
xmlpp::Element* nodeSecondaryFields = nodeGroupBy->add_child("secondary_fields");
type_vecLayoutItems itemsToGet;
for(LayoutGroup::type_list_items::iterator iterChildren = group_by->get_secondary_fields()->m_list_items.begin(); iterChildren != group_by->get_secondary_fields()->m_list_items.end(); ++iterChildren)
for(const auto& item : group_by->get_secondary_fields()->m_list_items)
{
std::shared_ptr<LayoutItem> item = *iterChildren;
itemsToGet.push_back( glom_sharedptr_clone(item) );
}
......@@ -322,10 +315,8 @@ bool ReportBuilder::report_build_groupby(const FoundSet& found_set_parent, xmlpp
bool ReportBuilder::report_build_records_get_fields(const FoundSet& found_set, const std::shared_ptr<LayoutGroup>& group, type_vecLayoutFields& items)
{
for(LayoutGroup::type_list_items::iterator iterChildren = group->m_list_items.begin(); iterChildren != group->m_list_items.end(); ++iterChildren)
for(const auto& item : group->m_list_items)
{
std::shared_ptr<LayoutItem> item = *iterChildren;
std::shared_ptr<LayoutItem_VerticalGroup> pVerticalGroup = std::dynamic_pointer_cast<LayoutItem_VerticalGroup>(item);
if(pVerticalGroup)
{
......@@ -549,10 +540,8 @@ bool ReportBuilder::report_build_records_vertical_group(const FoundSet& found_se
{
xmlpp::Element* nodeGroupVertical = parentNode.add_child(group->get_report_part_id());
for(LayoutGroup::type_list_items::iterator iterChildren = group->m_list_items.begin(); iterChildren != group->m_list_items.end(); ++iterChildren)
for(const auto& item : group->m_list_items)
{
std::shared_ptr<LayoutItem> item = *iterChildren;
std::shared_ptr<LayoutItem_VerticalGroup> pVerticalGroup = std::dynamic_pointer_cast<LayoutItem_VerticalGroup>(item);
if(pVerticalGroup)
{
......
......@@ -211,16 +211,16 @@ bool write_translations_to_po_file(Document* document, const Glib::ustring& po_f
Glib::ustring data;
Document::type_list_translatables list_layout_items = document->get_translatable_items();
for(Document::type_list_translatables::iterator iter = list_layout_items.begin(); iter != list_layout_items.end(); ++iter)
for(const auto& the_pair : list_layout_items)
{
std::shared_ptr<TranslatableItem> item = iter->first;
std::shared_ptr<TranslatableItem> item = the_pair.first;
if(!item)
continue;
if(item->get_title_original().empty())
continue;
const Glib::ustring hint = iter->second;
const Glib::ustring hint = the_pair.second;
// Add "context" comments, to uniquely identify similar strings, used in different places,
// and to provide a hint for translators.
......@@ -301,13 +301,13 @@ bool import_translations_from_po_file(Document* document, const Glib::ustring& p
const auto msgcontext = Glib::convert_const_gchar_ptr_to_ustring( po_message_msgctxt(msg) );
//Find the matching item in the list:
for(Document::type_list_translatables::iterator iter = list_layout_items.begin(); iter != list_layout_items.end(); ++iter)
for(const auto& the_pair : list_layout_items)
{
std::shared_ptr<TranslatableItem> item = iter->first;
std::shared_ptr<TranslatableItem> item = the_pair.first;
if(!item)
continue;
const Glib::ustring hint = iter->second;
const Glib::ustring hint = the_pair.second;
if( (item->get_title_original() == msgid) &&
(get_po_context_for_item(item, hint) == msgcontext) ) // This is not efficient, but it should be reliable.
......
......@@ -103,9 +103,9 @@ Glib::ustring Utils::trim_whitespace(const Glib::ustring& text)
//Find non-whitespace from front:
Glib::ustring::size_type posFront = Glib::ustring::npos;
Glib::ustring::size_type pos = 0;
for(Glib::ustring::iterator iter = result.begin(); iter != result.end(); ++iter)
for(const auto& item : result)
{
if(!Glib::Unicode::isspace(*iter))
if(!Glib::Unicode::isspace(item))
{
posFront = pos;
break;
......
......@@ -72,9 +72,9 @@ xmlpp::Element* get_node_child_named(const xmlpp::Element* node, const Glib::ust
//We check all of them, instead of just the first, until we find one,
//because get_children() returns, for instance, TextNodes (which are not Elements) for "text",
//as well as Elements with the name "text".
for(xmlpp::Node::NodeList::iterator iter = list.begin(); iter != list.end(); ++iter)
for(const auto& item : list)
{
nodeResult = dynamic_cast<xmlpp::Element*>(*iter);
nodeResult = dynamic_cast<xmlpp::Element*>(item);
if(nodeResult)
return nodeResult;
}
......
......@@ -264,9 +264,9 @@ Document::type_list_layout_groups Box_Data::get_data_layout_groups(const Glib::u
const auto table_privs = Privs::get_current_privs(m_table_name);
//Fill in the field information for the fields mentioned in the layout:
for(Document::type_list_layout_groups::iterator iterGroups = layout_groups.begin(); iterGroups != layout_groups.end(); ++iterGroups)
for(const auto& item : layout_groups)
{
fill_layout_group_field_info(*iterGroups, table_privs);
fill_layout_group_field_info(item, table_privs);
//std::cout << "debug: Box_Data::get_data_layout_groups: " << std::endl;
//*iterGroups->debug();
......@@ -285,10 +285,9 @@ void Box_Data::fill_layout_group_field_info(const std::shared_ptr<LayoutGroup>&
const auto document = get_document();
LayoutGroup::type_list_items items = group->get_items();
for(LayoutGroup::type_list_items::iterator iter = items.begin(); iter != items.end(); ++iter)
for(const auto& item : items)
{
std::shared_ptr<LayoutItem> item = *iter;
std::shared_ptr<LayoutItem_Field> item_field = std::dynamic_pointer_cast<LayoutItem_Field>(item);
auto item_field = std::dynamic_pointer_cast<LayoutItem_Field>(item);
if(item_field) //If is a field rather than some other layout item
{
......
......@@ -249,12 +249,11 @@ bool Box_Data_Calendar_Related::fill_from_database()
void Box_Data_Calendar_Related::clear_cached_database_values()
{
for(type_map_values::iterator iter = m_map_values.begin(); iter != m_map_values.end(); ++iter)
for(const auto& the_pair : m_map_values)
{
type_list_vectors vec = iter->second;
for(type_list_vectors::iterator iter = vec.begin(); iter != vec.end(); ++iter)
type_list_vectors vec = the_pair.second;
for(const auto& pValues : vec)
{
type_vector_values* pValues = *iter;
delete pValues;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment