Salome HOME
7a1426173cbd12fce451f2fdd08ceb9c06994197
[tools/libbatch.git] / src / Core / Batch_ParameterTypeMap.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  * Batch_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 "Batch_Constants.hxx"
34 #include "Batch_InvalidKeyException.hxx"
35 #include "Batch_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("ACCOUNT", STRING, 1);
49     addParameter("ARGUMENTS", STRING, 0);
50     addParameter("CHECKPOINT", LONG, 1);
51     addParameter("CKPTINTERVAL", LONG, 1);
52     addParameter("CREATIONTIME", LONG, 1);
53     addParameter("EGROUP", STRING, 1);
54     addParameter("ELIGIBLETIME", LONG, 1);
55     addParameter("ENDTIME", LONG, 1);
56     addParameter("EUSER", STRING, 1);
57     addParameter("EXECUTABLE", STRING, 1);
58     addParameter("EXITCODE", LONG, 1);
59     addParameter("HOLD", LONG, 1);
60     addParameter("ID", STRING, 1);
61     addParameter("INFILE", COUPLE, 0);
62     addParameter("MAIL", STRING, 1);
63     addParameter("MAXCPUTIME", LONG, 1);
64     addParameter("MAXDISKSIZE", LONG, 1);
65     addParameter("MAXRAMSIZE", LONG, 1);
66     addParameter("MAXWALLTIME", LONG, 1);
67     addParameter("MODIFICATIONTIME", LONG, 1);
68     addParameter("NAME", STRING, 1);
69     addParameter("NBPROC", LONG, 1);
70     addParameter("OUTFILE", COUPLE, 0);
71     addParameter("PID", LONG, 1);
72     addParameter("QUEUE", STRING, 1);
73     addParameter("QUEUEDTIME", LONG, 1);
74     addParameter("SERVER", STRING, 1);
75     addParameter("STARTTIME", LONG, 1);
76     addParameter("STATE", STRING, 1);
77     addParameter("TEXT", STRING, 1);
78     addParameter("USEDCPUTIME", LONG, 1);
79     addParameter("USEDDISKSIZE", LONG, 1);
80     addParameter("USEDRAMSIZE", LONG, 1);
81     addParameter("USEDWALLTIME", LONG, 1);
82     addParameter("USER", STRING, 1);
83     addParameter("WORKDIR", STRING, 1);
84     addParameter("HOMEDIR", STRING, 1);
85     addParameter("EXCLUSIVE", BOOL, 1);
86   }
87
88   ParameterTypeMap::~ParameterTypeMap()
89   {
90   }
91
92   /*!
93    * Returns the ParameterTypeMap singleton.
94    * We use the construct-on-first-use idiom here because otherwise there could be a problem with
95    * the initialization order between the factory singletons and this type map. Note that since the
96    * destructors do not depend on the other objects, the order is not important for destruction.
97    */
98   ParameterTypeMap& ParameterTypeMap::getInstance () {
99     static ParameterTypeMap instance;
100     return instance;
101   }
102
103   bool ParameterTypeMap::hasKey(const string & key) const
104   {
105     return (_map.find(key) != _map.end());
106   }
107
108   void ParameterTypeMap::addParameter(const std::string & key, DiscriminatorType type, int maxelem)
109   {
110     if (hasKey(key)) throw InvalidKeyException(key + " is already present in type map");
111     _map[key].type = type;
112     _map[key].maxelem = maxelem;
113   }
114
115   Versatile ParameterTypeMap::createVersatile(const std::string & parameterName)
116   {
117     map<string, ParameterType>::const_iterator it = _map.find(parameterName);
118     if (it == _map.end()) throw InvalidKeyException(parameterName);
119     return Versatile(it->second.type, it->second.maxelem, parameterName);
120   }
121
122 }