1 |
//####//------------------------------------------------------------ |
2 |
//####//------------------------------------------------------------ |
3 |
//####// MAGiC |
4 |
//####// Jean Christophe Cuilliere et Vincent FRANCOIS |
5 |
//####// Departement de Genie Mecanique - UQTR |
6 |
//####//------------------------------------------------------------ |
7 |
//####// MAGIC est un projet de recherche de l equipe ERICCA |
8 |
//####// du departement de genie mecanique de l Universite du Quebec a Trois Rivieres |
9 |
//####// http://www.uqtr.ca/ericca |
10 |
//####// http://www.uqtr.ca/ |
11 |
//####//------------------------------------------------------------ |
12 |
//####//------------------------------------------------------------ |
13 |
//####// |
14 |
//####// tpl_set.h |
15 |
//####// |
16 |
//####//------------------------------------------------------------ |
17 |
//####//------------------------------------------------------------ |
18 |
//####// COPYRIGHT 2000-2024 |
19 |
//####// jeu 13 jun 2024 11:54:00 EDT |
20 |
//####//------------------------------------------------------------ |
21 |
//####//------------------------------------------------------------ |
22 |
#ifndef TPL_SETH
|
23 |
#define TPL_SETH
|
24 |
|
25 |
#include <stdio.h>
|
26 |
|
27 |
#ifdef BORLANDCPP
|
28 |
#include <set.h>
|
29 |
#else
|
30 |
#include <set>
|
31 |
#endif
|
32 |
|
33 |
template <class X>
|
34 |
class TPL_SET
|
35 |
{
|
36 |
public:
|
37 |
typedef typename std::set< X >::iterator ITERATEUR;
|
38 |
|
39 |
TPL_SET() {};
|
40 |
TPL_SET(TPL_SET< X > & src){lst_X = src.lst_X;};
|
41 |
~TPL_SET() {};
|
42 |
|
43 |
/*
|
44 |
syntaxe :
|
45 |
TPL_SET<MG_ELEMENT_MAILLAGE*> liste;
|
46 |
TPL_SET<MG_ELEMENT_MAILLAGE*>::ITERATEUR it;
|
47 |
MG_ELEMENT_MAILLAGE* element;
|
48 |
for (element = liste.get_premier(it); element; element = liste.get_suivant(it) )
|
49 |
{
|
50 |
printf("element id = %d", element->get_id());
|
51 |
}
|
52 |
*/
|
53 |
|
54 |
|
55 |
void ajouter(X x)
|
56 |
{
|
57 |
lst_X.insert(x);
|
58 |
};
|
59 |
|
60 |
|
61 |
|
62 |
void supprimer(X x)
|
63 |
{
|
64 |
ITERATEUR j=lst_X.find(x);
|
65 |
if (j==lst_X.end())
|
66 |
{
|
67 |
return;
|
68 |
}
|
69 |
lst_X.erase(j);
|
70 |
};
|
71 |
|
72 |
bool contient(X x)
|
73 |
{
|
74 |
return (lst_X.find(x) != lst_X.end());
|
75 |
}
|
76 |
|
77 |
|
78 |
int get_nb(void)
|
79 |
{
|
80 |
return lst_X.size();
|
81 |
};
|
82 |
|
83 |
|
84 |
X get(int num)
|
85 |
{
|
86 |
ITERATEUR j=lst_X.begin();
|
87 |
std::advance (j, num);
|
88 |
if (j == lst_X.end())
|
89 |
return NULL;
|
90 |
return *j;
|
91 |
};
|
92 |
|
93 |
void vide(void)
|
94 |
{
|
95 |
lst_X.clear();
|
96 |
};
|
97 |
|
98 |
|
99 |
X get_premier(ITERATEUR &it)
|
100 |
{
|
101 |
it = lst_X.begin();
|
102 |
if (it == lst_X.end())
|
103 |
return NULL;
|
104 |
return *it;
|
105 |
};
|
106 |
|
107 |
X get_suivant(ITERATEUR &it)
|
108 |
{
|
109 |
it++;
|
110 |
if (it == lst_X.end())
|
111 |
return NULL;
|
112 |
return *it;
|
113 |
}
|
114 |
|
115 |
void ajouter (const TPL_SET < X > & ref )
|
116 |
{
|
117 |
ITERATEUR it;
|
118 |
for (X element = ref.get_premier(it); element; element = ref.get_suivant(it))
|
119 |
ajouter(element);
|
120 |
}
|
121 |
|
122 |
private:
|
123 |
std::set< X > lst_X;
|
124 |
|
125 |
|
126 |
};
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
#endif
|