Code_TYMPAN  4.2.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>
26 class CleanerSelector : public Selector<T>
27 {
28 public :
31  {
32  }
33 
34  virtual Selector<T>* Copy()
35  {
36  CleanerSelector* newSelector = new CleanerSelector();
37  newSelector->setIsDeletable(this->deletable);
38  return newSelector;
39  }
40 
41  virtual SELECTOR_RESPOND canBeInserted(T* r, unsigned long long& replace)
42  {
43  vector< boost::shared_ptr<Event> > *events = r->getEvents();
44  if (events->size() == 0) { return SELECTOR_ACCEPT; }
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) { return; }
62  virtual bool insertWithTest(T* r)
63  {
64  vector< boost::shared_ptr<Event> > *events = r->getEvents();
65  if (events->size() == 0) { return true; }
66 
67  vector< boost::shared_ptr<Event> >::iterator it = events->begin();
68  while(it != events->end())
69  {
70  if ( (*it)->getType() == NOTHING )
71  {
72  it = events->erase(it);
73  continue;
74  }
75 
76  it++;
77  }
78 
79  return true;
80  }
81 
85  virtual const char* getSelectorName(){
86  return typeid(this).name();
87  }
88 
89 protected:
90 };
91 
92 #endif //CLEANER_SELECTOR
const char * name
Definition: Event.h:29
SELECTOR_RESPOND
Definition: Selector.h:23
bool deletable
Flag to know if the selector may be deleted or not.
Definition: Selector.h:103
virtual bool insertWithTest(T *r)
Select the ray if it respects the criteria of this Selector.
CleanerSelector()
Constructor.
virtual Selector< T > * Copy()
Copy Selector.
virtual const char * getSelectorName()
Return the class type of the selector.
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.
Base class for Selector (used to keep or disable rays according different criterias) ...
Definition: Selector.h:77
Clean DoNothing events from ray events list \ –> After ray validation DoNothing events are no longer...
virtual void insert(T *r)
Select the ray.
void setIsDeletable(bool _isDeletable)
Set deletable flag.
Definition: Selector.h:92