Salome HOME
BUG 0020024: a --gdb-session option to runSalome ...
[modules/kernel.git] / src / Batch / Batch_Versatile.hxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 /*
21  * Versatile.hxx : 
22  *
23  * Auteur : Ivan DUTKA-MALEN - EDF R&D
24  * Date   : Septembre 2003
25  * Projet : SALOME 2
26  *
27  */
28
29 #ifndef _VERSATILE_H_
30 #define _VERSATILE_H_
31
32 #include "Batch_Defines.hxx"
33
34 #include <iostream>
35 #include <list>
36 #include <string>
37 #include "Batch_GenericType.hxx"
38 #include "Batch_IntType.hxx"
39 #include "Batch_BoolType.hxx"
40 #include "Batch_CharType.hxx"
41 #include "Batch_LongType.hxx"
42 #include "Batch_StringType.hxx"
43 #include "Batch_CoupleType.hxx"
44 #include "Batch_TypeMismatchException.hxx"
45 #include "Batch_ListIsFullException.hxx"
46
47 namespace Batch {
48
49         // Les types autorises
50   // enum DiscriminatorType { UNDEFINED, BOOL, CHAR, INT, LONG, STRING};
51   enum DiscriminatorType { UNDEFINED, LONG, STRING, COUPLE };
52
53   typedef struct {
54     DiscriminatorType type; // le type de l'element interne
55     int maxelem; // le nombre d'elements autorises
56   } TypeParam;
57
58   class BATCH_EXPORT Versatile : public std::list< GenericType * >
59   {
60   public:
61                 // Constructeur standard et destructeur
62     Versatile() : _discriminator(UNDEFINED), _maxsize(1), _name("undefined") {}
63     virtual ~Versatile();
64
65                 // Constructeur par recopie
66     Versatile(const Versatile & V);
67
68                 // Constructeur depuis le type de "base"
69     Versatile(long   l) : _discriminator(LONG), _maxsize(1), _name("long")   { push_back(new LongType(l)); }
70     Versatile(const std::string & s) : _discriminator(STRING), _maxsize(1), _name("string") { push_back(new StringType(s)); }
71     Versatile(const Couple & c) : _discriminator(COUPLE), _maxsize(1), _name("couple") { push_back(new CoupleType(c)); }
72
73                 // Operateur d'affectation et de concatenation a partir d'un type de "base"
74     Versatile & operator = (const long     l)    throw(TypeMismatchException);
75     Versatile & operator = (const std::string & ch)   throw(TypeMismatchException);
76     Versatile & operator +=(const std::string & ch)   throw(TypeMismatchException,ListIsFullException);
77     Versatile & operator , (const std::string & ch)   throw(TypeMismatchException,ListIsFullException);
78     Versatile & operator = (const Couple & cp)   throw(TypeMismatchException);
79     Versatile & operator +=(const Couple & cp)   throw(TypeMismatchException,ListIsFullException);
80     Versatile & operator , (const Couple & cp)   throw(TypeMismatchException,ListIsFullException);
81
82                 // Operateur d'affectation entre objets
83     Versatile & operator = (const Versatile & V) throw(TypeMismatchException);
84
85                 // Conversion de type vers un type de "base"
86     operator long() const throw(TypeMismatchException);
87     operator std::string() const throw(TypeMismatchException);
88     operator Couple() const throw(TypeMismatchException);
89     std::string str() const throw(TypeMismatchException);
90
91                 // Operateur pour l'affichage sur un stream
92     friend std::ostream & operator << (std::ostream & os, const Versatile & );
93
94                 // Positionnement et recuperation du type de l'element interne
95     void setType(DiscriminatorType) throw(TypeMismatchException);
96     DiscriminatorType getType() const;
97
98                 // Positionnement et recuperation du nombre d'elements internes
99     void setMaxSize(int i);
100                 int getMaxSize() const { return _maxsize; }
101
102                 // Positionnement et recuperation du nom de l'objet
103     std::string getName() const;
104     void setName(const std::string & name);
105
106   protected:
107                 // Efface tous les elements internes de l'objet
108     virtual void eraseAll();
109
110     DiscriminatorType _discriminator; // type de l'element interne
111     int _maxsize; // nombre max d'elements internes
112     std::string _name; // nom de l'objet (sert pour les exceptions)
113
114   private:
115
116   };
117
118 }
119
120 #endif
121