TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
TRUSTLists.h
1/****************************************************************************
2* Copyright (c) 2023, 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 TRUSTLists_included
17#define TRUSTLists_included
18
19#include <TRUSTList.h>
20
21inline void throw_()
22{
23 Cerr << "Unable to carry out allocation " << finl;
25}
26
27/*! @brief : Un tableau de listes de type IntList
28 *
29 */
30template<typename _TYPE_>
32{
33public :
34 virtual ~TRUSTLists()
35 {
36 if (sz)
37 {
38 assert(data);
39 delete[] data;
40 }
41 else
42 assert(data == 0);
43 }
44
45 TRUSTLists() : sz(0), data(0) { } // Construit un tableau vide de listes
46
47 // Construit un tableau de i listes
48 TRUSTLists(int i) : sz(i)
49 {
50 if (i == 0) data = 0;
51 else
52 {
53 data = new TRUSTList<_TYPE_>[i];
54 if (!data) throw_();
55 }
56 }
57
58 // Constructeur par copie
59 TRUSTLists(const TRUSTLists& vect) : sz(vect.sz)
60 {
61 if (vect.sz)
62 {
63 data = new TRUSTList<_TYPE_>[vect.sz];
64 if (!data) throw_();
65 }
66 int i = sz;
67 if (i == 0) data = 0;
68 else while (i--) data[i] = vect[i];
69 }
70
71 inline Sortie& printOn(Sortie& s) const
72 {
73 int i = sz;
74 while (i--) data[i].printOn(s);
75 return s << finl;
76 }
77
78 inline Entree& readOn(Entree& is) { return is; }
79
81
82 inline const TRUSTList<_TYPE_>& operator[](int) const;
84
85 inline void dimensionner(int );
86 inline int size() const { return sz; } // retourne le nombre de listes dans le tableau
87 inline int search(const TRUSTList<_TYPE_>&) const;
88
89protected :
90 int sz;
92};
93
94using IntLists = TRUSTLists<int>;
95using DoubleLists = TRUSTLists<double>;
96
97/*! @brief Copie et affectation.
98 *
99 * Les anciennes donnees sont perdues
100 *
101 */
102template<typename _TYPE_>
104{
105 sz = vect.sz;
106 if (data) delete[] data;
107
108 if (sz)
109 {
111 if (!data) throw_();
112 int i = sz;
113 while (i--) data[i] = vect[i];
114 }
115 else data = 0;
116 return *this;
117}
118
119/*! @brief Recherche d'une liste dans le tableau
120 *
121 */
122template<typename _TYPE_>
124{
125 int i = sz, retour = -1;
126 while (i--)
127 if (data[i] == t)
128 {
129 retour = i;
130 i = 0;
131 }
132 return retour;
133}
134
135/*! @brief Acces a la ieme liste du tableau
136 *
137 */
138template<typename _TYPE_>
140{
141 assert((i >= 0) && (i < sz));
142 return data[i];
143}
144
145template<typename _TYPE_>
147{
148 assert((i >= 0) && (i < sz));
149 return data[i];
150}
151
152/*! @brief Redimensionne un tableau de listes
153 *
154 */
155template<typename _TYPE_>
157{
158 assert(sz == 0 && data == 0);
159 sz = i;
160 if (i == 0) data = 0;
161 else
162 {
163 data = new TRUSTList<_TYPE_>[i];
164 if (!data) throw_();
165 }
166}
167
168#endif /* TRUSTLists_included */
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455
Classe de base des flux de sortie.
Definition Sortie.h:52
: Classe qui sert a representer une liste de reels int/double precision.
Definition TRUSTList.h:33
: Un tableau de listes de type IntList
Definition TRUSTLists.h:32
int size() const
Definition TRUSTLists.h:86
TRUSTList< _TYPE_ > & operator[](int)
Definition TRUSTLists.h:146
TRUSTLists(int i)
Definition TRUSTLists.h:48
int search(const TRUSTList< _TYPE_ > &) const
Recherche d'une liste dans le tableau.
Definition TRUSTLists.h:123
TRUSTLists & operator=(const TRUSTLists &)
Copie et affectation.
Definition TRUSTLists.h:103
Entree & readOn(Entree &is)
Definition TRUSTLists.h:78
virtual ~TRUSTLists()
Definition TRUSTLists.h:34
TRUSTLists(const TRUSTLists &vect)
Definition TRUSTLists.h:59
Sortie & printOn(Sortie &s) const
Definition TRUSTLists.h:71
void dimensionner(int)
Redimensionne un tableau de listes.
Definition TRUSTLists.h:156
const TRUSTList< _TYPE_ > & operator[](int) const
Acces a la ieme liste du tableau.
Definition TRUSTLists.h:139
TRUSTList< int > * data
Definition TRUSTLists.h:91