[glom] Add and use copy_with_cloned_items().
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] Add and use copy_with_cloned_items().
- Date: Wed, 10 Feb 2016 17:12:24 +0000 (UTC)
commit a89b442fcdea0e9f26e8db28679a3de625b10305
Author: Murray Cumming <murrayc murrayc com>
Date: Wed Feb 10 15:53:32 2016 +0100
Add and use copy_with_cloned_items().
glom/libglom/data_structure/layout/layoutgroup.cc | 12 ++----------
glom/libglom/report_builder.cc | 7 ++-----
glom/libglom/sharedptr.h | 16 ++++++++++++++++
3 files changed, 20 insertions(+), 15 deletions(-)
---
diff --git a/glom/libglom/data_structure/layout/layoutgroup.cc
b/glom/libglom/data_structure/layout/layoutgroup.cc
index 2407a98..78a8b47 100644
--- a/glom/libglom/data_structure/layout/layoutgroup.cc
+++ b/glom/libglom/data_structure/layout/layoutgroup.cc
@@ -40,11 +40,7 @@ LayoutGroup::LayoutGroup(const LayoutGroup& src)
m_border_width(src.m_border_width)
{
//Deep copy of the items map:
- for(const auto& item : src.m_list_items)
- {
- if(item)
- m_list_items.emplace_back( glom_sharedptr_clone(item) );
- }
+ m_list_items = copy_with_cloned_items(src.m_list_items);
}
LayoutGroup::~LayoutGroup()
@@ -77,11 +73,7 @@ LayoutGroup& LayoutGroup::operator=(const LayoutGroup& src)
//Deep copy of the items map:
remove_all_items();
- for(const auto& item : src.m_list_items)
- {
- if(item)
- m_list_items.emplace_back( glom_sharedptr_clone(item) );
- }
+ m_list_items = copy_with_cloned_items(src.m_list_items);
}
return *this;
diff --git a/glom/libglom/report_builder.cc b/glom/libglom/report_builder.cc
index 2baa2f5..42af551 100644
--- a/glom/libglom/report_builder.cc
+++ b/glom/libglom/report_builder.cc
@@ -272,11 +272,8 @@ bool ReportBuilder::report_build_groupby(const FoundSet& found_set_parent, xmlpp
{
auto nodeSecondaryFields = nodeGroupBy->add_child_element("secondary_fields");
- type_vecLayoutItems itemsToGet;
- for(const auto& item : group_by->get_secondary_fields()->m_list_items)
- {
- itemsToGet.emplace_back( glom_sharedptr_clone(item) );
- }
+ type_vecLayoutItems itemsToGet =
+ copy_with_cloned_items(group_by->get_secondary_fields()->m_list_items);
if(!itemsToGet.empty())
{
diff --git a/glom/libglom/sharedptr.h b/glom/libglom/sharedptr.h
index 29b688e..0f00408 100644
--- a/glom/libglom/sharedptr.h
+++ b/glom/libglom/sharedptr.h
@@ -54,6 +54,22 @@ std::shared_ptr<T_obj> glom_sharedptr_clone(const std::shared_ptr<const T_obj>&
return std::shared_ptr<T_obj>();
}
+template <class T_container>
+decltype(auto) copy_with_cloned_items(T_container src)
+{
+ T_container result;
+ result.reserve(src.size());
+
+ for (const auto& item : src) {
+ if(!item)
+ continue;
+
+ result.emplace_back(glom_sharedptr_clone(item));
+ }
+
+ return result;
+}
+
} //namespace Glom
#endif //GLOM_SHAREDPTR_H
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]