Salome HOME
Merge branch V7_3_1_BR
[modules/yacs.git] / src / engine / TypeCode.hxx
1 // Copyright (C) 2006-2014  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef __TYPECODE_HXX__
21 #define __TYPECODE_HXX__
22
23 #include "YACSlibEngineExport.hxx"
24 #include "RefCounter.hxx"
25 #include "Exception.hxx"
26 #include "Any.hxx"
27
28 #include <string>
29 #include <list>
30
31 namespace YACS
32 {
33   namespace ENGINE
34   {
35     class Visitor;
36
37     typedef enum
38       {
39         NONE     = 0,
40         Double   = 1,
41         Int      = 2,
42         String   = 3,
43         Bool     = 4,
44         Objref   = 5,
45         Sequence = 6,
46         Array    = 7,
47         Struct   = 8
48       } DynType;
49
50 //     typedef enum DynType StreamType;
51
52     class TypeCodeObjref;
53
54 /*! \brief Base class for all type objects.
55  *
56  * \ingroup TypeCodes
57  *
58  * All type objects should be a subclass of TypeCode.  Some type objects,
59  * TypeCodeObjref for example, represent one individual type.  Other type
60  * objects, such as TypeCodeSeq, are composite types (sequence, here)
61  *
62  * \see TypeCodeObjref
63  * \see TypeCodeSeq
64  * \see TypeCodeStruct
65  * \see TypeCodeArray
66  */
67     class YACSLIBENGINE_EXPORT TypeCode : public RefCounter
68     {
69     public:
70       TypeCode(DynType kind);
71
72       DynType kind() const;
73       const char * getKindRepr() const;
74       
75       virtual TypeCode *clone() const;
76       virtual void putReprAtPlace(char *pt, const char *val, bool deepCpy) const;
77       virtual void destroyZippedAny(char *data) const;
78       virtual AnyPtr getOrBuildAnyFromZippedData(char *data) const;
79       virtual const char * name()       const throw(Exception);
80       virtual const char * shortName()  const;
81       virtual const char * id()         const throw(Exception);
82       virtual const TypeCode * contentType() const throw(Exception);
83       virtual int isA(const char* repositoryId) const throw(Exception);
84       virtual int isA(const TypeCode* tc) const ;
85       virtual int isAdaptable(const TypeCode* tc) const;
86       virtual int isEquivalent(const TypeCode* tc) const;
87       virtual unsigned getSizeInByteOfAnyReprInSeq() const;
88
89       static const char *getKindRepr(DynType kind);
90       static TypeCode * interfaceTc(const char* id, const char* name);
91       static TypeCode * interfaceTc(const char* id, const char* name, const std::list<TypeCodeObjref *>& ltc);
92       static TypeCode * sequenceTc (const char* id, const char* name, TypeCode *content);
93       static TypeCode * structTc (const char* id, const char* name);
94
95     protected:
96       // --- These operators are placed here to avoid them being used externally
97       TypeCode(const TypeCode& tc);
98       TypeCode& operator=(const TypeCode& tc);
99 #ifndef SWIG
100       virtual ~TypeCode();
101 #endif
102     protected:
103       const DynType _kind;
104       static const char *KIND_STR_REPR [];
105     };
106
107     class YACSLIBENGINE_EXPORT TypeCodeComposed : public TypeCode
108     {
109     protected:
110       TypeCodeComposed(const TypeCodeComposed& other);
111       TypeCodeComposed(DynType kind, const char* repositoryId, const char* name);
112     protected:
113       const std::string _name;
114       const std::string _repoId;
115       std::string _shortName;
116     };
117
118
119 /*! \brief Class for reference objects.
120  *
121  * \ingroup TypeCodes
122  *
123  */
124     class YACSLIBENGINE_EXPORT TypeCodeObjref : public TypeCodeComposed
125     {
126       friend class Visitor;
127     public:
128       TypeCodeObjref(const char* repositoryId, const char* name);
129
130       TypeCodeObjref(const char* repositoryId, const char* name, const std::list<TypeCodeObjref *>& ltc);
131
132       TypeCode *clone() const;
133       void putReprAtPlace(char *pt, const char *val, bool deepCpy) const;
134       void destroyZippedAny(char *data) const;
135       AnyPtr getOrBuildAnyFromZippedData(char *data) const;
136       const char * id() const   throw(Exception);
137       const char * name() const throw(Exception);
138       const char * shortName() const;
139       int isA(const char* repositoryId) const throw(Exception);
140       virtual int isA(const TypeCode* tc) const ;
141       virtual int isAdaptable(const TypeCode* tc) const;
142       virtual int isEquivalent(const TypeCode* tc) const;
143     protected:
144 #ifndef SWIG
145       virtual ~TypeCodeObjref();
146 #endif
147       TypeCodeObjref(const TypeCodeObjref& other);
148     private:
149       std::list<TypeCodeObjref *> _listOfBases;
150     };
151
152
153 /*! \brief Class for sequence objects.
154  *
155  * \ingroup TypeCodes
156  *
157  */
158     class YACSLIBENGINE_EXPORT TypeCodeSeq: public TypeCodeComposed
159     {
160     public:
161       TypeCodeSeq(const char* repositoryId, const char* name, const TypeCode *content);
162
163       TypeCode *clone() const;
164       void putReprAtPlace(char *pt, const char *val, bool deepCpy) const;
165       void destroyZippedAny(char *data) const;
166       virtual unsigned getSizeInByteOfAnyReprInSeq() const;
167       AnyPtr getOrBuildAnyFromZippedData(char *data) const;
168       const char * id()   const throw(Exception);
169       const char * name() const throw(Exception);
170       const char * shortName() const;
171
172       virtual const TypeCode * contentType() const throw(Exception);
173       virtual int isA(const TypeCode* tc) const ;
174       virtual int isAdaptable(const TypeCode* tc) const;
175       virtual int isEquivalent(const TypeCode* tc) const;
176     protected:
177 #ifndef SWIG
178       virtual ~TypeCodeSeq();
179 #endif
180       TypeCodeSeq(const TypeCodeSeq& tc);
181     private:
182       const TypeCode  *_content;
183     };
184
185 /*! \brief Class for array objects.
186  *
187  * \ingroup TypeCodes
188  *
189  */
190     class YACSLIBENGINE_EXPORT TypeCodeArray : public TypeCodeComposed
191     {
192     public:
193       TypeCodeArray(const char* repositoryId, const char* name, const TypeCode *content, unsigned staticLgth);
194       TypeCode *clone() const;
195       void putReprAtPlace(char *pt, const char *val, bool deepCpy) const;
196       void destroyZippedAny(char *data) const;
197       AnyPtr getOrBuildAnyFromZippedData(char *data) const;
198       const char * id()   const throw(Exception);
199       const char * name() const throw(Exception);
200       const char * shortName() const;
201       unsigned getStaticLgth() const;
202
203       virtual const TypeCode * contentType() const throw(Exception);
204       virtual int isA(const TypeCode* tc) const ;
205       virtual int isAdaptable(const TypeCode* tc) const;
206       virtual int isEquivalent(const TypeCode* tc) const;
207       unsigned getSizeInByteOfAnyReprInSeq() const;
208     protected:
209 #ifndef SWIG
210       virtual ~TypeCodeArray();
211 #endif
212       TypeCodeArray(const TypeCodeArray& tc);
213     private:
214       const TypeCode  *_content;
215       const unsigned _staticLgth;
216     };
217
218     class StructAny;
219
220 /*! \brief Class for struct type.
221  *
222  * \ingroup TypeCodes
223  *
224  */
225     class YACSLIBENGINE_EXPORT TypeCodeStruct : public TypeCodeComposed
226     {
227       friend class StructAny;//Access to _members attribute.
228     public:
229       TypeCodeStruct(const char* repositoryId, const char* name);
230       TypeCode *clone() const;
231       void putReprAtPlace(char *pt, const char *val, bool deepCpy) const;
232       void destroyZippedAny(char *data) const;
233       AnyPtr getOrBuildAnyFromZippedData(char *data) const;
234       const char * id() const   throw(Exception);
235       const char * name() const throw(Exception);
236       const char * shortName() const;
237       virtual unsigned getSizeInByteOfAnyReprInSeq() const;
238       const TypeCode * contentType() const throw(Exception);
239       virtual int isA(const char* repositoryId) const throw(Exception);
240       virtual int isA(const TypeCode* tc) const ;
241       virtual int isAdaptable(const TypeCode* tc) const;
242       virtual int isEquivalent(const TypeCode* tc) const;
243       //! The only non const method.
244       virtual void addMember(const std::string& name,TypeCode* tc);
245       const TypeCode *getMember(const std::string& name, unsigned& offset) const;
246       int memberCount() const;
247       const char*  memberName(int index) const;
248       TypeCode*  memberType(int index) const;
249     protected:
250 #ifndef SWIG
251       virtual ~TypeCodeStruct();
252 #endif
253       TypeCodeStruct(const TypeCodeStruct& tc);
254     private:
255       std::vector< std::pair<std::string,TypeCode*> > _members;
256     };
257
258   }
259 }
260 #endif