1 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 This file is part of CEPS.
4 CEPS is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 CEPS is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with CEPS (see file LICENSE at root of project).
16 If not, see <https://www.gnu.org/licenses/>.
19 Copyright 2019-2024 Inria, Universite de Bordeaux
21 Authors, in alphabetical order:
23 Pierre-Elliott BECUE, Florian CARO, Yves COUDIERE(*), Andjela DAVIDOVIC,
24 Charlie DOUANLA-LONTSI, Marc FUENTES, Mehdi JUHOOR, Michael LEGUEBE(*),
25 Pauline MIGERDITICHAN, Valentin PANNETIER(*), Nejib ZEMZEMI.
26 * : currently active authors
28 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
29 /** @file AbstractSelector.tpp Utility that selects geometric entities with a criterion */
30 #include "geometry/selectors/AbstractSelector.hpp"
32 template <class _Iterator>
33 AbstractSelector<_Iterator>&
34 AbstractSelector<_Iterator>::operator= (const AbstractSelector &that)
36 if (ceps::isDifferentPtr (this, &that))
37 m_selected = that.m_selected;
41 template <class _Iterator>
43 AbstractSelector<_Iterator>::onlyOnBoundary(CepsBool value)
45 m_keepOnBoundary = value;
49 template <class _Iterator>
51 AbstractSelector<_Iterator>::onlyOnThisProc(CepsBool value)
53 m_keepOnThisProc = value;
57 template <class _Iterator>
59 AbstractSelector<_Iterator>::appendSelectedTo (CepsVector<Object>* selected)
61 CEPS_ABORT_IF(ceps::isNullPtr(selected),
62 "Cannot append selection into vector pointed with nullptr"
64 ceps::pushBack (*selected, m_selected.begin(), m_selected.end());
68 template <class _Iterator>
69 CepsVector<typename AbstractSelector<_Iterator>::Object>
70 AbstractSelector<_Iterator>::getSelected() const
75 template <class _Iterator>
77 AbstractSelector<_Iterator>::clearSelection()
83 template <class _Iterator>
85 AbstractSelector<_Iterator>::reset()
87 m_keepOnBoundary = false;
88 m_keepOnThisProc = false;
93 template <class _Iterator>
94 AbstractSelector<_Iterator>::AbstractSelector():
95 m_keepOnBoundary(false),
96 m_keepOnThisProc(false)
100 template <class _Iterator>
102 AbstractSelector<_Iterator>::internalRun (Selector *selector, _Iterator first, _Iterator last)
104 Selector select1 = *selector;
105 if constexpr (std::is_convertible<Object,ceps::HoldsBoundary*>::value)
106 if (m_keepOnBoundary)
108 select1 = [&] (Object obj) {
109 if (obj->isBoundary())
110 return (*selector)(obj);
115 Selector select2 = select1;
116 if constexpr (std::is_convertible<Object,ceps::HoldsProcIds*>::value)
117 if (m_keepOnThisProc)
119 select2 = [&] (Object obj) {
120 if (obj->getOwner() == ceps::getRank())
126 return internalRun2 (&select2,first,last);
129 template <class _Iterator>
131 AbstractSelector<_Iterator>::internalRun2 (Selector *selector, _Iterator first, _Iterator last)
134 m_selected.reserve (std::distance (first, last));
135 for (_Iterator it = first; it != last; ++it)
136 if ((*selector) (*it))
137 m_selected.push_back (*it);