1 // Copyright (C) 2007-2010 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 };
55 class BATCH_EXPORT Versatile : public std::list< GenericType * >
58 // Constructeur standard et destructeur
59 Versatile() : _discriminator(UNDEFINED), _maxsize(1), _name("undefined") {}
62 // Constructeur par recopie
63 Versatile(const Versatile & V);
65 // Constructeur depuis le type de "base"
66 Versatile(long l) : _discriminator(LONG), _maxsize(1), _name("long") { push_back(new LongType(l)); }
67 Versatile(const std::string & s) : _discriminator(STRING), _maxsize(1), _name("string") { push_back(new StringType(s)); }
68 Versatile(const Couple & c) : _discriminator(COUPLE), _maxsize(1), _name("couple") { push_back(new CoupleType(c)); }
70 // Operateur d'affectation et de concatenation a partir d'un type de "base"
71 Versatile & operator = (const long l) throw(TypeMismatchException);
72 Versatile & operator = (const std::string & ch) throw(TypeMismatchException);
73 Versatile & operator +=(const std::string & ch) throw(TypeMismatchException,ListIsFullException);
74 Versatile & operator , (const std::string & ch) throw(TypeMismatchException,ListIsFullException);
75 Versatile & operator = (const Couple & cp) throw(TypeMismatchException);
76 Versatile & operator +=(const Couple & cp) throw(TypeMismatchException,ListIsFullException);
77 Versatile & operator , (const Couple & cp) throw(TypeMismatchException,ListIsFullException);
79 // Operateur d'affectation entre objets
80 Versatile & operator = (const Versatile & V) throw(TypeMismatchException);
82 // Conversion de type vers un type de "base"
83 operator long() const throw(TypeMismatchException);
84 operator std::string() const throw(TypeMismatchException);
85 operator Couple() const throw(TypeMismatchException);
86 std::string str() const throw(TypeMismatchException);
88 // Operateur pour l'affichage sur un stream
89 BATCH_EXPORT friend std::ostream & operator << (std::ostream & os, const Versatile & );
91 // Positionnement et recuperation du type de l'element interne
92 void setType(DiscriminatorType) throw(TypeMismatchException);
93 DiscriminatorType getType() const;
95 // Positionnement et recuperation du nombre d'elements internes
96 void setMaxSize(int i);
97 int getMaxSize() const { return _maxsize; }
99 // Positionnement et recuperation du nom de l'objet
100 std::string getName() const;
101 void setName(const std::string & name);
103 // Efface tous les elements internes de l'objet
104 virtual void eraseAll();
107 DiscriminatorType _discriminator; // type de l'element interne
108 size_type _maxsize; // nombre max d'elements internes
109 std::string _name; // nom de l'objet (sert pour les exceptions)