TrioCFD 1.9.9_beta
TrioCFD documentation
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 Returns the last element of the list.
25 *
26 * @return (Liste_bloc&) the last element of the list
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 Clears the list.
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 Access operator to the i-th element of the list.
62 *
63 * @param (int i) the index of the element to find
64 * @return (Objet_U&) the i-th element of the list
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 Adds an Objet_U to the list. to_add is released on exit.
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
The Liste_bloc and Liste_bloc_curseur classes represent a list of Deriv<Objet_U> elements and an asso...
Definition Liste_bloc.h:25
~Liste_bloc() override
int est_dernier() const
Definition Liste_bloc.h:34
Liste_bloc & dernier()
Returns the last element of the list.
Objet_U & operator[](int)
Access operator to the i-th element of the list.
int est_vide() const
Definition Liste_bloc.h:31
Liste_bloc * suivant_
Definition Liste_bloc.h:48
void vide()
Clears the list.
Objet_U & valeur()
Definition Liste_bloc.h:32
Objet_U & add_deplace(DerObjU &)
Adds an Objet_U to the list. to_add is released on exit.
DerObjU data
Definition Liste_bloc.h:47
Base class for TRUST objects (Objet_U).
Definition Objet_U.h:68
const Nom & que_suis_je() const
Returns the string identifying the class.
Definition Objet_U.cpp:104
virtual Entree & readOn(Entree &)
Reads an Objet_U from an input stream. Virtual method to override.
Definition Objet_U.cpp:289
Objet_U()
Default constructor: assigns a unique identifier to the object (object_id_) and registers the object ...
Definition Objet_U.cpp:54
virtual Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
Definition Objet_U.cpp:278
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
Base class for output streams.
Definition Sortie.h:52