// FICHIER : EnumTypePilotage.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-2021 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 "EnumTypePilotage.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>

#include "UtilLecture.h"

char* Nom_TypePilotage (const EnumTypePilotage id_TypePilotage)
// Retourne le nom de la loi de TypePilotage correspondant a l'identificateur 
// de type enumere id_TypePilotage
{
	
   char* result;
	switch (id_TypePilotage)
	{
		case PILOTAGE_BASIQUE : result="PILOTAGE_BASIQUE"; break;
		case PILOT_GRADIENT : result="PILOT_GRADIENT"; break;
		case AUCUN_PILOTAGE : result="AUCUN_PILOTAGE"; break;
		default :
			cout << "\nErreur : valeur incorrecte du type EnumTypePilotage !\n";
			cout << "Nom_TypePilotage(const EnumTypePilotage id_TypePilotage) \n";
			Sortie(1);
	};
	return result;
	
};
						
EnumTypePilotage Id_nom_TypePilotage (const char* nom_TypePilotage)
// Retourne la variable de type enumere associee au nom  
// de TypePilotage nom_TypePilotage
{
	EnumTypePilotage result;
	if ( strcmp(nom_TypePilotage,"PILOTAGE_BASIQUE")==0 ) result=PILOTAGE_BASIQUE;
	else if ( strcmp(nom_TypePilotage,"PILOT_GRADIENT")==0 ) result=PILOT_GRADIENT;
	else if ( strcmp(nom_TypePilotage,"AUCUN_PILOTAGE")==0 ) result=AUCUN_PILOTAGE;
	else
	{
		cout << "\nErreur : nom du type de pilotage: " << nom_TypePilotage << "  inconnu !\n";
		cout << "Id_nom_TypePilotage(char* ) \n";
		Sortie(1);
	};
	return result;
	
};

// retourne si la chaine de caractère existe ou pas en tant que EnumTypePilotage
bool Existe_dans_TypePilotage(const char* nom_TypePilotage)
{  bool retour;
    if ( strcmp(nom_TypePilotage,"PILOTAGE_BASIQUE")==0 ) {retour=true;}
	else if ( strcmp(nom_TypePilotage,"PILOT_GRADIENT")==0 ) {retour=true;}
	else if ( strcmp(nom_TypePilotage,"AUCUN_PILOTAGE")==0 ) {retour=true;}
	else {retour = false;};
	return retour;	
};
   	
   // surcharge de l'operator de lecture
istream & operator >> (istream & entree, EnumTypePilotage& a)
 { char nom_EnumTypePilotage[50];
   entree >> nom_EnumTypePilotage;
   if (Existe_dans_TypePilotage(nom_EnumTypePilotage))
     {a = Id_nom_TypePilotage ( nom_EnumTypePilotage);}
   else
     { cout << "\n erreur en lecture d'un type de pilotage, chaine lue: " << nom_EnumTypePilotage;
       throw (UtilLecture::ErrNouvelleDonnee(-1));
       Sortie(1);
      }; 
   return entree;
 };
   
   // surcharge de l'operator d'ecriture
ostream & operator << (ostream & sort, const EnumTypePilotage& a)
    { // on ecrit la forme caractère
       sort << Nom_TypePilotage(a) << " ";
       return sort;      
     }; 

	
