Code_TYMPAN  4.4.0
Industrial site acoustic simulation
CleanerSelector.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012-2024> <EDF-DTG> <FRANCE>
3  * This file is part of Code_TYMPAN (R).
4  * Code_TYMPAN (R) 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.
8  * Code_TYMPAN (R) is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  * You should have received a copy of the GNU General Public License along
13  * with Code_TYMPAN (R). If not, see <https://www.gnu.org/licenses/>.
14  */
15 
16 #ifndef CLEANER_SELECTOR
17 #define CLEANER_SELECTOR
18 
19 #include "Selector.h"
20 
25 template <typename T> class CleanerSelector : public Selector<T>
26 {
27 public:
30 
31  virtual Selector<T>* Copy()
32  {
33  CleanerSelector* newSelector = new CleanerSelector();
34  newSelector->setIsDeletable(this->deletable);
35  return newSelector;
36  }
37 
38  virtual SELECTOR_RESPOND canBeInserted(T* r, unsigned long long& replace)
39  {
40  std::vector<boost::shared_ptr<Event>>* events = r->getEvents();
41  if (events->size() == 0)
42  {
43  return SELECTOR_ACCEPT;
44  }
45 
46  std::vector<boost::shared_ptr<Event>>::iterator it = events->begin();
47  while (it != events->end())
48  {
49  if ((*it)->getType() == NOTHING)
50  {
51  it = events->erase(it);
52  continue;
53  }
54 
55  it++;
56  }
57 
58  return SELECTOR_REPLACE;
59  }
60 
61  virtual void insert(T* r)
62  {
63  return;
64  }
65  virtual bool insertWithTest(T* r)
66  {
67  std::vector<boost::shared_ptr<Event>>* events = r->getEvents();
68  if (events->size() == 0)
69  {
70  return true;
71  }
72 
73  std::vector<boost::shared_ptr<Event>>::iterator it = events->begin();
74  while (it != events->end())
75  {
76  if ((*it)->getType() == NOTHING)
77  {
78  it = events->erase(it);
79  continue;
80  }
81 
82  it++;
83  }
84 
85  return true;
86  }
87 
91  virtual const char* getSelectorName()
92  {
93  return typeid(this).name();
94  }
95 
96 protected:
97 };
98 
99 #endif // CLEANER_SELECTOR
@ NOTHING
Definition: Event.h:28
SELECTOR_RESPOND
Definition: Selector.h:24
@ SELECTOR_ACCEPT
Definition: Selector.h:25
@ SELECTOR_REPLACE
Definition: Selector.h:27
const char * name
Clean DoNothing events from ray events list \ --> After ray validation DoNothing events are no longer...
virtual Selector< T > * Copy()
Copy Selector.
virtual void insert(T *r)
Select the ray.
virtual SELECTOR_RESPOND canBeInserted(T *r, unsigned long long &replace)
Check if the ray respects the criteria of this Selector and return a SELECTOR_RESPOND.
virtual const char * getSelectorName()
Return the class type of the selector.
virtual bool insertWithTest(T *r)
Select the ray if it respects the criteria of this Selector.
CleanerSelector()
Constructor.
Base class for Selector (used to keep or disable rays according different criterias)
Definition: Selector.h:78
void setIsDeletable(bool _isDeletable)
Set deletable flag.
Definition: Selector.h:103
bool deletable
Flag to know if the selector may be deleted or not.
Definition: Selector.h:130