1 // Copyright (C) 2006-2016 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef __TYPECODE_HXX__
21 #define __TYPECODE_HXX__
23 #include "YACSlibEngineExport.hxx"
24 #include "RefCounter.hxx"
25 #include "Exception.hxx"
50 // typedef enum DynType StreamType;
54 /*! \brief Base class for all type objects.
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)
67 class YACSLIBENGINE_EXPORT TypeCode : public RefCounter
70 TypeCode(DynType kind);
73 const char * getKindRepr() const;
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;
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);
96 // --- These operators are placed here to avoid them being used externally
97 TypeCode(const TypeCode& tc);
98 TypeCode& operator=(const TypeCode& tc);
104 static const char *KIND_STR_REPR [];
107 class YACSLIBENGINE_EXPORT TypeCodeComposed : public TypeCode
110 TypeCodeComposed(const TypeCodeComposed& other);
111 TypeCodeComposed(DynType kind, const char* repositoryId, const char* name);
113 const std::string _name;
114 const std::string _repoId;
115 std::string _shortName;
119 /*! \brief Class for reference objects.
124 class YACSLIBENGINE_EXPORT TypeCodeObjref : public TypeCodeComposed
126 friend class Visitor;
128 TypeCodeObjref(const char* repositoryId, const char* name);
130 TypeCodeObjref(const char* repositoryId, const char* name, const std::list<TypeCodeObjref *>& ltc);
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;
145 virtual ~TypeCodeObjref();
147 TypeCodeObjref(const TypeCodeObjref& other);
149 std::list<TypeCodeObjref *> _listOfBases;
153 /*! \brief Class for sequence objects.
158 class YACSLIBENGINE_EXPORT TypeCodeSeq: public TypeCodeComposed
161 TypeCodeSeq(const char* repositoryId, const char* name, const TypeCode *content);
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;
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;
178 virtual ~TypeCodeSeq();
180 TypeCodeSeq(const TypeCodeSeq& tc);
182 const TypeCode *_content;
185 /*! \brief Class for array objects.
190 class YACSLIBENGINE_EXPORT TypeCodeArray : public TypeCodeComposed
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;
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;
210 virtual ~TypeCodeArray();
212 TypeCodeArray(const TypeCodeArray& tc);
214 const TypeCode *_content;
215 const unsigned _staticLgth;
220 /*! \brief Class for struct type.
225 class YACSLIBENGINE_EXPORT TypeCodeStruct : public TypeCodeComposed
227 friend class StructAny;//Access to _members attribute.
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;
251 virtual ~TypeCodeStruct();
253 TypeCodeStruct(const TypeCodeStruct& tc);
255 std::vector< std::pair<std::string,TypeCode*> > _members;