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