TrioCFD 1.9.9_beta
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 : Class used to represent a list of int/double precision reals.
25 *
26 * The container class List cannot be used with objects of type int/double because int/double is a predefined C++ type that does not have the functions required by 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; } // returns 1 if the list is empty, 0 otherwise
41 inline int est_dernier() const { return ((est_vide()) || (suivant_ == 0)); } // returns 1 if there is no next element, 0 otherwise
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 // We do not use the "delete suivant_" version because it is limited by the maximum recursion depth
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 */
: Class used to represent a list of int/double precision reals.
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.
: Class used to represent a list of int/double precision reals.
Definition TRUSTList.h:33
friend int operator==(const TRUSTList< T > &, const TRUSTList< T > &)