Salome HOME
Copyrights update
[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/
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 <iostream>
33 #include <list>
34 #include <string>
35 #include "Batch_GenericType.hxx"
36 #include "Batch_IntType.hxx"
37 #include "Batch_BoolType.hxx"
38 #include "Batch_CharType.hxx"
39 #include "Batch_LongType.hxx"
40 #include "Batch_StringType.hxx"
41 #include "Batch_CoupleType.hxx"
42 #include "Batch_TypeMismatchException.hxx"
43 #include "Batch_ListIsFullException.hxx"
44
45 namespace Batch {
46
47         // Les types autorises
48   // enum DiscriminatorType { UNDEFINED, BOOL, CHAR, INT, LONG, STRING};
49   enum DiscriminatorType { UNDEFINED, LONG, STRING, COUPLE };
50
51   typedef struct {
52     DiscriminatorType type; // le type de l'element interne
53     int maxelem; // le nombre d'elements autorises
54   } TypeParam;
55
56   class Versatile : public std::list< GenericType * >
57   {
58   public:
59                 // Constructeur standard et destructeur
60     Versatile() : _discriminator(UNDEFINED), _maxsize(1), _name("undefined") {}
61     virtual ~Versatile();
62
63                 // Constructeur par recopie
64     Versatile(const Versatile & V);
65
66                 // Constructeur depuis le type de "base"
67     Versatile(long   l) : _discriminator(LONG), _maxsize(1), _name("long")   { push_back(new LongType(l)); }
68     Versatile(const std::string & s) : _discriminator(STRING), _maxsize(1), _name("string") { push_back(new StringType(s)); }
69     Versatile(const Couple & c) : _discriminator(COUPLE), _maxsize(1), _name("couple") { push_back(new CoupleType(c)); }
70
71                 // Operateur d'affectation et de concatenation a partir d'un type de "base"
72     Versatile & operator = (const long     l)    throw(TypeMismatchException);
73     Versatile & operator = (const std::string & ch)   throw(TypeMismatchException);
74     Versatile & operator +=(const std::string & ch)   throw(TypeMismatchException,ListIsFullException);
75     Versatile & operator , (const std::string & ch)   throw(TypeMismatchException,ListIsFullException);
76     Versatile & operator = (const Couple & cp)   throw(TypeMismatchException);
77     Versatile & operator +=(const Couple & cp)   throw(TypeMismatchException,ListIsFullException);
78     Versatile & operator , (const Couple & cp)   throw(TypeMismatchException,ListIsFullException);
79
80                 // Operateur d'affectation entre objets
81     Versatile & operator = (const Versatile & V) throw(TypeMismatchException);
82
83                 // Conversion de type vers un type de "base"
84     operator long() const throw(TypeMismatchException);
85     operator std::string() const throw(TypeMismatchException);
86     operator Couple() const throw(TypeMismatchException);
87     std::string str() const throw(TypeMismatchException);
88
89                 // Operateur pour l'affichage sur un stream
90     friend std::ostream & operator << (std::ostream & os, const Versatile & );
91
92                 // Positionnement et recuperation du type de l'element interne
93     void setType(DiscriminatorType) throw(TypeMismatchException);
94     DiscriminatorType getType() const;
95
96                 // Positionnement et recuperation du nombre d'elements internes
97     void setMaxSize(int i);
98                 int getMaxSize() const { return _maxsize; }
99
100                 // Positionnement et recuperation du nom de l'objet
101     std::string getName() const;
102     void setName(const std::string & name);
103
104   protected:
105                 // Efface tous les elements internes de l'objet
106     virtual void eraseAll();
107
108     DiscriminatorType _discriminator; // type de l'element interne
109     int _maxsize; // nombre max d'elements internes
110     std::string _name; // nom de l'objet (sert pour les exceptions)
111
112   private:
113
114   };
115
116 }
117
118 #endif
119