Code_TYMPAN  4.4.0
Industrial site acoustic simulation
CleanerSelector.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012> <EDF-R&D> <FRANCE>
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  * See the GNU General Public License for more details.
11  * You should have received a copy of the GNU General Public License along
12  * with this program; if not, write to the Free Software Foundation, Inc.,
13  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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  vector<boost::shared_ptr<Event>>* events = r->getEvents();
41  if (events->size() == 0)
42  {
43  return SELECTOR_ACCEPT;
44  }
45 
46  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  vector<boost::shared_ptr<Event>>* events = r->getEvents();
68  if (events->size() == 0)
69  {
70  return true;
71  }
72 
73  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