Salome HOME
Copyright update 2021
[tools/libbatch.git] / src / Core / Versatile.hxx
1 // Copyright (C) 2007-2021  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, or (at your option) any later version.
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 "Defines.hxx"
34
35 #include <iostream>
36 #include <list>
37 #include <string>
38 #include "GenericType.hxx"
39 #include "BoolType.hxx"
40 #include "LongType.hxx"
41 #include "StringType.hxx"
42 #include "CoupleType.hxx"
43 #include "TypeMismatchException.hxx"
44 #include "ListIsFullException.hxx"
45 #include "RunTimeException.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     // Use of default constructor is forbidden but we cannot declare it private because
61     // compilation fails with VC8 on Windows
62     Versatile() { throw RunTimeException("Forbidden constructor"); }
63
64     // Destructor
65     virtual ~Versatile();
66
67     // Affectation and concatenation operators from base types
68     Versatile & operator = (const long     l);
69     Versatile & operator = (const std::string & ch);
70     Versatile & operator +=(const std::string & ch);
71     Versatile & operator , (const std::string & ch);
72     Versatile & operator = (const char * ch);
73     Versatile & operator +=(const char * ch);
74     Versatile & operator , (const char * ch);
75     Versatile & operator = (const Couple & cp);
76     Versatile & operator +=(const Couple & cp);
77     Versatile & operator , (const Couple & cp);
78     Versatile & operator = (const int i);
79     Versatile & operator = (const bool b);
80
81     // Type conversion to base types
82     operator long() const;
83     operator std::string() const;
84     operator Couple() const;
85     std::string str() const;
86     operator bool() const;
87     operator int() const;
88
89     // Display on a stream
90     BATCH_EXPORT friend std::ostream & operator << (std::ostream & os, const Versatile & );
91
92     // Check the type
93     void checkType(DiscriminatorType t) const;
94
95     // Getter methods
96     DiscriminatorType getType() const;
97     size_type getMaxSize() const;
98     const std::string & getName() const;
99
100     // Erase all internal elements
101     void eraseAll();
102
103   protected:
104
105     DiscriminatorType _discriminator; // Internal element type
106     size_type _maxsize; // Maximum number of internal elements
107     std::string _name; // Object name (used for exceptions)
108
109   private:
110
111     // Forbid the use of assignment operator
112     void operator= (const Versatile &) {}
113
114   };
115
116 }
117
118 #endif