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;
74 const TypeCode *subContentType(int lev) 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;
88 virtual std::string getPrintStr() const;
90 static const char *getKindRepr(DynType kind);
91 static TypeCode * interfaceTc(const char* id, const char* name);
92 static TypeCode * interfaceTc(const char* id, const char* name, const std::list<TypeCodeObjref *>& ltc);
93 static TypeCode * sequenceTc (const char* id, const char* name, TypeCode *content);
94 static TypeCode * structTc (const char* id, const char* name);
97 // --- These operators are placed here to avoid them being used externally
98 TypeCode(const TypeCode& tc);
99 TypeCode& operator=(const TypeCode& tc);
105 static const char *KIND_STR_REPR [];
108 class YACSLIBENGINE_EXPORT TypeCodeComposed : public TypeCode
111 TypeCodeComposed(const TypeCodeComposed& other);
112 TypeCodeComposed(DynType kind, const char* repositoryId, const char* name);
114 const std::string _name;
115 const std::string _repoId;
116 std::string _shortName;
120 /*! \brief Class for reference objects.
125 class YACSLIBENGINE_EXPORT TypeCodeObjref : public TypeCodeComposed
127 friend class Visitor;
129 TypeCodeObjref(const char* repositoryId, const char* name);
131 TypeCodeObjref(const char* repositoryId, const char* name, const std::list<TypeCodeObjref *>& ltc);
133 TypeCode *clone() const;
134 void putReprAtPlace(char *pt, const char *val, bool deepCpy) const;
135 void destroyZippedAny(char *data) const;
136 AnyPtr getOrBuildAnyFromZippedData(char *data) const;
137 const char * id() const throw(Exception);
138 const char * name() const throw(Exception);
139 const char * shortName() const;
140 int isA(const char* repositoryId) const throw(Exception);
141 virtual int isA(const TypeCode* tc) const ;
142 virtual int isAdaptable(const TypeCode* tc) const;
143 virtual int isEquivalent(const TypeCode* tc) const;
146 virtual ~TypeCodeObjref();
148 TypeCodeObjref(const TypeCodeObjref& other);
150 std::list<TypeCodeObjref *> _listOfBases;
154 /*! \brief Class for sequence objects.
159 class YACSLIBENGINE_EXPORT TypeCodeSeq: public TypeCodeComposed
162 TypeCodeSeq(const char* repositoryId, const char* name, const TypeCode *content);
164 TypeCode *clone() const;
165 void putReprAtPlace(char *pt, const char *val, bool deepCpy) const;
166 void destroyZippedAny(char *data) const;
167 virtual unsigned getSizeInByteOfAnyReprInSeq() const;
168 AnyPtr getOrBuildAnyFromZippedData(char *data) const;
169 const char * id() const throw(Exception);
170 const char * name() const throw(Exception);
171 const char * shortName() const;
172 virtual std::string getPrintStr() const;
174 virtual const TypeCode * contentType() const throw(Exception);
175 virtual int isA(const TypeCode* tc) const ;
176 virtual int isAdaptable(const TypeCode* tc) const;
177 virtual int isEquivalent(const TypeCode* tc) const;
180 virtual ~TypeCodeSeq();
182 TypeCodeSeq(const TypeCodeSeq& tc);
184 const TypeCode *_content;
187 /*! \brief Class for array objects.
192 class YACSLIBENGINE_EXPORT TypeCodeArray : public TypeCodeComposed
195 TypeCodeArray(const char* repositoryId, const char* name, const TypeCode *content, unsigned staticLgth);
196 TypeCode *clone() const;
197 void putReprAtPlace(char *pt, const char *val, bool deepCpy) const;
198 void destroyZippedAny(char *data) const;
199 AnyPtr getOrBuildAnyFromZippedData(char *data) const;
200 const char * id() const throw(Exception);
201 const char * name() const throw(Exception);
202 const char * shortName() const;
203 unsigned getStaticLgth() const;
205 virtual const TypeCode * contentType() const throw(Exception);
206 virtual int isA(const TypeCode* tc) const ;
207 virtual int isAdaptable(const TypeCode* tc) const;
208 virtual int isEquivalent(const TypeCode* tc) const;
209 unsigned getSizeInByteOfAnyReprInSeq() const;
212 virtual ~TypeCodeArray();
214 TypeCodeArray(const TypeCodeArray& tc);
216 const TypeCode *_content;
217 const unsigned _staticLgth;
222 /*! \brief Class for struct type.
227 class YACSLIBENGINE_EXPORT TypeCodeStruct : public TypeCodeComposed
229 friend class StructAny;//Access to _members attribute.
231 TypeCodeStruct(const char* repositoryId, const char* name);
232 TypeCode *clone() const;
233 void putReprAtPlace(char *pt, const char *val, bool deepCpy) const;
234 void destroyZippedAny(char *data) const;
235 AnyPtr getOrBuildAnyFromZippedData(char *data) const;
236 const char * id() const throw(Exception);
237 const char * name() const throw(Exception);
238 const char * shortName() const;
239 virtual unsigned getSizeInByteOfAnyReprInSeq() const;
240 const TypeCode * contentType() const throw(Exception);
241 virtual int isA(const char* repositoryId) const throw(Exception);
242 virtual int isA(const TypeCode* tc) const ;
243 virtual int isAdaptable(const TypeCode* tc) const;
244 virtual int isEquivalent(const TypeCode* tc) const;
245 //! The only non const method.
246 virtual void addMember(const std::string& name,TypeCode* tc);
247 const TypeCode *getMember(const std::string& name, unsigned& offset) const;
248 int memberCount() const;
249 const char* memberName(int index) const;
250 TypeCode* memberType(int index) const;
253 virtual ~TypeCodeStruct();
255 TypeCodeStruct(const TypeCodeStruct& tc);
257 std::vector< std::pair<std::string,TypeCode*> > _members;