Herezh_dev/Tableaux/Tableau_3D.cc

1 line
4.6 KiB
C++
Raw Permalink Normal View History

2023-05-03 17:23:49 +02:00
// FICHIER : Tableau_3D.cc // CLASSE : Tableau_3D // This file is part of the Herezh++ application. // // The finite element software Herezh++ is dedicated to the field // of mechanics for large transformations of solid structures. // It is developed by Gérard Rio (APP: IDDN.FR.010.0106078.000.R.P.2006.035.20600) // INSTITUT DE RECHERCHE DUPUY DE LÔME (IRDL) <https://www.irdl.fr/>. // // Herezh++ is distributed under GPL 3 license ou ultérieure. // // Copyright (C) 1997-2022 Université Bretagne Sud (France) // AUTHOR : Gérard Rio // E-MAIL : gerardrio56@free.fr // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, // or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. // See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see <https://www.gnu.org/licenses/>. // // For more information, please consult: <https://herezh.irdl.fr/>. #include <iostream> using namespace std; #include <stdlib.h> #include "Sortie.h" #include "Tableau_3D.h" Tableau_3D::Tableau_3D () // Constructeur par defaut { dim1=0; dim2=0; dim3=0; t=NULL; }; Tableau_3D::Tableau_3D (int d1,int d2,int d3,double val) // Constructeur utile quand les trois dimensions ainsi qu'une // eventuelle valeur d'initialisation sont connues { if ( ( d1<0 ) || ( d2<0 ) || ( d3<0 ) ) { cout << "\nErreur : taille(s) invalide(s) !\n"; cout << "TABLEAU_3D::TABLEAU_3D(int ,int ,int ,double ) \n"; Sortie(1); }; if ( ( d1==0 ) || ( d2==0 ) || ( d3==0 ) ) // cas ou une des dimensions est nulle : initialisation identique // a l'appel du constructeur par defaut { dim1=0; dim2=0; dim3=0; t=NULL; } else // autres cas { dim1=d1; dim2=d2; dim3=d3; t=new double [d1*d2*d3]; // allocation dynamique de la memoire Initialise(val); // initialisation des composantes a val }; }; Tableau_3D::Tableau_3D (const Tableau_3D& tab) // Constructeur de copie { if ( tab.dim1==0 ) // cas ou le tableau copie est vide : initialisation // identique a l'appel du constructeur par defaut { dim1=0; dim2=0; dim3=0; t=NULL; } else { dim1=tab.dim1; dim2=tab.dim2; dim3=tab.dim3; t=new double [dim1*dim2*dim3]; // allocation dynamique de la memoire double* ptr1=t; double* ptr2=tab.t; for (int i=0;i<dim1;i++) { for (int j=0;j<dim2;j++) { for (int k=0;k<dim3;k++) { (*ptr1++)=(*ptr2++); // copie des composantes du tableau tab }; }; }; }; }; Tableau_3D::~Tableau_3D () // Destructeur (N.B. : Apres l'appel de ce destructeur le tableau est identique // a ce qu'il aurait ete a la suite d'un appel du constructeur par defaut) { Libere(); }; void Tableau_3D::Initialise (double val) // Initialisation des composantes du tableau a trois dimensions { double* ptr=t; for (int i=0;i<dim1;i++) { for (int j=0;j<dim2;j++) { for (int k=0;k<dim3;k++) { (*ptr++)=val; // initialisation des composantes a val }; }; }; }; void Tableau_3D::Libere () // Apres l'appel de cette methode le tableau est identique a ce qu'il // aurait ete a la suite d'un appel du constructeur par defaut { if ( dim1>0 ) delete [] t; // desallocation de la place memoire else { if ( t!=NULL ) { cout << "\nErreur de liberation de la place memoire\n"; cout << "TABLEAU_3D::LIBERE() \n"; Sortie(1); } }; t=NULL; dim1=0; dim2=0; dim3=0; }; Tableau_3D& Tableau_3D::operator= (const Tableau_3D& tab) // Surcharge de l'operateur = : egalite entre deux tableaux a trois dimensions { if ( t!=NULL ) Libere(); // cas ou le tableau se trouvant a gauche du signe = // n'est pas vide : desallocation de ce tableau if ( tab.dim1==0 ) // cas ou le tab