Salome HOME
PR: mergefrom_BR_BATCH_22Oct04
[modules/kernel.git] / src / Batch / Batch_Versatile.hxx
1 /*
2  * Versatile.hxx : 
3  *
4  * Auteur : Ivan DUTKA-MALEN - EDF R&D
5  * Date   : Septembre 2003
6  * Projet : SALOME 2
7  *
8  */
9
10 #ifndef _VERSATILE_H_
11 #define _VERSATILE_H_
12
13 using namespace std;
14 #include <iostream>
15 #include <list>
16 #include <string>
17 #include "Batch_GenericType.hxx"
18 #include "Batch_IntType.hxx"
19 #include "Batch_BoolType.hxx"
20 #include "Batch_CharType.hxx"
21 #include "Batch_LongType.hxx"
22 #include "Batch_StringType.hxx"
23 #include "Batch_CoupleType.hxx"
24 #include "Batch_TypeMismatchException.hxx"
25 #include "Batch_ListIsFullException.hxx"
26
27 namespace Batch {
28
29         // Les types autorises
30   // enum DiscriminatorType { UNDEFINED, BOOL, CHAR, INT, LONG, STRING};
31   enum DiscriminatorType { UNDEFINED, LONG, STRING, COUPLE };
32
33   typedef struct {
34     DiscriminatorType type; // le type de l'element interne
35     int maxelem; // le nombre d'elements autorises
36   } TypeParam;
37
38   class Versatile : public list< GenericType * >
39   {
40   public:
41                 // Constructeur standard et destructeur
42     Versatile() : _discriminator(UNDEFINED), _maxsize(1), _name("undefined") {}
43     virtual ~Versatile();
44
45                 // Constructeur par recopie
46     Versatile(const Versatile & V);
47
48                 // Constructeur depuis le type de "base"
49     Versatile(long   l) : _discriminator(LONG), _maxsize(1), _name("long")   { push_back(new LongType(l)); }
50     Versatile(const string & s) : _discriminator(STRING), _maxsize(1), _name("string") { push_back(new StringType(s)); }
51     Versatile(const Couple & c) : _discriminator(COUPLE), _maxsize(1), _name("couple") { push_back(new CoupleType(c)); }
52
53                 // Operateur d'affectation et de concatenation a partir d'un type de "base"
54     Versatile & operator = (const long     l)    throw(TypeMismatchException);
55     Versatile & operator = (const string & ch)   throw(TypeMismatchException);
56     Versatile & operator +=(const string & ch)   throw(TypeMismatchException,ListIsFullException);
57     Versatile & operator , (const string & ch)   throw(TypeMismatchException,ListIsFullException);
58     Versatile & operator = (const Couple & cp)   throw(TypeMismatchException);
59     Versatile & operator +=(const Couple & cp)   throw(TypeMismatchException,ListIsFullException);
60     Versatile & operator , (const Couple & cp)   throw(TypeMismatchException,ListIsFullException);
61
62                 // Operateur d'affectation entre objets
63     Versatile & operator = (const Versatile & V) throw(TypeMismatchException);
64
65                 // Conversion de type vers un type de "base"
66     operator long() const throw(TypeMismatchException);
67     operator string() const throw(TypeMismatchException);
68     operator Couple() const throw(TypeMismatchException);
69     string str() const throw(TypeMismatchException);
70
71                 // Operateur pour l'affichage sur un stream
72     friend ostream & operator << (ostream & os, const Versatile & );
73
74                 // Positionnement et recuperation du type de l'element interne
75     void setType(DiscriminatorType) throw(TypeMismatchException);
76     DiscriminatorType getType() const;
77
78                 // Positionnement et recuperation du nombre d'elements internes
79     void setMaxSize(int i);
80                 int getMaxSize() const { return _maxsize; }
81
82                 // Positionnement et recuperation du nom de l'objet
83     string getName() const;
84     void setName(const string & name);
85
86   protected:
87                 // Efface tous les elements internes de l'objet
88     virtual void eraseAll();
89
90     DiscriminatorType _discriminator; // type de l'element interne
91     int _maxsize; // nombre max d'elements internes
92     string _name; // nom de l'objet (sert pour les exceptions)
93
94   private:
95
96   };
97
98 }
99
100 #endif
101