Salome HOME
96b4b6016c9dc6ff941709eba32f152894dd96d4
[tools/libbatch.git] / src / Core / Batch_Versatile.hxx
1 //  Copyright (C) 2007-2011  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  * Author : Ivan DUTKA-MALEN - EDF R&D
26  * Date   : September 2003
27  *
28  */
29
30 #ifndef _VERSATILE_H_
31 #define _VERSATILE_H_
32
33 #include "Batch_Defines.hxx"
34
35 #include <iostream>
36 #include <list>
37 #include <string>
38 #include "Batch_GenericType.hxx"
39 #include "Batch_BoolType.hxx"
40 #include "Batch_CharType.hxx"
41 #include "Batch_LongType.hxx"
42 #include "Batch_StringType.hxx"
43 #include "Batch_CoupleType.hxx"
44 #include "Batch_TypeMismatchException.hxx"
45 #include "Batch_ListIsFullException.hxx"
46
47 namespace Batch {
48
49   // Authorized types
50   enum DiscriminatorType { BOOL, LONG, STRING, COUPLE };
51
52   class BATCH_EXPORT Versatile : public std::list< GenericType * >
53   {
54   public:
55
56     // Constructors
57     Versatile(DiscriminatorType discriminator, size_type maxsize, std::string name);
58     Versatile(const Versatile & V);
59
60     // Destructor
61     virtual ~Versatile();
62
63     // Affectation and concatenation operators from base types
64     Versatile & operator = (const long     l)    throw(TypeMismatchException);
65     Versatile & operator = (const std::string & ch)   throw(TypeMismatchException);
66     Versatile & operator +=(const std::string & ch)   throw(TypeMismatchException,ListIsFullException);
67     Versatile & operator , (const std::string & ch)   throw(TypeMismatchException,ListIsFullException);
68     Versatile & operator = (const char * ch)   throw(TypeMismatchException);
69     Versatile & operator +=(const char * ch)   throw(TypeMismatchException,ListIsFullException);
70     Versatile & operator , (const char * ch)   throw(TypeMismatchException,ListIsFullException);
71     Versatile & operator = (const Couple & cp)   throw(TypeMismatchException);
72     Versatile & operator +=(const Couple & cp)   throw(TypeMismatchException,ListIsFullException);
73     Versatile & operator , (const Couple & cp)   throw(TypeMismatchException,ListIsFullException);
74     Versatile & operator = (const int i) throw(TypeMismatchException);
75     Versatile & operator = (const bool b) throw(TypeMismatchException);
76
77     // Type conversion to base types
78     operator long() const throw(TypeMismatchException);
79     operator std::string() const throw(TypeMismatchException);
80     operator Couple() const throw(TypeMismatchException);
81     std::string str() const throw(TypeMismatchException);
82     operator bool() const throw(TypeMismatchException);
83     operator int() const throw(TypeMismatchException);
84
85     // Display on a stream
86     BATCH_EXPORT friend std::ostream & operator << (std::ostream & os, const Versatile & );
87
88     // Check the type
89     void checkType(DiscriminatorType t) const throw (TypeMismatchException);
90
91     // Getter methods
92     DiscriminatorType getType() const;
93     size_type getMaxSize() const;
94     const std::string & getName() const;
95
96     // Erase all internal elements
97     void eraseAll();
98
99   protected:
100
101     DiscriminatorType _discriminator; // Internal element type
102     size_type _maxsize; // Maximum number of internal elements
103     std::string _name; // Object name (used for exceptions)
104
105   private:
106
107     // Forbid the use of default constructor and affectation operator
108     Versatile() {}
109     void operator= (const Versatile & V) {}
110
111   };
112
113 }
114
115 #endif