TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
Static_Int_Lists.h
1/****************************************************************************
2* Copyright (c) 2024, 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#ifndef Static_Int_Lists_included
16#define Static_Int_Lists_included
17
18#include <TRUSTTabs_forward.h>
19#include <TRUSTArray.h>
20
21/*! @brief Cette classe permet de stocker des listes d'entiers accessibles en temps constant.
22 *
23 * La taille des listes ne peut pas changer sans
24 * perdre le contenu (ce sont des listes statiques).
25 * Exemple:
26 * Static_Int_List l;
27 * ArrOfInt tailles(3);
28 * tailles[0] = 2; tailles[1] = 3; tailles[2] = 0;
29 * // On reserve la memoire pour trois listes de taille 2, 3 et 0:
30 * l.set_list_sizes(tailles);
31 * // On affecte une valeur au deuxieme element de la premiere liste:
32 * l.set_value(0,1,765);
33 * // Affiche la valeur
34 * Cout << l(0,1);
35 *
36 */
37template <typename _SIZE_>
39{
40public:
41 using int_t = _SIZE_;
42 using ArrOfInt_t = ArrOfInt_T<_SIZE_>;
43 using ArrsOfInt_t = ArrsOfInt_T<_SIZE_>;
44
45 void set_list_sizes(const ArrOfInt_t& sizes);
46 void reset();
47
48 void copy_list_to_array(int_t i_liste, ArrOfInt_t& array) const;
49
50 inline void set_value(int_t i_liste, int_t i_element, int_t valeur);
51 inline int_t operator() (int_t i_liste, int_t i_element) const;
52 inline int_t get_list_size(int_t i_liste) const;
53 inline int_t get_nb_lists() const;
54 const ArrOfInt_t& get_index() const { return index_; }
55 const ArrOfInt_t& get_data() const { return valeurs_; }
56 void set_data(const ArrOfInt_t& data);
57 void set_index_data(const ArrOfInt_t& index, const ArrOfInt_t& data);
59 void set(const ArrsOfInt_t& src);
60
61 Sortie& printOn(Sortie& os) const;
63 Sortie& ecrire(Sortie& os) const;
64
65private:
66 // Les listes d'entiers sont stockees de facon contigue
67 // dans le tableau valeurs_.
68 // Le premier element de la liste i est valeurs_[index_[i]]
69 // et le dernier element est valeurs_[index_[i+1]-1]
70 // (c'est comme le stockage morse des matrices).
71 ArrOfInt_t index_;
72 ArrOfInt_t valeurs_;
73};
74
75/*! @brief affecte la "valeur" au j-ieme element de la i-ieme liste avec 0 <= i < get_nb_lists() et 0 <= j < get_list_size(i)
76 *
77 */
78template <typename _SIZE_>
80{
81 const int_t index = index_[i] + j;
82 assert(index < index_[i+1]);
83 valeurs_[index] = valeur;
84}
85
86/*! @brief renvoie le j-ieme element de la i-ieme liste avec 0 <= i < get_nb_lists() et 0 <= j < get_list_size(i)
87 *
88 */
89template <typename _SIZE_>
91{
92 const int_t index = index_[i] + j;
93 assert(index < index_[i+1]);
94 const int_t val = valeurs_[index];
95 return val;
96}
97
98/*! @brief renvoie le nombre d'elements de la liste i
99 *
100 */
101template <typename _SIZE_>
103{
104 return index_[i+1] - index_[i];
105}
106
107/*! @brief renvoie le nombre de listes stockees
108 *
109 */
110template <typename _SIZE_>
112{
113 return index_.size_array() - 1;
114}
115
116using Static_Int_Lists = Static_Int_Lists_32_64<int>;
117using Static_Int_Lists_64 = Static_Int_Lists_32_64<trustIdType>;
118
119#endif
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
Cette classe permet de stocker des listes d'entiers accessibles en temps constant.
void set(const ArrsOfInt_t &src)
Sortie & ecrire(Sortie &os) const
void copy_list_to_array(int_t i_liste, ArrOfInt_t &array) const
copie la i-ieme liste dans le tableau fourni Le tableau array doit etre resizable.
const ArrOfInt_t & get_index() const
void set_value(int_t i_liste, int_t i_element, int_t valeur)
affecte la "valeur" au j-ieme element de la i-ieme liste avec 0 <= i < get_nb_lists() et 0 <= j < get...
void set_index_data(const ArrOfInt_t &index, const ArrOfInt_t &data)
remplace index et data.
ArrsOfInt_T< _SIZE_ > ArrsOfInt_t
void reset()
detruit toutes les listes
int_t get_list_size(int_t i_liste) const
renvoie le nombre d'elements de la liste i
void trier_liste(int_t i)
tri par ordre croissant des valeurs de la i-ieme liste.
void set_list_sizes(const ArrOfInt_t &sizes)
detruit les listes existantes et en cree de nouvelles.
int_t get_nb_lists() const
renvoie le nombre de listes stockees
Entree & readOn(Entree &is)
ArrOfInt_T< _SIZE_ > ArrOfInt_t
Sortie & printOn(Sortie &os) const
void set_data(const ArrOfInt_t &data)
remplace les valeurs stockes par toutes les listes par celles du tableau data.
const ArrOfInt_t & get_data() const
int_t operator()(int_t i_liste, int_t i_element) const
renvoie le j-ieme element de la i-ieme liste avec 0 <= i < get_nb_lists() et 0 <= j < get_list_size(i...