1 // Copyright (C) 2006-2008 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.
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
19 #ifndef __TYPECODE_HXX__
20 #define __TYPECODE_HXX__
22 #include "RefCounter.hxx"
23 #include "Exception.hxx"
48 // typedef enum DynType StreamType;
52 /*! \brief Base class for all type objects.
56 * All type objects should be a subclass of TypeCode. Some type objects,
57 * TypeCodeObjref for example, represent one individual type. Other type
58 * objects, such as TypeCodeSeq, are composite types (sequence, here)
65 class TypeCode : public RefCounter
68 TypeCode(DynType kind);
71 const char * getKindRepr() const;
73 virtual TypeCode *clone() const;
74 virtual void putReprAtPlace(char *pt, const char *val, bool deepCpy) const;
75 virtual void destroyZippedAny(char *data) const;
76 virtual AnyPtr getOrBuildAnyFromZippedData(char *data) const;
77 virtual const char * name() const throw(Exception);
78 virtual const char * shortName() const;
79 virtual const char * id() const throw(Exception);
80 virtual const TypeCode * contentType() const throw(Exception);
81 virtual int isA(const char* repositoryId) const throw(Exception);
82 virtual int isA(const TypeCode* tc) const ;
83 virtual int isAdaptable(const TypeCode* tc) const;
84 virtual int isEquivalent(const TypeCode* tc) const;
85 virtual unsigned getSizeInByteOfAnyReprInSeq() const;
87 static const char *getKindRepr(DynType kind);
88 static TypeCode * interfaceTc(const char* id, const char* name);
89 static TypeCode * interfaceTc(const char* id, const char* name, const std::list<TypeCodeObjref *>& ltc);
90 static TypeCode * sequenceTc (const char* id, const char* name, TypeCode *content);
91 static TypeCode * structTc (const char* id, const char* name);
94 // --- These operators are placed here to avoid them being used externally
95 TypeCode(const TypeCode& tc);
96 TypeCode& operator=(const TypeCode& tc);
102 static const char *KIND_STR_REPR [];
105 class TypeCodeComposed : public TypeCode
108 TypeCodeComposed(const TypeCodeComposed& other);
109 TypeCodeComposed(DynType kind, const char* repositoryId, const char* name);
111 const std::string _name;
112 const std::string _repoId;
113 std::string _shortName;
117 /*! \brief Class for reference objects.
122 class TypeCodeObjref : public TypeCodeComposed
124 friend class Visitor;
126 TypeCodeObjref(const char* repositoryId, const char* name);
128 TypeCodeObjref(const char* repositoryId, const char* name, const std::list<TypeCodeObjref *>& ltc);
130 TypeCode *clone() const;
131 void putReprAtPlace(char *pt, const char *val, bool deepCpy) const;
132 void destroyZippedAny(char *data) const;
133 AnyPtr getOrBuildAnyFromZippedData(char *data) const;
134 const char * id() const throw(Exception);
135 const char * name() const throw(Exception);
136 const char * shortName() const;
137 int isA(const char* repositoryId) const throw(Exception);
138 virtual int isA(const TypeCode* tc) const ;
139 virtual int isAdaptable(const TypeCode* tc) const;
140 virtual int isEquivalent(const TypeCode* tc) const;
143 virtual ~TypeCodeObjref();
145 TypeCodeObjref(const TypeCodeObjref& other);
147 std::list<TypeCodeObjref *> _listOfBases;
151 /*! \brief Class for sequence objects.
156 class TypeCodeSeq: public TypeCodeComposed
159 TypeCodeSeq(const char* repositoryId, const char* name, const TypeCode *content);
161 TypeCode *clone() const;
162 void putReprAtPlace(char *pt, const char *val, bool deepCpy) const;
163 void destroyZippedAny(char *data) const;
164 virtual unsigned getSizeInByteOfAnyReprInSeq() const;
165 AnyPtr getOrBuildAnyFromZippedData(char *data) const;
166 const char * id() const throw(Exception);
167 const char * name() const throw(Exception);
168 const char * shortName() const;
170 virtual const TypeCode * contentType() const throw(Exception);
171 virtual int isA(const TypeCode* tc) const ;
172 virtual int isAdaptable(const TypeCode* tc) const;
173 virtual int isEquivalent(const TypeCode* tc) const;
176 virtual ~TypeCodeSeq();
178 TypeCodeSeq(const TypeCodeSeq& tc);
180 const TypeCode *_content;
183 /*! \brief Class for array objects.
188 class TypeCodeArray : public TypeCodeComposed
191 TypeCodeArray(const char* repositoryId, const char* name, const TypeCode *content, unsigned staticLgth);
192 TypeCode *clone() const;
193 void putReprAtPlace(char *pt, const char *val, bool deepCpy) const;
194 void destroyZippedAny(char *data) const;
195 AnyPtr getOrBuildAnyFromZippedData(char *data) const;
196 const char * id() const throw(Exception);
197 const char * name() const throw(Exception);
198 const char * shortName() const;
199 unsigned getStaticLgth() const;
201 virtual const TypeCode * contentType() const throw(Exception);
202 virtual int isA(const TypeCode* tc) const ;
203 virtual int isAdaptable(const TypeCode* tc) const;
204 virtual int isEquivalent(const TypeCode* tc) const;
205 unsigned getSizeInByteOfAnyReprInSeq() const;
208 virtual ~TypeCodeArray();
210 TypeCodeArray(const TypeCodeArray& tc);
212 const TypeCode *_content;
213 const unsigned _staticLgth;
218 /*! \brief Class for struct type.
223 class TypeCodeStruct : public TypeCodeComposed
225 friend class StructAny;//Access to _members attribute.
227 TypeCodeStruct(const char* repositoryId, const char* name);
228 TypeCode *clone() const;
229 void putReprAtPlace(char *pt, const char *val, bool deepCpy) const;
230 void destroyZippedAny(char *data) const;
231 AnyPtr getOrBuildAnyFromZippedData(char *data) const;
232 const char * id() const throw(Exception);
233 const char * name() const throw(Exception);
234 const char * shortName() const;
235 virtual unsigned getSizeInByteOfAnyReprInSeq() const;
236 const TypeCode * contentType() const throw(Exception);
237 virtual int isA(const char* repositoryId) const throw(Exception);
238 virtual int isA(const TypeCode* tc) const ;
239 virtual int isAdaptable(const TypeCode* tc) const;
240 virtual int isEquivalent(const TypeCode* tc) const;
241 //! The only non const method.
242 virtual void addMember(const std::string& name,TypeCode* tc);
243 const TypeCode *getMember(const std::string& name, unsigned& offset) const;
244 int memberCount() const;
245 const char* memberName(int index) const;
246 TypeCode* memberType(int index) const;
249 virtual ~TypeCodeStruct();
251 TypeCodeStruct(const TypeCodeStruct& tc);
253 std::vector< std::pair<std::string,TypeCode*> > _members;