Salome HOME
Added possibility to add specific parameters in the client classes. Added parameter...
[tools/libbatch.git] / src / Core / Batch_Versatile.hxx
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 /*
23  * Versatile.hxx :
24  *
25  * Auteur : Ivan DUTKA-MALEN - EDF R&D
26  * Date   : Septembre 2003
27  * Projet : SALOME 2
28  *
29  */
30
31 #ifndef _VERSATILE_H_
32 #define _VERSATILE_H_
33
34 #include "Batch_Defines.hxx"
35
36 #include <iostream>
37 #include <list>
38 #include <string>
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"
48
49 namespace Batch {
50
51         // Les types autorises
52   // enum DiscriminatorType { UNDEFINED, BOOL, CHAR, INT, LONG, STRING};
53   enum DiscriminatorType { UNDEFINED, LONG, STRING, COUPLE };
54
55   class BATCH_EXPORT Versatile : public std::list< GenericType * >
56   {
57   public:
58                 // Constructeur standard et destructeur
59     Versatile() : _discriminator(UNDEFINED), _maxsize(1), _name("undefined") {}
60     virtual ~Versatile();
61
62                 // Constructeur par recopie
63     Versatile(const Versatile & V);
64
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)); }
69
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);
78
79                 // Operateur d'affectation entre objets
80     Versatile & operator = (const Versatile & V) throw(TypeMismatchException);
81
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);
87
88                 // Operateur pour l'affichage sur un stream
89     BATCH_EXPORT friend std::ostream & operator << (std::ostream & os, const Versatile & );
90
91                 // Positionnement et recuperation du type de l'element interne
92     void setType(DiscriminatorType) throw(TypeMismatchException);
93     DiscriminatorType getType() const;
94
95                 // Positionnement et recuperation du nombre d'elements internes
96     void setMaxSize(int i);
97                 int getMaxSize() const { return _maxsize; }
98
99                 // Positionnement et recuperation du nom de l'objet
100     std::string getName() const;
101     void setName(const std::string & name);
102
103                 // Efface tous les elements internes de l'objet
104     virtual void eraseAll();
105   protected:
106
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)
110
111   private:
112
113   };
114
115 }
116
117 #endif