[glom/no_raw_loops2: 4/4] Added and used Utils::transform().
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom/no_raw_loops2: 4/4] Added and used Utils::transform().
- Date: Wed, 10 Feb 2016 14:22:31 +0000 (UTC)
commit 09db5689f2d3e6a257f299f3657e802dbaec0aa1
Author: Murray Cumming <murrayc murrayc com>
Date: Wed Feb 10 15:19:44 2016 +0100
Added and used Utils::transform().
glom/libglom/algorithms_utils.h | 26 ++++++++
glom/libglom/document/document.cc | 65 ++++++++++----------
glom/libglom/privs.cc | 16 +++---
glom/libglom/report_builder.cc | 10 ++-
glom/mode_design/fields/box_db_table_definition.cc | 10 ++--
glom/mode_design/iso_codes.cc | 13 ++--
6 files changed, 85 insertions(+), 55 deletions(-)
---
diff --git a/glom/libglom/algorithms_utils.h b/glom/libglom/algorithms_utils.h
index bcf2883..f398e39 100644
--- a/glom/libglom/algorithms_utils.h
+++ b/glom/libglom/algorithms_utils.h
@@ -102,6 +102,32 @@ copy_if(T_container_input input, T_container_output& output, T_callable f)
f);
}
+template<typename T_container_input, typename T_container_output, typename T_callable>
+void
+transform(T_container_input input, T_container_output& output, T_callable f)
+{
+ std::transform(
+ std::begin(input), std::end(input),
+ std::back_inserter(output),
+ f
+ );
+}
+
+/*
+template<typename T_container_input, typename T_container_output, typename T_callable_transform, typename
T_callable_if>
+void
+transform_if(const T_container_input& input, T_container_output& output,
+ T_callable_transform f, T_callable_if)
+{
+ std::transform(
+ std::begin(input), std::end(input),
+ std::back_inserter(output),
+ f
+ );
+}
+*/
+
+
} //namespace Utils
} //namespace Glom
diff --git a/glom/libglom/document/document.cc b/glom/libglom/document/document.cc
index bcd2b21..3173c90 100644
--- a/glom/libglom/document/document.cc
+++ b/glom/libglom/document/document.cc
@@ -3961,10 +3961,11 @@ Glib::ustring Document::get_name() const
Document::type_list_groups Document::get_groups() const
{
type_list_groups result;
- for(const auto& group_pair : m_groups)
- {
- result.emplace_back(group_pair.second);
- }
+ Utils::transform(m_groups, result,
+ [](const auto& group_pair) {
+ return group_pair.second;
+ }
+ );
return result;
}
@@ -4004,18 +4005,17 @@ void Document::remove_group(const Glib::ustring& group_name)
std::vector<Glib::ustring> Document::get_report_names(const Glib::ustring& table_name) const
{
const auto info = get_table_info(table_name);
- if(info)
- {
- std::vector<Glib::ustring> result;
- for(const auto& report_pair : info->m_reports)
- {
- result.emplace_back(report_pair.second->get_name());
+ if(!info)
+ return std::vector<Glib::ustring>();
+
+ std::vector<Glib::ustring> result;
+ Utils::transform(info->m_reports, result,
+ [](const auto& the_pair) {
+ return the_pair.second->get_name();
}
+ );
- return result;
- }
- else
- return std::vector<Glib::ustring>();
+ return result;
}
void Document::set_report(const Glib::ustring& table_name, const std::shared_ptr<Report>& report)
@@ -4062,18 +4062,17 @@ void Document::remove_report(const Glib::ustring& table_name, const Glib::ustrin
std::vector<Glib::ustring> Document::get_print_layout_names(const Glib::ustring& table_name) const
{
const auto info = get_table_info(table_name);
- if(info)
- {
- std::vector<Glib::ustring> result;
- for(const auto& print_layout_pair : info->m_print_layouts)
- {
- result.emplace_back(print_layout_pair.second->get_name());
+ if(!info)
+ return std::vector<Glib::ustring>();
+
+ std::vector<Glib::ustring> result;
+ Utils::transform(info->m_print_layouts, result,
+ [](const auto& the_pair) {
+ return the_pair.second->get_name();
}
+ );
- return result;
- }
- else
- return std::vector<Glib::ustring>();
+ return result;
}
@@ -4485,10 +4484,11 @@ void Document::fill_translatable_custom_choices(Formatting& formatting, type_lis
if(!formatting.get_has_custom_choices())
return;
- for(const auto& value : formatting.get_choices_custom())
- {
- the_list.emplace_back( pair_translatable_item_and_hint(value, hint) );
- }
+ Utils::transform(formatting.get_choices_custom(), the_list,
+ [&hint](const auto& value) {
+ return pair_translatable_item_and_hint(value, hint);;
+ }
+ );
}
void Document::fill_translatable_layout_items(const std::shared_ptr<LayoutItem_Field>& layout_field,
type_list_translatables& the_list, const Glib::ustring& hint)
@@ -4629,10 +4629,11 @@ guint Document::get_latest_known_document_format_version()
std::vector<Glib::ustring> Document::get_library_module_names() const
{
std::vector<Glib::ustring> result;
- for(const auto& script_pair : m_map_library_scripts)
- {
- result.emplace_back(script_pair.first);
- }
+ Utils::transform(m_map_library_scripts, result,
+ [](const auto& the_pair) {
+ return the_pair.first;
+ }
+ );
return result;
}
diff --git a/glom/libglom/privs.cc b/glom/libglom/privs.cc
index 5d6f002..94ee631 100644
--- a/glom/libglom/privs.cc
+++ b/glom/libglom/privs.cc
@@ -45,15 +45,15 @@ Privs::type_vec_strings Privs::get_database_groups()
builder->select_add_target("pg_group");
auto data_model = DbUtils::query_execute_select(builder);
- if(data_model)
+ if(!data_model)
+ return result;
+
+ const auto rows_count = data_model->get_n_rows();
+ for(int row = 0; row < rows_count; ++row)
{
- const auto rows_count = data_model->get_n_rows();
- for(int row = 0; row < rows_count; ++row)
- {
- const auto value = data_model->get_value_at(0, row);
- const auto name = value.get_string();
- result.emplace_back(name);
- }
+ const auto value = data_model->get_value_at(0, row);
+ const auto name = value.get_string();
+ result.emplace_back(name);
}
return result;
diff --git a/glom/libglom/report_builder.cc b/glom/libglom/report_builder.cc
index 2baa2f5..51467fb 100644
--- a/glom/libglom/report_builder.cc
+++ b/glom/libglom/report_builder.cc
@@ -272,11 +272,13 @@ bool ReportBuilder::report_build_groupby(const FoundSet& found_set_parent, xmlpp
{
auto nodeSecondaryFields = nodeGroupBy->add_child_element("secondary_fields");
+ const auto& items = group_by->get_secondary_fields()->m_list_items;
type_vecLayoutItems itemsToGet;
- for(const auto& item : group_by->get_secondary_fields()->m_list_items)
- {
- itemsToGet.emplace_back( glom_sharedptr_clone(item) );
- }
+ Utils::transform(items, itemsToGet,
+ [](const auto& item) {
+ return glom_sharedptr_clone(item);
+ }
+ );
if(!itemsToGet.empty())
{
diff --git a/glom/mode_design/fields/box_db_table_definition.cc
b/glom/mode_design/fields/box_db_table_definition.cc
index 39e8e38..b8ac16a 100644
--- a/glom/mode_design/fields/box_db_table_definition.cc
+++ b/glom/mode_design/fields/box_db_table_definition.cc
@@ -76,11 +76,11 @@ void Box_DB_Table_Definition::init()
const auto mapFieldTypes = Field::get_usable_type_names();
AddDel::type_vec_strings vecTypes;
- for(const auto& mapFieldType : mapFieldTypes)
- {
- const auto& name = (mapFieldType).second;
- vecTypes.emplace_back(name);
- }
+ Utils::transform(mapFieldTypes, vecTypes,
+ [](const auto& item) {
+ return item.second;
+ }
+ );
m_AddDel.set_column_choices(m_colType, vecTypes);
diff --git a/glom/mode_design/iso_codes.cc b/glom/mode_design/iso_codes.cc
index 10f037c..e42a45b 100644
--- a/glom/mode_design/iso_codes.cc
+++ b/glom/mode_design/iso_codes.cc
@@ -129,12 +129,13 @@ Glib::ustring get_locale_name(const Glib::ustring& locale_id)
//because this is normally what translators translate to.
//For instance, po/ files generally contain po/de.po.
type_list_ids list_ids_simple;
- for(const auto& id : list_ids)
- {
- Glib::ustring id_language, id_country;
- split_locale_id(id, id_language, id_country);
- list_ids_simple.emplace_back(id_language);
- }
+ Utils::transform(list_ids, list_ids_simple,
+ [](const auto& id) {
+ Glib::ustring id_language, id_country;
+ split_locale_id(id, id_language, id_country);
+ return id_language;
+ }
+ );
//Add the non-specific locales:
for(const auto& id : list_ids_simple)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]