// FICHIER : EnuTypeCL.cc


// 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 "EnuTypeCL.h"


# include <iostream>
using namespace std;  //introduces namespace std
#include <stdlib.h>
#include "Sortie.h"
//#ifdef SYSTEM_MAC_OS_X
//  #include <stringfwd.h> // a priori ce n'est pas portable
//#el
#if defined  SYSTEM_MAC_OS_CARBON
  #include <stringfwd.h> // a priori ce n'est pas portable
#else  
  #include <string.h> // pour le flot en memoire centrale
#endif
#include <string>

// tout d'abord on définit la map qui permet de relier les chaines et les types énumérés
  // 1) def de la map 
  map < string,  EnuTypeCL , std::less < string> > 
           ClassPourEnuTypeCL::map_EnuTypeCL;
         
  // 2) def de la grandeur statique qui permet de remplir la map
  ClassPourEnuTypeCL ClassPourEnuTypeCL::remplir_map;
  // le constructeur qui rempli effectivement la map
  ClassPourEnuTypeCL::ClassPourEnuTypeCL()
    { // remplissage de la map
      map_EnuTypeCL["TANGENTE_CL"]=TANGENTE_CL; 
      map_EnuTypeCL["RIEN_TYPE_CL"]=RIEN_TYPE_CL;
      };

char* NomTypeCL(EnuTypeCL id_TypeCL)
// Retourne le nom du type de grandeur correspondant a l'identificateur 
// de type enumere id_TypeCL
{   char* result;
	switch (id_TypeCL)
	{   case TANGENTE_CL : result="TANGENTE_CL"; break;
		case RIEN_TYPE_CL : result="RIEN_TYPE_CL"; break;
		default :
			cout << "\nErreur : valeur incorrecte du type EnuTypeCL !\n";
			cout << "NomTypeCL(EnuTypeCL ) \n";
			Sortie(1);
	};
	return result;	
};
						
EnuTypeCL Id_nomTypeCL (char* nom_TypeCL)
// Retourne la variable de type enumere associe au nom nom_TypeCL
{	// on vérifie si la variable de type enumere existe
	map < string, EnuTypeCL , std::less < string> >& maa=ClassPourEnuTypeCL::map_EnuTypeCL;
    map < string, EnuTypeCL , std::less < string> >::iterator il,ilfin= maa.end();
    il = maa.find(nom_TypeCL);
    if (il == maa.end())
	   {// on vérifie si la variable de type enumere existe
		cout << "\nErreur : nom du type de grandeur  '" <<nom_TypeCL <<  " 'inconnu !\n";
		cout << "Id_nomTypeCL(char* ) \n";
		Sortie(1);
	   };
	 // retour de la grandeur 
	 return (*il).second;  
};

EnuTypeCL Id_nomTypeCL (string& nom_TypeCL)
// Retourne la variable de type enumere associe au nom nom_TypeCL
{	// on vérifie si la variable de type enumere existe
	map < string, EnuTypeCL , std::less < string> >& maa=ClassPourEnuTypeCL::map_EnuTypeCL;
    map < string, EnuTypeCL , std::less < string> >::iterator il,ilfin= maa.end();
    il = maa.find(nom_TypeCL);
    if (il == maa.end())
	   {// on vérifie si la variable de type enumere existe
		cout << "\nErreur : nom du type de grandeur  '" <<nom_TypeCL <<  " 'inconnu !\n";
		cout << "Id_nomTypeCL(string& ) \n";
		Sortie(1);
	   };
	 // retour de la grandeur 
	 return (*il).second;  
};

// indique si le string correspond à un type CL reconnu ou non
bool Existe_typeCL(string& nom)
{   return ( ClassPourEnuTypeCL::map_EnuTypeCL.find(nom) 
            != ClassPourEnuTypeCL::map_EnuTypeCL.end());};
	
// surcharge de la lecture
istream & operator >> (istream & entree, EnuTypeCL & result)
 { char nom_TypeCL[80];
   entree >> nom_TypeCL;
   result = Id_nomTypeCL ( nom_TypeCL);
   return entree;
 };  
   	   
// surcharge de l'operator d'ecriture
ostream & operator << (ostream & sort, const EnuTypeCL& a)
    { // on ecrit la forme caractère
       sort << NomTypeCL(a) << " ";
       return sort;      
     };