TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
Liste_bloc.cpp
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#include <Liste_bloc.h>
17
18Implemente_instanciable_sans_constructeur_ni_destructeur(Liste_bloc,"Liste_bloc",Objet_U);
19
20Entree& Liste_bloc::readOn(Entree& is) { return is; }
21
22Sortie& Liste_bloc::printOn(Sortie& os) const { return os; }
23
24/*! @brief Renvoie le dernier element de la liste
25 *
26 * @return (Liste_bloc&) le dernier element de la liste
27 */
29{
30 if (est_dernier()) return *this;
31 Liste_bloc_curseur curseur(*this);
32 while (curseur)
33 if (curseur.list().est_dernier()) break;
34 else ++curseur;
35 return curseur.list();
36}
37
39{
40 vide();
41 suivant_ = nullptr;
42}
43
44/*! @brief Vide la liste
45 *
46 */
48{
49 if (!est_vide())
50 {
51 if (suivant_)
52 {
53 suivant_->vide();
54 delete suivant_;
55 }
56 data = DerObjU();
57 }
58 suivant_ = this;
59}
60
61/*! @brief Operateur d'acces au ieme element de la liste
62 *
63 * @param (int i) l'indice de l'element a trouver
64 * @return (Objet_U&) le ieme element de la liste
65 */
67{
68 Liste_bloc_curseur curseur(*this);
69 if (!curseur)
70 {
71 Cerr << que_suis_je() << " : empty list !" << finl;
73 }
74 while (curseur && i--)
75 ++curseur;
76 if (i != -1)
77 {
78 Cerr << que_suis_je() << " : overflow of list " << finl;
79 assert(i == -1);
81 }
82 return curseur.valeur();
83}
84
85/*! @brief Ajout d'un Objet_U a la liste to_add est libere en sortie
86 *
87 */
89{
90 if (est_vide())
91 {
92 data.deplace(to_add);
93 suivant_ = nullptr;
94 return valeur();
95 }
96 else
97 {
98 if (est_dernier())
99 {
100 Liste_bloc *liste_ptr = new Liste_bloc;
101 if (!liste_ptr)
102 {
103 Cerr << "Run out of memory " << finl;
105 }
106 liste_ptr->add_deplace(to_add);
107 suivant_ = liste_ptr;
108 return suivant_->valeur();
109 }
110 else
111 return dernier().add_deplace(to_add);
112 }
113}
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
const Liste_bloc & list() const
Definition Liste_bloc.h:59
const Objet_U & valeur() const
Definition Liste_bloc.h:55
La classe Liste_bloc et Liste_bloc_curseur represente une liste de Deriv<Objet_U> et un curseur assoc...
Definition Liste_bloc.h:25
~Liste_bloc() override
int est_dernier() const
Definition Liste_bloc.h:34
Liste_bloc & dernier()
Renvoie le dernier element de la liste.
Objet_U & operator[](int)
Operateur d'acces au ieme element de la liste.
int est_vide() const
Definition Liste_bloc.h:31
Liste_bloc * suivant_
Definition Liste_bloc.h:48
void vide()
Vide la liste.
Objet_U & valeur()
Definition Liste_bloc.h:32
Objet_U & add_deplace(DerObjU &)
Ajout d'un Objet_U a la liste to_add est libere en sortie.
DerObjU data
Definition Liste_bloc.h:47
classe Objet_U Cette classe est la classe de base des Objets de TRUST
Definition Objet_U.h:73
const Nom & que_suis_je() const
renvoie la chaine identifiant la classe.
Definition Objet_U.cpp:104
virtual Entree & readOn(Entree &)
Lecture d'un Objet_U sur un flot d'entree Methode a surcharger.
Definition Objet_U.cpp:293
Objet_U()
Constructeur par defaut : attribue un numero d'identifiant unique a l'objet (object_id_),...
Definition Objet_U.cpp:55
virtual Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
Definition Objet_U.cpp:282
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