Code_TYMPAN  4.4.0
Industrial site acoustic simulation
Selector.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 SELECTOR_H
17 #define SELECTOR_H
18 
19 #include <vector>
20 #include <algorithm>
21 #include <iostream>
22 
24 {
28 };
29 
31 {
32  LESS = 0,
36  GREATER
37 };
39 {
40  bool operator()(std::vector<unsigned int> list1, std::vector<unsigned int> list2) const
41  {
42  // On compare jusqu'a ce qu'on atteigne le bout du plus petit vecteur
43  size_t minSize =
44  (list1.size() < list2.size()) ? list1.size() : list2.size(); // Ne fonctionnait pas avec std::min
45  for (size_t i = 0; i < minSize; i++)
46  {
47  if (list1.at(i) < list2.at(i))
48  {
49  return true;
50  }
51  else if (list1.at(i) == list2.at(i))
52  {
53  continue;
54  }
55  else
56  {
57  return false;
58  }
59  }
60  // Si les vecteurs ont la meme taille, c'est qu'ils sont egaux
61  if (list1.size() == list2.size())
62  {
63  return false;
64  }
65  // La liste avec la plus grande taille est superieure a l'autre
66  if (list1.size() < list2.size())
67  {
68  return true;
69  }
70  return false;
71  }
72 };
73 
77 template <typename T> class Selector
78 {
79 
80 public:
82  Selector() : deletable(true) {}
84  virtual ~Selector() {}
86  virtual void reset()
87  {
88  return;
89  }
91  virtual Selector* Copy()
92  {
93  Selector* newSelector = new Selector();
94  newSelector->setIsDeletable(deletable);
95  return newSelector;
96  }
98  bool isDeletable()
99  {
100  return deletable;
101  }
103  void setIsDeletable(bool _isDeletable)
104  {
105  deletable = _isDeletable;
106  }
108  virtual SELECTOR_RESPOND canBeInserted(T* r, unsigned long long& replace)
109  {
110  std::cout << "Appel du mauvais selector." << std::endl;
111  return SELECTOR_REJECT;
112  }
114  virtual void insert(T* r)
115  {
116  return;
117  }
119  virtual bool insertWithTest(T* r)
120  {
121  return true;
122  }
123  // Return the class type of the selector as a string
124  virtual const char* getSelectorName()
125  {
126  return typeid(this).name();
127  }
128 
129 protected:
130  bool deletable;
131 };
132 
133 #endif
OPERATOR
Definition: Selector.h:31
@ GREATER
Definition: Selector.h:36
@ EQUAL
Definition: Selector.h:34
@ LESS
Definition: Selector.h:32
@ GREATER_OR_EQUAL
Definition: Selector.h:35
@ LESS_OR_EQUAL
Definition: Selector.h:33
SELECTOR_RESPOND
Definition: Selector.h:24
@ SELECTOR_ACCEPT
Definition: Selector.h:25
@ SELECTOR_REJECT
Definition: Selector.h:26
@ SELECTOR_REPLACE
Definition: Selector.h:27
const char * name
Base class for Selector (used to keep or disable rays according different criterias)
Definition: Selector.h:78
virtual bool insertWithTest(T *r)
Select the ray if it respects the criteria of this Selector.
Definition: Selector.h:119
virtual Selector * Copy()
Copy Selector.
Definition: Selector.h:91
void setIsDeletable(bool _isDeletable)
Set deletable flag.
Definition: Selector.h:103
virtual const char * getSelectorName()
Definition: Selector.h:124
Selector()
Base constructor.
Definition: Selector.h:82
bool deletable
Flag to know if the selector may be deleted or not.
Definition: Selector.h:130
virtual ~Selector()
Destructor.
Definition: Selector.h:84
virtual void reset()
Reset (clear the data) of this Selector.
Definition: Selector.h:86
bool isDeletable()
Return true if the Selector may be deleted.
Definition: Selector.h:98
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.
Definition: Selector.h:108
virtual void insert(T *r)
Select the ray.
Definition: Selector.h:114
bool operator()(std::vector< unsigned int > list1, std::vector< unsigned int > list2) const
Definition: Selector.h:40