Commit 12453ef5 authored by Murray Cumming's avatar Murray Cumming
Browse files

C++11: range-based for loops: Don't get the container separately.

Don't use an intermediate variable to get the container.
Range-based for loops only evaluate the second part once so this is
fine. This simplifies code by not making us think about whether the
variable is used later in the method.

This is only useful with containers that don't need to be
const-iterated. We can const_cast<> the container, but that is
lengthy and involves mentining the type.
parent 3a672465
......@@ -1499,7 +1499,7 @@ bool AppWindow::recreate_database_from_example(bool& user_cancelled)
ShowProgressMessage progress_message(_("Creating Glom database from example file."));
//Create a database, based on the information in the current document:
Document* pDocument = static_cast<Document*>(get_document());
const auto pDocument = static_cast<Document*>(get_document());
if(!pDocument)
return false;
......@@ -1617,7 +1617,7 @@ bool AppWindow::recreate_database_from_example(bool& user_cancelled)
return false;
//Create each table:
Document::type_listTableInfo tables = pDocument->get_tables();
const auto tables = pDocument->get_tables();
for(const auto& table_info : tables)
{
//Create SQL to describe all fields in this table:
......@@ -1872,15 +1872,14 @@ void AppWindow::fill_menu_tables()
menu->remove(0);
}
Document* document = dynamic_cast<Document*>(get_document());
const auto document = dynamic_cast<Document*>(get_document());
if(!document)
{
std::cerr << G_STRFUNC << ": document is null." << std::endl;
return;
}
const auto tables = document->get_tables();
for(const auto& table_info : tables)
for(const auto& table_info : document->get_tables())
{
if(!table_info->get_hidden())
{
......@@ -1927,17 +1926,16 @@ void AppWindow::fill_menu_reports(const Glib::ustring& table_name)
m_refNavReportsActionGroup = Gio::SimpleActionGroup::create();
Document* document = dynamic_cast<Document*>(get_document());
const auto document = dynamic_cast<Document*>(get_document());
if(!document)
{
std::cerr << G_STRFUNC << ": document is null." << std::endl;
return;
}
const auto reports = document->get_report_names(table_name);
for(const auto& item : reports)
for(const auto& item : document->get_report_names(table_name))
{
std::shared_ptr<Report> report = document->get_report(table_name, item);
const auto report = document->get_report(table_name, item);
if(report)
{
const auto report_name = report->get_name();
......@@ -1968,11 +1966,9 @@ void AppWindow::enable_menu_print_layouts_details(bool enable)
//Enable/Disable each action in the group:
//TODO: Suggest a simpler get_actions() method?
typedef std::vector<Glib::ustring> type_vec_action_names;
type_vec_action_names actions = m_refNavPrintLayoutsActionGroup->list_actions();
for(const auto& name : actions)
for(const auto& name : m_refNavPrintLayoutsActionGroup->list_actions())
{
Glib::RefPtr<Gio::SimpleAction> action =
auto action =
Glib::RefPtr<Gio::SimpleAction>::cast_dynamic(m_refNavPrintLayoutsActionGroup->lookup_action(name));
if(action)
action->set_enabled(enable);
......@@ -2017,14 +2013,12 @@ void AppWindow::fill_menu_print_layouts(const Glib::ustring& table_name)
return;
}
const auto tables = document->get_print_layout_names(table_name);
// TODO_clientonly: Should this be available in client only mode? We need to
// depend on goocanvas in client only mode then:
#ifndef GLOM_ENABLE_CLIENT_ONLY
for(const auto& item : tables)
for(const auto& item : document->get_print_layout_names(table_name))
{
std::shared_ptr<PrintLayout> layout = document->get_print_layout(table_name, item);
const auto layout = document->get_print_layout(table_name, item);
if(layout)
{
const auto name = layout->get_name();
......@@ -2085,8 +2079,7 @@ void AppWindow::on_menu_file_save_as_example()
document->set_is_example_file();
//Save all data from all tables into the document:
Document::type_listTableInfo list_table_info = document->get_tables();
for(const auto& item : list_table_info)
for(const auto& item : document->get_tables())
{
const auto table_name = item->get_name();
......
......@@ -595,9 +595,8 @@ std::shared_ptr<Field> Base_DB::get_field_primary_key_for_table(const Glib::ustr
if(document)
{
//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(const auto& field : fields)
for(const auto& field : document->get_table_fields(table_name))
{
if(!field)
continue;
......@@ -618,8 +617,7 @@ 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(const auto& item : items)
for(const auto& item : group->get_items())
{
std::shared_ptr<LayoutItem_Field> item_field = std::dynamic_pointer_cast<LayoutItem_Field>(item);
if(item_field)
......@@ -854,8 +852,7 @@ void Base_DB::calculate_field(const LayoutFieldInRecord& field_in_record)
//Calculate dependencies first:
//TODO: Prevent unncessary recalculations?
const auto fields_needed = get_calculation_fields(field_in_record.m_table_name, field_in_record.m_field);
for(const auto& field_item_needed : fields_needed)
for(const auto& field_item_needed : get_calculation_fields(field_in_record.m_table_name, field_in_record.m_field))
{
if(field_item_needed->get_has_relationship_name())
{
......@@ -1144,9 +1141,7 @@ void Base_DB::do_calculations(const LayoutFieldInRecord& field_changed, bool fir
//Recalculate fields that are triggered by a change of this field's value, not including calculations that these calculations use.
type_list_const_field_items calculated_fields = get_calculated_fields(field_changed.m_table_name, field_changed.m_field);
//std::cout << " debug: calculated_field.size()=" << calculated_fields.size() << std::endl;
for(const auto& field : calculated_fields)
for(const auto& field : get_calculated_fields(field_changed.m_table_name, field_changed.m_field))
{
if(field)
{
......@@ -1176,10 +1171,9 @@ Base_DB::type_list_const_field_items Base_DB::get_calculated_fields(const Glib::
//Look at each field in the table, and get lists of what fields trigger their calculations,
//so we can see if our field is in any of those lists:
const auto fields = document->get_table_fields(table_name); //TODO_Performance: Cache this?
//Examine all fields, not just the the shown fields.
//TODO: How do we trigger relcalculation of related fields if necessary?
for(const auto& field_to_examine : fields)
for(const auto& field_to_examine : document->get_table_fields(table_name)) //TODO_Performance: Cache this?
{
std::shared_ptr<LayoutItem_Field> layoutitem_field_to_examine = std::make_shared<LayoutItem_Field>();
layoutitem_field_to_examine->set_full_field_details(field_to_examine);
......@@ -1257,18 +1251,17 @@ Base_DB::type_list_const_field_items Base_DB::get_calculation_fields(const Glib:
}
//Check the use of related records too:
const auto relationships_used = field->get_calculation_relationships();
for(const auto& item : relationships_used)
for(const auto& item : field->get_calculation_relationships())
{
std::shared_ptr<Relationship> relationship = document->get_relationship(table_name, item);
auto relationship = document->get_relationship(table_name, item);
if(relationship)
{
//If the field uses this relationship then it should be triggered by a change in the key that specifies which record the relationship points to:
const auto field_from_name = relationship->get_from_field();
std::shared_ptr<Field> field_from = document->get_field(table_name, field_from_name);
auto field_from = document->get_field(table_name, field_from_name);
if(field_from)
{
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_from);
result.push_back(layout_item);
......@@ -1289,11 +1282,10 @@ void Base_DB::do_lookups(const LayoutFieldInRecord& field_in_record, const Gtk::
//Get values for lookup fields, if this field triggers those relationships:
//TODO_performance: There is a LOT of iterating and copying here.
const auto strFieldName = field_in_record.m_field->get_name();
const auto lookups = document->get_lookup_fields(field_in_record.m_table_name, strFieldName);
//std::cout << "debug: " << G_STRFUNC << ": lookups size=" << lookups.size() << std::endl;
for(const auto& the_pair : lookups)
for(const auto& the_pair : document->get_lookup_fields(field_in_record.m_table_name, strFieldName))
{
std::shared_ptr<const LayoutItem_Field> layout_item = the_pair.first;
const auto& layout_item = the_pair.first;
//std::cout << "debug: " << G_STRFUNC << ": item=" << layout_item->get_name() << std::endl;
......
......@@ -103,10 +103,9 @@ bool Box_Reports::fill_from_database()
Document* document = get_document();
if(document)
{
listTableReports = document->get_report_names(m_table_name);
for(const auto& item : listTableReports)
for(const auto& item : document->get_report_names(m_table_name))
{
std::shared_ptr<Report> report = document->get_report(m_table_name, item);
auto report = document->get_report(m_table_name, item);
if(report)
{
auto row = m_AddDel.add_item(report->get_name());
......
......@@ -168,8 +168,7 @@ Dialog_ExistingOrNew::Dialog_ExistingOrNew(BaseObjectType* cobject, const Glib::
#endif
// Add recently used files
typedef std::vector< Glib::RefPtr<Gtk::RecentInfo> > type_vec_infos;
type_vec_infos infos = Gtk::RecentManager::get_default()->get_items();
const auto infos = Gtk::RecentManager::get_default()->get_items();
for(const auto& info : infos)
{
if(info->get_mime_type() == "application/x-glom")
......
......@@ -103,8 +103,7 @@ Dialog_Import_CSV::Dialog_Import_CSV(BaseObjectType* cobject, const Glib::RefPtr
// Separator:
m_encoding_model->append();
const auto list_encodings = FileEncodings::get_list_of_encodings();
for(const auto& encoding : list_encodings)
for(const auto& encoding : FileEncodings::get_list_of_encodings())
{
if(encoding.get_name().empty())
continue;
......
......@@ -574,8 +574,7 @@ bool ConnectionPool::handle_error_cerr_only()
{
Glib::RefPtr<Gnome::Gda::Connection> gda_connection = sharedconnection->get_gda_connection();
typedef std::vector< Glib::RefPtr<Gnome::Gda::ConnectionEvent> > type_list_errors;
type_list_errors list_errors = gda_connection->get_events();
const auto list_errors = gda_connection->get_events();
if(!list_errors.empty())
{
......
......@@ -278,7 +278,7 @@ bool recreate_database_from_document(Document* document, const std::function<voi
progress();
//Create each table:
Document::type_listTableInfo tables = document->get_tables();
const auto tables = document->get_tables();
for(const auto& table_info : tables)
{
//Create SQL to describe all fields in this table:
......@@ -620,9 +620,7 @@ bool add_standard_groups(Document* document)
priv_devs.m_create = true;
priv_devs.m_delete = true;
const auto table_list = document->get_tables(true /* including system prefs */);
for(const auto& table_info : table_list)
for(const auto& table_info : document->get_tables(true /* including system prefs */))
{
if(table_info)
{
......@@ -662,11 +660,9 @@ bool add_groups_from_document(const Document* document)
//Get the list of groups from the database server:
const auto database_groups = Privs::get_database_groups();
//Get the list of groups from the document:
const auto document_groups = document->get_groups();
//Add each group if it doesn't exist yet:
for(const auto& group : document_groups)
//Get the list of groups from the document
//and add each group if it doesn't exist yet:
for(const auto& group : document->get_groups())
{
const auto name = group.get_name();
//std::cout << G_STRFUNC << ": DEBUG: group=" << name << std::endl;
......
......@@ -176,8 +176,7 @@ void Document_XML::add_indenting_white_space_to_node(xmlpp::Node* node, const Gl
//Remove any previous indenting:
{
auto list = node->get_children();
for(const auto& child : list)
for(const auto& child : node->get_children())
{
if(!child)
continue;
......@@ -202,8 +201,7 @@ void Document_XML::add_indenting_white_space_to_node(xmlpp::Node* node, const Gl
//Add indenting text items:
bool had_children = false;
auto node_as_element = dynamic_cast<xmlpp::Element*>(node);
auto list = node_as_element->get_children();
for(const auto& child : list)
for(const auto& child : node_as_element->get_children())
{
if(!child)
continue;
......
This diff is collapsed.
......@@ -33,8 +33,7 @@ void print_layout_group(const std::shared_ptr<Glom::LayoutGroup>& layout_group,
return;
//Look at each child item:
const auto items = layout_group->get_items();
for(const auto& layout_item : items)
for(const auto& layout_item : layout_group->get_items())
{
if(!layout_item)
continue;
......@@ -105,14 +104,12 @@ int main()
// Look at each table:
const auto table_names = document.get_table_names();
for(const auto& table_name : table_names)
for(const auto& table_name : document.get_table_names())
{
std::cout << "Table: " << table_name << std::endl;
// List the fields for this table:
Glom::Document::type_vec_fields fields = document.get_table_fields(table_name);
for(const auto& field : fields)
for(const auto& field : document.get_table_fields(table_name))
{
if(!field)
continue;
......@@ -126,8 +123,7 @@ int main()
}
// List the relationships for this table:
Glom::Document::type_vec_relationships relationships = document.get_relationships(table_name);
for(const auto& relationship : relationships)
for(const auto& relationship : document.get_relationships(table_name))
{
if(!relationship)
continue;
......
......@@ -478,10 +478,10 @@ Privileges Privs::get_current_privs(const Glib::ustring& table_name)
if(sharedconnection && sharedconnection->get_gda_connection()->supports_feature(Gnome::Gda::CONNECTION_FEATURE_USERS))
{
//Get the "true" rights for any groups that the user is in:
type_vec_strings groups = get_groups_of_user(current_user);
const type_vec_strings groups = get_groups_of_user(current_user);
for(const auto& group : groups)
{
Privileges privs = get_table_privileges(group, table_name);
const auto privs = get_table_privileges(group, table_name);
if(privs.m_view)
result.m_view = true;
......
......@@ -87,9 +87,8 @@ boost::python::object PyGlomRecord::get_related()
m_related = boost::python::object(new PyGlomRelated()); //TODO_NotSure
//Fill it:
Document::type_vec_relationships vecRelationships = m_document->get_relationships(m_table_name);
PyGlomRelated::type_map_relationships map_relationships;
for(const auto& relationship : vecRelationships)
for(const auto& relationship : m_document->get_relationships(m_table_name))
{
if(relationship)
map_relationships[relationship->get_name()] = relationship;
......
......@@ -210,8 +210,7 @@ bool write_translations_to_po_file(Document* document, const Glib::ustring& po_f
//do that manually anyway.
Glib::ustring data;
Document::type_list_translatables list_layout_items = document->get_translatable_items();
for(const auto& the_pair : list_layout_items)
for(const auto& the_pair : document->get_translatable_items())
{
std::shared_ptr<TranslatableItem> item = the_pair.first;
if(!item)
......@@ -259,7 +258,7 @@ bool import_translations_from_po_file(Document* document, const Glib::ustring& p
return false;
}
Document::type_list_translatables list_layout_items = document->get_translatable_items();
const auto list_layout_items = document->get_translatable_items();
if(list_layout_items.empty())
return false;
......@@ -303,11 +302,11 @@ bool import_translations_from_po_file(Document* document, const Glib::ustring& p
//Find the matching item in the list:
for(const auto& the_pair : list_layout_items)
{
std::shared_ptr<TranslatableItem> item = the_pair.first;
const auto& item = the_pair.first;
if(!item)
continue;
const Glib::ustring hint = the_pair.second;
const auto& 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.
......
......@@ -567,10 +567,9 @@ Utils::type_list_values_with_second Utils::get_choice_values(const Document* doc
if(layout_choice_extra)
{
const LayoutGroup::type_list_const_items extra_fields = layout_choice_extra->get_items_recursive();
for(const auto& item : extra_fields)
for(const auto& item : layout_choice_extra->get_items_recursive())
{
const std::shared_ptr<const LayoutItem_Field> item_field = std::dynamic_pointer_cast<const LayoutItem_Field>(item);
const auto& item_field = std::dynamic_pointer_cast<const LayoutItem_Field>(item);
if(item_field)
fields.push_back(item_field); //TODO: Don't ignore other usable items such as static text.
}
......
......@@ -185,14 +185,12 @@ void Box_Data_List::on_adddel_user_reordered_columns()
Document* pDoc = dynamic_cast<Document*>(get_document());
if(pDoc)
{
std::shared_ptr<LayoutGroup> group = std::make_shared<LayoutGroup>();
auto group = std::make_shared<LayoutGroup>();
group->set_name("toplevel");
AddDel::type_vec_strings vec_field_names = m_AddDel.get_columns_order();
for(const auto& field_name : vec_field_names)
for(const auto& field_name : m_AddDel.get_columns_order())
{
std::shared_ptr<LayoutItem_Field> layout_item = std::make_shared<LayoutItem_Field>();
auto layout_item = std::make_shared<LayoutItem_Field>();
layout_item->set_name(field_name);
group->add_item(layout_item);
}
......
......@@ -208,8 +208,7 @@ Gtk::CellRenderer* create_cell(const std::shared_ptr<const LayoutItem>& layout_i
{
//set_choices_fixed() needs this, for the numeric layout:
//pCellRendererCombo->set_layout_item(get_layout_item()->clone(), table_name); //TODO_Performance: We only need this for the numerical format.
const auto list_values = item_field->get_formatting_used().get_choices_custom();
for(const auto& value : list_values)
for(const auto& value : item_field->get_formatting_used().get_choices_custom())
{
if(!value)
continue;
......
......@@ -238,7 +238,7 @@ void ComboGlom::set_value(const Gnome::Gda::Value& value)
m_old_value = value;
Glib::RefPtr<Gtk::TreeModel> model = get_choices_model();
auto model = get_choices_model();
if(!model)
{
std::cerr << G_STRFUNC << ": model is null." << std::endl;
......
......@@ -57,7 +57,7 @@ void ComboAsRadioButtons::set_choices_with_second(const type_list_values_with_se
//Clear existing buttons:
for(const auto& the_pair : m_map_buttons)
{
Gtk::RadioButton* button = the_pair.second;
auto button = the_pair.second;
delete button;
}
m_map_buttons.clear();
......@@ -83,9 +83,9 @@ void ComboAsRadioButtons::set_choices_with_second(const type_list_values_with_se
if(layout_choice_first)
{
const auto value_first = Conversions::get_text_for_gda_value(layout_choice_first->get_glom_type(), the_pair.first, layout_choice_first->get_formatting_used().m_numeric_format);
Glib::ustring title = value_first;
auto title = value_first;
const type_list_values extra_values = the_pair.second;
const auto extra_values = the_pair.second;
if(layout_choice_extra && !extra_values.empty())
{
type_list_values::const_iterator iterValues = extra_values.begin();
......
......@@ -355,7 +355,7 @@ void FlowTableWithFields::add_layout_notebook(const std::shared_ptr<LayoutItem_N
for(const auto& item : notebook->m_list_items)
{
std::shared_ptr<LayoutGroup> group = std::dynamic_pointer_cast<LayoutGroup>(item);
auto group = std::dynamic_pointer_cast<LayoutGroup>(item);
if(group)
{
#ifndef GLOM_ENABLE_CLIENT_ONLY
......@@ -413,8 +413,7 @@ void FlowTableWithFields::add_layout_notebook(const std::shared_ptr<LayoutItem_N
notebook_widget->append_page(*event_box, *tab_label);
//Add child items:
LayoutGroup::type_list_items child_items = group->get_items();
for(const auto& child_item : child_items)
for(const auto& child_item : group->get_items())
{
if(child_item)
{
......@@ -673,10 +672,9 @@ void FlowTableWithFields::set_field_value(const std::shared_ptr<const LayoutItem
void FlowTableWithFields::set_field_value(const std::shared_ptr<const LayoutItem_Field>& field, const Gnome::Gda::Value& value, bool set_specified_field_layout)
{
//Set widgets which should show the value of this field:
type_list_widgets list_widgets = get_field(field, set_specified_field_layout);
for(const auto& item : list_widgets)
for(const auto& item : get_field(field, set_specified_field_layout))
{
DataWidget* datawidget = dynamic_cast<DataWidget*>(item);
auto datawidget = dynamic_cast<DataWidget*>(item);
if(datawidget)
{
datawidget->set_value(value);
......@@ -684,8 +682,7 @@ void FlowTableWithFields::set_field_value(const std::shared_ptr<const LayoutItem
}
//Refresh portal widgets which should show the related records for relationships that use this field:
type_portals list_portals = get_portals(field /* from_key field name */);
for(const auto& portal : list_portals)
for(const auto& portal : get_portals(field /* from_key field name */))
{
if(portal)
{
......@@ -695,8 +692,7 @@ void FlowTableWithFields::set_field_value(const std::shared_ptr<const LayoutItem
}
//Refresh choices widgets which should show the related records for relationships that use this field:
type_choice_widgets list_choice_widgets = get_choice_widgets(field /* from_key field name */);
for(const auto& widget : list_choice_widgets)
for(const auto& widget : get_choice_widgets(field /* from_key field name */))
{
if(widget)
{
......@@ -732,8 +728,7 @@ Gnome::Gda::Value FlowTableWithFields::get_field_value(const std::shared_ptr<con
void FlowTableWithFields::set_field_editable(const std::shared_ptr<const LayoutItem_Field>& field, bool editable)
{
type_list_widgets list_widgets = get_field(field, true);
for(const auto& item : list_widgets)
for(const auto& item : get_field(field, true))
{
DataWidget* datawidget = dynamic_cast<DataWidget*>(item);
if(datawidget)
......@@ -745,8 +740,7 @@ void FlowTableWithFields::set_field_editable(const std::shared_ptr<const LayoutI
void FlowTableWithFields::update_choices(const std::shared_ptr<const LayoutItem_Field>& field)
{
type_list_widgets list_widgets = get_field(field, true);
for(const auto& item : list_widgets)
for(const auto& item : get_field(field, true))
{
DataWidget* datawidget = dynamic_cast<DataWidget*>(item);
if(!datawidget)
......
......@@ -77,12 +77,12 @@ bool Box_DB_Table_Relationships::fill_from_database()
bool result = Box_DB_Table::fill_from_database();
Document* document = get_document();
const Document* document = get_document();
if(!document)
return false;
//Get relationships from the document:
Document::type_vec_relationships vecRelationships = document->get_relationships(m_table_name);
const auto vecRelationships = document->get_relationships(m_table_name);
m_AddDel.remove_all();
......
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