TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
TRUSTList.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 TRUSTList_included
17#define TRUSTList_included
18
19#include <TRUSTListElem.h>
20#include <Double.h>
21#include <Nom.h>
22#include <limits>
23
24template<typename _TYPE_> class TRUSTList_Curseur;
25
26/*! @brief : Classe qui sert a representer une liste de reels int/double precision.
27 *
28 * 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< >.
29 *
30 */
31template<typename _TYPE_>
32class TRUSTList : public TRUSTListElem<_TYPE_>
33{
34public :
35 friend class TRUSTList_Curseur<_TYPE_>;
36
38 {
39 min_data = std::numeric_limits<_TYPE_>::max();
40 max_data = std::numeric_limits<_TYPE_>::lowest();
41 size_ = 0;
42 dernier_ = this;
43 }
44
45 // Constructeur par copie
46 TRUSTList(const TRUSTList& a_list) : TRUSTListElem<_TYPE_>()
47 {
48 min_data = a_list.min_data;
49 max_data = a_list.max_data;
50 size_ = a_list.size_;
51 if (a_list.est_vide()) this->suivant_ = this;
52 else
53 {
54 this->data = a_list.data;
55 dernier_ = this;
56 if (a_list.suivant_)
57 {
58 TRUSTListElem<_TYPE_> *next = new TRUSTListElem<_TYPE_>(*a_list.suivant_); //Recursif !!
59 this->suivant_ = next;
60 }
61 else this->suivant_ = 0;
62 }
63 }
64
65 inline Sortie& printOn(Sortie& os) const;
66 inline Entree& readOn(Entree& is);
67
68 inline int size() const { return size_; };
69 inline int contient(_TYPE_) const;
70 inline int rang(_TYPE_) const;
71
72 /*! @brief Renvoie le dernier element de la liste
73 *
74 */
75 inline TRUSTListElem<_TYPE_>& dernier() { return *dernier_; }
76 inline const TRUSTListElem<_TYPE_>& dernier() const { return *dernier_; }
77
78 inline _TYPE_& operator[](int );
79 inline const _TYPE_& operator[](int ) const;
80
81 inline TRUSTList& add(_TYPE_ ) ;
82 inline TRUSTList& add_if_not(_TYPE_ ) ;
83 inline TRUSTList& operator=(const TRUSTList& );
84
85 template<typename T>
86 friend int operator ==(const TRUSTList<T>& , const TRUSTList<T>& );
87
88 inline void suppr(_TYPE_ );
89 inline void vide();
90 inline void calcule_min_max();
91
92private:
93 TRUSTListElem<_TYPE_>* dernier_;
94 _TYPE_ min_data, max_data;
95 int size_;
96};
97
98/*! @brief : List_Curseur de reels int/double precision
99 *
100 */
101template<typename _TYPE_>
103{
104public :
106 TRUSTList_Curseur(const TRUSTList<_TYPE_>& a_list) : curseur(&(TRUSTListElem<_TYPE_>&) a_list) { if (a_list.est_vide()) curseur = 0; }
107 TRUSTList_Curseur(const TRUSTListElem<_TYPE_>& a_list) : curseur(&(TRUSTListElem<_TYPE_>&) a_list) { if (a_list.est_vide()) curseur = 0; }
108
109 inline operator bool() const { return (curseur != 0); } // Teste si le curseur est non nul
110
111 // Avance le curseur dans la liste. Si le curseur est sur le dernier element, il devient nul
112 inline void operator++() { curseur = curseur->est_dernier() ? 0 : &(curseur->suivant()); }
113
114 // retourne la valeur du curseur
115 inline _TYPE_ valeur() const { return curseur->valeur(); }
116 inline _TYPE_& valeur() { return curseur->valeur(); }
117
118 // Affectation d'une liste a une liste_curseur
119 inline void operator=(const TRUSTList<_TYPE_>& a_list)
120 {
121 curseur = (&(TRUSTListElem<_TYPE_>&) a_list);
122 if (a_list.est_vide()) curseur = 0;
123 }
124
125 // Retourne la liste associee a la liste_curseur
126 inline const TRUSTListElem<_TYPE_>& list() const { return *curseur; }
127 inline TRUSTListElem<_TYPE_>& list() { return *curseur; }
128
129private :
130 TRUSTListElem<_TYPE_>* curseur = nullptr;
131};
132
133// typedefs !!!
134using IntList = TRUSTList<int>;
135using TIDList = TRUSTList<trustIdType>;
136using DoubleList = TRUSTList<double>;
137using IntList_Curseur = TRUSTList_Curseur<int>;
138using DoubleList_Curseur = TRUSTList_Curseur<double>;
139
140#include <TRUSTList.tpp> // templates specializations ici ;)
141
142#endif /* TRUSTList_included */
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
Classe de base des flux de sortie.
Definition Sortie.h:52
: Classe qui sert a representer une liste de reels int/double precision.
int est_vide() const
: List_Curseur de reels int/double precision
Definition TRUSTList.h:103
TRUSTList_Curseur(const TRUSTList< _TYPE_ > &a_list)
Definition TRUSTList.h:106
void operator=(const TRUSTList< _TYPE_ > &a_list)
Definition TRUSTList.h:119
TRUSTListElem< _TYPE_ > & list()
Definition TRUSTList.h:127
const TRUSTListElem< _TYPE_ > & list() const
Definition TRUSTList.h:126
_TYPE_ valeur() const
Definition TRUSTList.h:115
_TYPE_ & valeur()
Definition TRUSTList.h:116
TRUSTList_Curseur(const TRUSTListElem< _TYPE_ > &a_list)
Definition TRUSTList.h:107
: Classe qui sert a representer une liste de reels int/double precision.
Definition TRUSTList.h:33
const _TYPE_ & operator[](int) const
_TYPE_ & operator[](int)
Operateur d'acces au ieme int de la liste.
Sortie & printOn(Sortie &os) const
Ecriture d'une liste sur un flot de sortie les elements separes par des virgules figurent entre des a...
Definition TRUSTList.tpp:23
TRUSTList & add(_TYPE_)
insertion en queue
Definition TRUSTList.tpp:85
int rang(_TYPE_) const
renvoie le rang d'un element dans la liste si un element apparait plusieurs fois, renvoie le rang du ...
TRUSTList & add_if_not(_TYPE_)
Ajout d'un element a la liste ssi il n'existe pas deja.
TRUSTList(const TRUSTList &a_list)
Definition TRUSTList.h:46
Entree & readOn(Entree &is)
Lecture d'une liste sur un flot d'entree les elements separes par des virgules figurent entre des acc...
Definition TRUSTList.tpp:43
void suppr(_TYPE_)
Supprime un element contenu dans la liste.
int contient(_TYPE_) const
Verifie si un element appartient ou non a la liste.
const TRUSTListElem< _TYPE_ > & dernier() const
Definition TRUSTList.h:76
TRUSTList & operator=(const TRUSTList &)
Affectation.
Definition TRUSTList.tpp:65
void vide()
Vide la liste.
void calcule_min_max()
TRUSTListElem< _TYPE_ > & dernier()
Renvoie le dernier element de la liste.
Definition TRUSTList.h:75
int size() const
Definition TRUSTList.h:68