TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
ArrOfBit.cpp
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
16#include <arch.h>
17#include <ArrOfBit.h>
18#include <cstring>
19
20Implemente_instanciable_sans_constructeur_ni_destructeur_32_64(ArrOfBit_32_64,"ArrOfBit",Objet_U);
21
22/*! @brief Constructeur d'un tableau de taille n, non initialise
23 */
24template <typename _SIZE_>
31
32/*! @brief Destructeur.
33 */
34template <typename _SIZE_>
36{
37 if (data)
38 delete[] data;
39 data = 0;
40}
41
42/*! @brief Constructeur par copie (deep copy)
43 */
44template <typename _SIZE_>
46{
47 taille = 0;
48 data = 0;
49 operator=(array);
50}
51
52/*! @brief Taille en "int" du tableau requis pour stocker un tableau de bits de taille donnees.
53 */
54template <typename _SIZE_>
56{
57 assert(la_taille >= 0);
58 int_t siz = la_taille >> SIZE_OF_INT_BITS;
59 if (la_taille & DRAPEAUX_INT)
60 siz++;
61 return siz;
62}
63
64/*! @brief Change la taille du tableau et copie les donnees existantes.
65 *
66 * Si la taille est plus petite, les donnees sont
67 * tronquees, et si la taille est plus grande, les nouveaux elements
68 * ne sont pas initialises.
69 */
70template <typename _SIZE_>
72{
73 if (taille == n)
74 return *this;
75 assert(n >= 0);
76 if (n > 0)
77 {
79 int_t newsize = calculer_int_size(n);
80 unsigned int * newdata = new unsigned int[newsize];
81 int_t size_copy = (newsize > oldsize) ? oldsize : newsize;
82 if (size_copy)
83 {
84 memcpy(newdata, data, size_copy);
85 delete[] data;
86 }
87 data = newdata;
88 taille = n;
89 }
90 else
91 {
92 delete[] data; // data!=0 sinon taille==n et on ne serait pas ici
93 data = 0;
94 taille = 0;
95 }
96 return *this;
97}
98
99/*! @brief Operateur copie (deep copy).
100 */
101template <typename _SIZE_>
103{
104 int_t newsize = calculer_int_size(array.taille);
105 if (taille != array.taille)
106 {
107 if (data)
108 {
109 delete[] data;
110 data = 0;
111 }
112 if (newsize > 0)
113 data = new unsigned int[newsize];
114 }
115 taille = array.taille;
116 if (taille)
117 memcpy(data, array.data, newsize * sizeof(unsigned int));
118 return *this;
119}
120
121/*! @brief Si la valeur est non nulle, met la valeur 1 dans tous les elements du tableau, sinon met la valeur 0.
122 */
123template <typename _SIZE_>
125{
126 unsigned int valeur = val ? (~((unsigned int) 0)) : 0;
128 for (int_t i = 0; i < size; i++)
129 data[i] = valeur;
130 return *this;
131}
132
133/*! @brief Ecriture du tableau.
134 *
135 * Format: n
136 * 0 1 0 0 1 0 ... (n valeurs)
137 *
138 */
139template <typename _SIZE_>
141{
142#ifndef LATATOOLS
143 os << taille << finl;
144 // Un retour a la ligne tous les 32 bits,
145 // Une espace tous les 8 bits
146 int_t i = 0;
147 for (; i < taille; i++)
148 {
149 os << operator[](i);
150 if ((i & 7) == 7)
151 os << tspace;
152 if ((i & 31) == 31)
153 os << finl;
154 }
155 // Un retour a la ligne si la derniere ligne n'etait pas terminee
156 if (i & 31)
157 os << finl;
158#endif
159 return os;
160}
161
162/*! @brief Lecture du tableau.
163 *
164 * Format: n
165 * 0 1 0 0 1 0 ... (n valeurs)
166 *
167 */
168template <typename _SIZE_>
170{
171#ifndef LATATOOLS
172 int_t newsize;
173 is >> newsize;
174 resize_array(newsize);
175 operator=(0);
176
177 for (int_t i = 0; i < taille; i++)
178 {
179 int bit;
180 is >> bit;
181 if (bit) setbit(i);
182 }
183#endif
184 return is;
185}
186
187/////////////////////////////////////////////////
188//// Template instanciations
189/////////////////////////////////////////////////
190
191template class ArrOfBit_32_64<int>;
192#if INT_is_64_ == 2
193template class ArrOfBit_32_64<trustIdType>;
194#endif
195
int_t calculer_int_size(int_t taille) const
Taille en "int" du tableau requis pour stocker un tableau de bits de taille donnees.
Definition ArrOfBit.cpp:55
ArrOfBit_32_64 & operator=(const ArrOfBit_32_64 &array)
Operateur copie (deep copy).
Definition ArrOfBit.cpp:102
static constexpr unsigned int DRAPEAUX_INT
Definition ArrOfBit.h:52
ArrOfBit_32_64(int_t n=0)
Constructeur d'un tableau de taille n, non initialise.
Definition ArrOfBit.cpp:25
_SIZE_ int_t
Definition ArrOfBit.h:33
ArrOfBit_32_64 & resize_array(int_t n)
Change la taille du tableau et copie les donnees existantes.
Definition ArrOfBit.cpp:71
unsigned int * data
Definition ArrOfBit.h:50
static constexpr unsigned int SIZE_OF_INT_BITS
Definition ArrOfBit.h:51
~ArrOfBit_32_64() override
Destructeur.
Definition ArrOfBit.cpp:35
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
classe Objet_U Cette classe est la classe de base des Objets de TRUST
Definition Objet_U.h:73
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
Classe de base des flux de sortie.
Definition Sortie.h:52