Salome HOME
897eede280209b5d669c46c51c59b91e762009fe
[tools/libbatch.git] / src / Core / ParameterTypeMap.cxx
1 // Copyright (C) 2007-2015  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, or (at your option) any later version.
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  * ParameterTypeMap.cxx :
24  *
25  * Auteur : Renaud Barate - EDF R&D
26  * Date   : Mars 2011
27  *
28  */
29
30 #include <string>
31 #include <map>
32
33 #include "Constants.hxx"
34 #include "InvalidKeyException.hxx"
35 #include "ParameterTypeMap.hxx"
36
37 using namespace std;
38
39 namespace Batch {
40
41   /*!
42    * The values of this type map contain the type of the parameters and the maximum
43    * number of items in the corresponding Versatile object (0 means any number).
44    */
45   ParameterTypeMap::ParameterTypeMap()
46   {
47     // Don't use the string constants in this constructor because they might be uninitialized
48     addParameter("ARGUMENTS", STRING, 0);
49     addParameter("ASSIGNEDHOSTNAMES", STRING, 1);
50     addParameter("EXECUTABLE", STRING, 1);
51     addParameter("ID", STRING, 1);
52     addParameter("INFILE", COUPLE, 0);
53     addParameter("MAXCPUTIME", LONG, 1);
54     addParameter("MAXDISKSIZE", LONG, 1);
55     addParameter("MAXRAMSIZE", LONG, 1);
56     addParameter("MAXWALLTIME", LONG, 1);
57     addParameter("NAME", STRING, 1);
58     addParameter("NBPROC", LONG, 1);
59     addParameter("NBPROCPERNODE", LONG, 1);
60     addParameter("OUTFILE", COUPLE, 0);
61     addParameter("QUEUE", STRING, 1);
62     addParameter("STATE", STRING, 1);
63     addParameter("WORKDIR", STRING, 1);
64     addParameter("EXCLUSIVE", BOOL, 1);
65     addParameter("MEMPERCPU", LONG, 1);
66     addParameter("WCKEY", STRING, 1);
67     addParameter("EXTRAPARAMS", STRING, 1);
68
69         // Parameters for COORM
70     addParameter("LAUNCHER_FILE", STRING, 1);
71     addParameter("LAUNCHER_ARGS", STRING, 1);
72   }
73
74   ParameterTypeMap::~ParameterTypeMap()
75   {
76   }
77
78   /*!
79    * Returns the ParameterTypeMap singleton.
80    * We use the construct-on-first-use idiom here because otherwise there could be a problem with
81    * the initialization order between the factory singletons and this type map. Note that since the
82    * destructors do not depend on the other objects, the order is not important for destruction.
83    */
84   ParameterTypeMap& ParameterTypeMap::getInstance () {
85     static ParameterTypeMap instance;
86     return instance;
87   }
88
89   bool ParameterTypeMap::hasKey(const string & key) const
90   {
91     return (_map.find(key) != _map.end());
92   }
93
94   void ParameterTypeMap::addParameter(const std::string & key, DiscriminatorType type, int maxelem)
95   {
96     if (hasKey(key)) throw InvalidKeyException(key + " is already present in type map");
97     _map[key].type = type;
98     _map[key].maxelem = maxelem;
99   }
100
101   Versatile ParameterTypeMap::createVersatile(const std::string & parameterName)
102   {
103     map<string, ParameterType>::const_iterator it = _map.find(parameterName);
104     if (it == _map.end()) throw InvalidKeyException(parameterName);
105     return Versatile(it->second.type, it->second.maxelem, parameterName);
106   }
107
108 }