4 * Auteur : Ivan DUTKA-MALEN - EDF R&D
5 * Date : Septembre 2003
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"
29 // Les types autorises
30 // enum DiscriminatorType { UNDEFINED, BOOL, CHAR, INT, LONG, STRING};
31 enum DiscriminatorType { UNDEFINED, LONG, STRING, COUPLE };
34 DiscriminatorType type; // le type de l'element interne
35 int maxelem; // le nombre d'elements autorises
38 class Versatile : public list< GenericType * >
41 // Constructeur standard et destructeur
42 Versatile() : _discriminator(UNDEFINED), _maxsize(1), _name("undefined") {}
45 // Constructeur par recopie
46 Versatile(const Versatile & V);
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)); }
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);
62 // Operateur d'affectation entre objets
63 Versatile & operator = (const Versatile & V) throw(TypeMismatchException);
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);
71 // Operateur pour l'affichage sur un stream
72 friend ostream & operator << (ostream & os, const Versatile & );
74 // Positionnement et recuperation du type de l'element interne
75 void setType(DiscriminatorType) throw(TypeMismatchException);
76 DiscriminatorType getType() const;
78 // Positionnement et recuperation du nombre d'elements internes
79 void setMaxSize(int i);
80 int getMaxSize() const { return _maxsize; }
82 // Positionnement et recuperation du nom de l'objet
83 string getName() const;
84 void setName(const string & name);
87 // Efface tous les elements internes de l'objet
88 virtual void eraseAll();
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)