1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 * Auteur : Ivan DUTKA-MALEN - EDF R&D
24 * Date : Septembre 2003
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"
47 // Les types autorises
48 // enum DiscriminatorType { UNDEFINED, BOOL, CHAR, INT, LONG, STRING};
49 enum DiscriminatorType { UNDEFINED, LONG, STRING, COUPLE };
52 DiscriminatorType type; // le type de l'element interne
53 int maxelem; // le nombre d'elements autorises
56 class Versatile : public std::list< GenericType * >
59 // Constructeur standard et destructeur
60 Versatile() : _discriminator(UNDEFINED), _maxsize(1), _name("undefined") {}
63 // Constructeur par recopie
64 Versatile(const Versatile & V);
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)); }
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);
80 // Operateur d'affectation entre objets
81 Versatile & operator = (const Versatile & V) throw(TypeMismatchException);
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);
89 // Operateur pour l'affichage sur un stream
90 friend std::ostream & operator << (std::ostream & os, const Versatile & );
92 // Positionnement et recuperation du type de l'element interne
93 void setType(DiscriminatorType) throw(TypeMismatchException);
94 DiscriminatorType getType() const;
96 // Positionnement et recuperation du nombre d'elements internes
97 void setMaxSize(int i);
98 int getMaxSize() const { return _maxsize; }
100 // Positionnement et recuperation du nom de l'objet
101 std::string getName() const;
102 void setName(const std::string & name);
105 // Efface tous les elements internes de l'objet
106 virtual void eraseAll();
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)