Code_TYMPAN  4.2.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,
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  int minSize = ( list1.size() < list2.size() ) ? list1.size() : list2.size() ; // Ne fonctionnait pas avec std::min
44  for (int i = 0; i < minSize; i++)
45  {
46  if (list1.at(i) < list2.at(i))
47  {
48  return true;
49  }
50  else if (list1.at(i) == list2.at(i))
51  {
52  continue;
53  }
54  else
55  {
56  return false;
57  }
58  }
59  //Si les vecteurs ont la meme taille, c'est qu'ils sont egaux
60  if (list1.size() == list2.size())
61  {
62  return false;
63  }
64  //La liste avec la plus grande taille est superieure a l'autre
65  if (list1.size() < list2.size())
66  {
67  return true;
68  }
69  return false;
70  }
71 };
72 
76 template<typename T>
77 class Selector
78 {
79 
80 public:
82  Selector() : deletable(true) { }
84  virtual ~Selector() { }
86  virtual void reset() { return; }
88  virtual Selector* Copy() { Selector* newSelector = new Selector(); newSelector->setIsDeletable(deletable); return newSelector; }
90  bool isDeletable() { return deletable; }
92  void setIsDeletable(bool _isDeletable) { deletable = _isDeletable; }
94  virtual SELECTOR_RESPOND canBeInserted(T* r, unsigned long long& replace) { std::cout << "Appel du mauvais selector." << std::endl; return SELECTOR_REJECT; }
96  virtual void insert(T* r) { return; }
98  virtual bool insertWithTest(T* r) { return true; }
99  // Return the class type of the selector as a string
100  virtual const char* getSelectorName(){ return typeid(this).name();}
101 
102 protected:
103  bool deletable;
104 };
105 
106 #endif
const char * name
virtual ~Selector()
Destructor.
Definition: Selector.h:84
Definition: Selector.h:32
SELECTOR_RESPOND
Definition: Selector.h:23
bool deletable
Flag to know if the selector may be deleted or not.
Definition: Selector.h:103
virtual void reset()
Reset (clear the data) of this Selector.
Definition: Selector.h:86
OPERATOR
Definition: Selector.h:30
virtual const char * getSelectorName()
Definition: Selector.h:100
Base class for Selector (used to keep or disable rays according different criterias) ...
Definition: Selector.h:77
Definition: Selector.h:34
Selector()
Base constructor.
Definition: Selector.h:82
bool operator()(std::vector< unsigned int > list1, std::vector< unsigned int > list2) const
Definition: Selector.h:40
virtual Selector * Copy()
Copy Selector.
Definition: Selector.h:88
virtual bool insertWithTest(T *r)
Select the ray if it respects the criteria of this Selector.
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:94
void setIsDeletable(bool _isDeletable)
Set deletable flag.
Definition: Selector.h:92
bool isDeletable()
Return true if the Selector may be deleted.
Definition: Selector.h:90
virtual void insert(T *r)
Select the ray.
Definition: Selector.h:96