1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
25 * Auteur : Ivan DUTKA-MALEN - EDF R&D
26 * Date : Septembre 2003
34 #include "Batch_Defines.hxx"
39 #include "Batch_GenericType.hxx"
40 #include "Batch_IntType.hxx"
41 #include "Batch_BoolType.hxx"
42 #include "Batch_CharType.hxx"
43 #include "Batch_LongType.hxx"
44 #include "Batch_StringType.hxx"
45 #include "Batch_CoupleType.hxx"
46 #include "Batch_TypeMismatchException.hxx"
47 #include "Batch_ListIsFullException.hxx"
51 // Les types autorises
52 // enum DiscriminatorType { UNDEFINED, BOOL, CHAR, INT, LONG, STRING};
53 enum DiscriminatorType { UNDEFINED, LONG, STRING, COUPLE };
56 DiscriminatorType type; // le type de l'element interne
57 int maxelem; // le nombre d'elements autorises
60 class BATCH_EXPORT Versatile : public std::list< GenericType * >
63 // Constructeur standard et destructeur
64 Versatile() : _discriminator(UNDEFINED), _maxsize(1), _name("undefined") {}
67 // Constructeur par recopie
68 Versatile(const Versatile & V);
70 // Constructeur depuis le type de "base"
71 Versatile(long l) : _discriminator(LONG), _maxsize(1), _name("long") { push_back(new LongType(l)); }
72 Versatile(const std::string & s) : _discriminator(STRING), _maxsize(1), _name("string") { push_back(new StringType(s)); }
73 Versatile(const Couple & c) : _discriminator(COUPLE), _maxsize(1), _name("couple") { push_back(new CoupleType(c)); }
75 // Operateur d'affectation et de concatenation a partir d'un type de "base"
76 Versatile & operator = (const long l) throw(TypeMismatchException);
77 Versatile & operator = (const std::string & ch) throw(TypeMismatchException);
78 Versatile & operator +=(const std::string & ch) throw(TypeMismatchException,ListIsFullException);
79 Versatile & operator , (const std::string & ch) throw(TypeMismatchException,ListIsFullException);
80 Versatile & operator = (const Couple & cp) throw(TypeMismatchException);
81 Versatile & operator +=(const Couple & cp) throw(TypeMismatchException,ListIsFullException);
82 Versatile & operator , (const Couple & cp) throw(TypeMismatchException,ListIsFullException);
84 // Operateur d'affectation entre objets
85 Versatile & operator = (const Versatile & V) throw(TypeMismatchException);
87 // Conversion de type vers un type de "base"
88 operator long() const throw(TypeMismatchException);
89 operator std::string() const throw(TypeMismatchException);
90 operator Couple() const throw(TypeMismatchException);
91 std::string str() const throw(TypeMismatchException);
93 // Operateur pour l'affichage sur un stream
94 friend std::ostream & operator << (std::ostream & os, const Versatile & );
96 // Positionnement et recuperation du type de l'element interne
97 void setType(DiscriminatorType) throw(TypeMismatchException);
98 DiscriminatorType getType() const;
100 // Positionnement et recuperation du nombre d'elements internes
101 void setMaxSize(int i);
102 int getMaxSize() const { return _maxsize; }
104 // Positionnement et recuperation du nom de l'objet
105 std::string getName() const;
106 void setName(const std::string & name);
109 // Efface tous les elements internes de l'objet
110 virtual void eraseAll();
112 DiscriminatorType _discriminator; // type de l'element interne
113 int _maxsize; // nombre max d'elements internes
114 std::string _name; // nom de l'objet (sert pour les exceptions)