[glom] LayoutItem_Field: Replace predicate_LayoutItem_Field_IsSameField with function.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] LayoutItem_Field: Replace predicate_LayoutItem_Field_IsSameField with function.
- Date: Mon, 20 Jul 2015 21:08:04 +0000 (UTC)
commit 9da6319d0df9b5ee3119ff76826b5dcc06af3fbb
Author: Murray Cumming <murrayc murrayc com>
Date: Mon Jul 20 22:08:24 2015 +0200
LayoutItem_Field: Replace predicate_LayoutItem_Field_IsSameField with function.
Replace with find_if_layout_item_field_is_same_field(), which uses
a C++11 lambda.
.../data_structure/layout/layoutitem_field.h | 58 ++++++++++----------
glom/libglom/utils.cc | 6 ++-
glom/mode_data/box_data_details.cc | 2 +-
3 files changed, 33 insertions(+), 33 deletions(-)
---
diff --git a/glom/libglom/data_structure/layout/layoutitem_field.h
b/glom/libglom/data_structure/layout/layoutitem_field.h
index 54f5aed..cdf42fd 100644
--- a/glom/libglom/data_structure/layout/layoutitem_field.h
+++ b/glom/libglom/data_structure/layout/layoutitem_field.h
@@ -30,36 +30,6 @@
namespace Glom
{
-
-/** A predicate for use with std::find_if() to find a LayoutItem_Field which refers
- * to the same field, without comparing irrelevant stuff such as formatting.
- */
-template<class T_ElementField, class T_Element = T_ElementField>
-class predicate_LayoutItem_Field_IsSameField
-{
-public:
- predicate_LayoutItem_Field_IsSameField(const std::shared_ptr<const T_ElementField>& layout_item)
- {
- m_layout_item = layout_item;
- }
-
- bool operator() (const std::shared_ptr<const T_Element>& element)
- {
- if(!m_layout_item && !element)
- return true;
-
- //Allow this to be used on a container of LayoutItems,
- //as well as just of LayoutItem_Fields.
- const auto element_field = std::dynamic_pointer_cast<const T_ElementField>(element);
- if(!element_field)
- return false;
-
- return m_layout_item && m_layout_item->is_same_field(element_field);
- }
-
-private:
- std::shared_ptr<const T_ElementField> m_layout_item;
-};
/** A LayoutItem that shows the data from a table field.
* The field may be in a known table, or in a to table of a relationship
@@ -189,6 +159,34 @@ private:
std::shared_ptr<CustomTitle> m_title_custom; //translatable.
};
+/**
+ * Find the element in the container which is a LayoutItem_Field which refers
+ * to the same field, without comparing irrelevant stuff such as formatting.
+ * This assumes that the element is a shared_ptr<>.
+ */
+template
+<typename T_Container>
+auto find_if_layout_item_field_is_same_field(T_Container& container, const std::shared_ptr<const
LayoutItem_Field>& layout_item) -> decltype(container.begin())
+{
+ return std::find_if(container.begin(), container.end(),
+ [layout_item](const typename T_Container::value_type& element)
+ {
+ //Assume that element is a shared_ptr<>.
+
+ if(!layout_item && !element)
+ return true;
+
+ //Allow this to be used on a container of LayoutItems,
+ //as well as just of LayoutItem_Fields.
+ const auto element_field = std::dynamic_pointer_cast<const LayoutItem_Field>(element);
+ if(!element_field)
+ return false;
+
+ return layout_item && layout_item->is_same_field(element_field);
+ }
+ );
+}
+
} //namespace Glom
#endif //GLOM_DATASTRUCTURE_LAYOUTITEM_FIELD_H
diff --git a/glom/libglom/utils.cc b/glom/libglom/utils.cc
index 6baf19f..84f1967 100644
--- a/glom/libglom/utils.cc
+++ b/glom/libglom/utils.cc
@@ -1510,7 +1510,8 @@ LayoutGroup::type_list_const_items Utils::get_layout_items_plus_primary_key(cons
pk_layout_item->set_hidden();
pk_layout_item->set_full_field_details(field_primary_key);
- const LayoutGroup::type_list_const_items::const_iterator iterFind = std::find_if(items.begin(),
items.end(), predicate_LayoutItem_Field_IsSameField<LayoutItem_Field, LayoutItem>(pk_layout_item));
+ const LayoutGroup::type_list_const_items::const_iterator iterFind =
+ find_if_layout_item_field_is_same_field(items, pk_layout_item);
if(iterFind != items.end())
return items; //It is already in the list:
@@ -1539,7 +1540,8 @@ LayoutGroup::type_list_items Utils::get_layout_items_plus_primary_key(const Layo
pk_layout_item->set_hidden();
pk_layout_item->set_full_field_details(field_primary_key);
- const LayoutGroup::type_list_items::const_iterator iterFind = std::find_if(items.begin(), items.end(),
predicate_LayoutItem_Field_IsSameField<LayoutItem_Field, LayoutItem>(pk_layout_item));
+ const LayoutGroup::type_list_items::const_iterator iterFind =
+ find_if_layout_item_field_is_same_field(items, pk_layout_item);
if(iterFind != items.end())
return items; //It is already in the list:
diff --git a/glom/mode_data/box_data_details.cc b/glom/mode_data/box_data_details.cc
index 5407a39..6d521a3 100644
--- a/glom/mode_data/box_data_details.cc
+++ b/glom/mode_data/box_data_details.cc
@@ -304,7 +304,7 @@ bool Box_Data_Details::fill_from_database()
//TODO_Performance: Do this for create_layout() only, instead of repeating it for each refresh?:
int index_primary_key = -1; //Arbitrary default.
//g_warning("primary_key name = %s", m_field_primary_key->get_name().c_str());
- const auto iterFind = std::find_if(fieldsToGet.begin(), fieldsToGet.end(),
predicate_LayoutItem_Field_IsSameField<LayoutItem_Field>(layout_item_pk));
+ const auto iterFind = find_if_layout_item_field_is_same_field(fieldsToGet, layout_item_pk);
if(iterFind == fieldsToGet.end())
{
fieldsToGet.push_back(layout_item_pk);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]