Salome HOME
Update copyrights
[tools/libbatch.git] / src / Core / Batch_Parametre.cxx
1 //  Copyright (C) 2007-2012  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     Parametre::iterator it = find(mk);
54     if (it != end()) {
55       return it->second;
56     } else {
57       Versatile V = ParameterTypeMap::getInstance().createVersatile(mk);
58       pair<iterator, bool> result = insert(make_pair(mk, V));
59       return result.first->second;
60     }
61   }
62
63   // Operateur de recherche dans la map
64   // Cet operateur agit sur les objets CONSTANTS
65   const Versatile & Parametre::operator [] (const string & mk) const
66   {
67     // On controle que la clef est valide
68     if (!ParameterTypeMap::getInstance().hasKey(mk)) throw InvalidKeyException(mk);
69
70     // On recherche la valeur associee
71     Parametre::const_iterator it = find(mk);
72     if (it == end()) throw InvalidKeyException(mk);
73     const Versatile & V = (*it).second;
74
75     return V;
76   }
77
78   // Operateur d'affectation
79   Parametre & Parametre::operator =(const Parametre & PM)
80   {
81     // On ne reaffecte pas l'objet a lui-meme, sinon aie, aie, aie
82     if (this == &PM) return *this;
83
84     // On efface toute la map
85     erase(begin(), end());
86
87     // On recree la structure interne de la map avec les valeurs de celle passee en argument
88     Parametre::const_iterator it;
89     for(it=PM.begin(); it!=PM.end(); it++)
90       insert(make_pair((*it).first, Versatile((*it).second)));
91
92     return *this;
93   }
94
95   // Constructeur par recopie
96   Parametre::Parametre(const Parametre & PM) : map< string, Versatile >()
97   {
98     // On cree la structure interne de la map avec les valeurs de celle passee en argument
99     Parametre::const_iterator it;
100     for(it=PM.begin(); it!=PM.end(); it++)
101       insert(make_pair((*it).first, Versatile((*it).second)));
102   }
103
104 }