Salome HOME
Changed year in copyrights
[tools/libbatch.git] / src / Core / Batch_Parametre.cxx
1 //  Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 /*
23  * Parametre.cxx :
24  *
25  * Auteur : Ivan DUTKA-MALEN - EDF R&D
26  * Date   : Septembre 2003
27  * Projet : SALOME 2
28  *
29  */
30
31 #include "Batch_Versatile.hxx"
32 #include "Batch_InvalidKeyException.hxx"
33 #include "Batch_ParameterTypeMap.hxx"
34 #include "Batch_Parametre.hxx"
35
36 using namespace std;
37
38 namespace Batch {
39
40   // Constructeur standard
41   Parametre::Parametre() : map< string, Versatile >()
42   {
43   }
44
45   // Operateur de recherche dans la map
46   // Cet operateur agit sur les objets NON CONSTANTS, il autorise la modification de
47   // la valeur associ�e � la clef car il retourne une reference non constante
48   Versatile & Parametre::operator [] (const string & mk)
49   {
50     // On controle que la clef est valide
51     if (!ParameterTypeMap::getInstance().hasKey(mk)) throw InvalidKeyException(mk);
52
53     // On recherche la valeur associee...
54     Versatile & V = map< string, Versatile >::operator [] (mk);
55
56     // ... et on l'initialise systematiquement
57     // ATTENTION : si un probleme de type survient (ie, on stocke une valeur d'un type
58     // different de celui inscrit dans TypeMap) une exception TypeMismatchException est
59     // levee
60     V.setName(mk);
61     V.setType(ParameterTypeMap::getInstance()[mk].type);
62     V.setMaxSize(ParameterTypeMap::getInstance()[mk].maxelem);
63
64     return V;
65   }
66
67   // Operateur de recherche dans la map
68   // Cet operateur agit sur les objets CONSTANTS
69   const Versatile & Parametre::operator [] (const string & mk) const
70   {
71     // On controle que la clef est valide
72     if (!ParameterTypeMap::getInstance().hasKey(mk)) throw InvalidKeyException(mk);
73
74     // On recherche la valeur associee
75     Parametre::const_iterator it = find(mk);
76     if (it == end()) throw InvalidKeyException(mk);
77     const Versatile & V = (*it).second;
78
79     return V;
80   }
81
82   // Operateur d'affectation
83   Parametre & Parametre::operator =(const Parametre & PM)
84   {
85     // On ne reaffecte pas l'objet a lui-meme, sinon aie, aie, aie
86     if (this == &PM) return *this;
87
88     // On efface toute la map
89     erase(begin(), end());
90
91     // On recree la structure interne de la map avec les valeurs de celle passee en argument
92     Parametre::const_iterator it;
93     for(it=PM.begin(); it!=PM.end(); it++)
94       insert(make_pair((*it).first, Versatile((*it).second)));
95
96     return *this;
97   }
98
99   // Constructeur par recopie
100   Parametre::Parametre(const Parametre & PM) : map< string, Versatile >()
101   {
102     // On cree la structure interne de la map avec les valeurs de celle passee en argument
103     Parametre::const_iterator it;
104     for(it=PM.begin(); it!=PM.end(); it++)
105       insert(make_pair((*it).first, Versatile((*it).second)));
106   }
107
108 }