TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
TRUSTListElem.h
1/****************************************************************************
2* Copyright (c) 2022, CEA
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9*
10* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
11* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
12* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13*
14*****************************************************************************/
15
16#ifndef TRUSTListElem_included
17#define TRUSTListElem_included
18
19#include <assert.h>
20#include <arch.h>
21
22template<typename _TYPE_> class TRUSTList;
23
24/*! @brief : Classe qui sert a representer une liste de reels int/double precision.
25 *
26 * On ne peut pas utiliser la classe container List avec des objets du type int/double car int/double est un type predefini du C++ qui ne possede pas les fonctions exigees par List< >.
27 *
28 */
29template<typename _TYPE_>
31{
32public :
33 friend class TRUSTList<_TYPE_>;
34
35 TRUSTListElem() { suivant_ = this; } // Construit une liste vide.
36 TRUSTListElem(const _TYPE_ x) : data(x), suivant_(0) { } // Construit le singleton (x).
39
40 inline int est_vide() const { return suivant_ == this; } // renvoie 1 si la liste est vide. 0 sinon
41 inline int est_dernier() const { return ((est_vide()) || (suivant_ == 0)); } // renvoie 1 si il n'y a pas de suivant. 0 sinon
42
43 inline _TYPE_& valeur() { return data; }
44 inline _TYPE_ valeur() const { return data; }
45
46 inline TRUSTListElem& add(_TYPE_ ) ;
47 inline TRUSTListElem& suivant() { return *suivant_; }
48 inline const TRUSTListElem& suivant() const { return *suivant_; }
49
50 template<typename T>
51 friend int operator ==(const TRUSTListElem<T>& , const TRUSTListElem<T>& );
52
53protected:
54 _TYPE_ data;
56};
57
58using IntListElem = TRUSTListElem<int>;
59using DoubleListElem = TRUSTListElem<double>;
60
61/*! @brief Constructeur par copie
62 *
63 * @param (const TRUSTListElem& list (la liste a copier))
64 */
65template<typename _TYPE_>
67{
68 if (list.est_vide()) suivant_ = this;
69 else
70 {
71 data = list.data;
72 if (list.suivant_)
73 {
74 TRUSTListElem<_TYPE_> *next = new TRUSTListElem<_TYPE_>(*list.suivant_); //Recursif !!
75 suivant_ = next;
76 }
77 else suivant_ = 0;
78 }
79}
80
81template<typename _TYPE_>
83{
84 if (est_vide()) suivant_ = 0;
85
86 if (suivant_)
87 {
88 // On ne garde pas la version delete suivant_ car sinon on est limite par le nombre d'appel recursif possible
89 // delete suivant_;
90 TRUSTListElem<_TYPE_> *poignee, *pr;
91 pr = suivant_;
92 suivant_ = 0;
93 while (pr)
94 {
95 poignee = pr->suivant_;
96 pr->suivant_ = 0;
97 delete pr;
98 pr = poignee;
99 }
100 }
101}
102
103/*! @brief insertion en queue
104 *
105 * @param (int/double value_to_add (element a ajouter))
106 */
107template<typename _TYPE_>
109{
110 assert(est_dernier());
111 TRUSTListElem<_TYPE_> *next = new TRUSTListElem<_TYPE_>(value_to_add);
112 suivant_ = next;
113 return *this;
114}
115
116/*! @brief Operateur de comparaison de deux listes
117 *
118 * @return (1 si les listes sont egales, 0 sinon)
119 */
120template<typename _TYPE_>
122{
123 int retour = 1;
124 if (list1.data != list2.data) retour = 0;
125 if ((!list1.est_dernier()) && (list2.est_dernier())) retour = 0;
126 if ((list1.est_dernier()) && (!list2.est_dernier())) retour = 0;
127 if ((!list1.est_dernier()) && (!list2.est_dernier())) retour = (*list1.suivant_ == *list2.suivant_);
128 return retour;
129}
130
131#endif /* TRUSTListElem_included */
: Classe qui sert a representer une liste de reels int/double precision.
const TRUSTListElem & suivant() const
_TYPE_ valeur() const
TRUSTListElem(const _TYPE_ x)
_TYPE_ & valeur()
int est_vide() const
TRUSTListElem & add(_TYPE_)
insertion en queue
int est_dernier() const
TRUSTListElem * suivant_
TRUSTListElem & suivant()
friend int operator==(const TRUSTListElem< T > &, const TRUSTListElem< T > &)
TRUSTListElem(const TRUSTListElem &)
Constructeur par copie.
: Classe qui sert a representer une liste de reels int/double precision.
Definition TRUSTList.h:33
friend int operator==(const TRUSTList< T > &, const TRUSTList< T > &)