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