1 #ifndef __TYPECODE_HXX__
2 #define __TYPECODE_HXX__
4 #include "RefCounter.hxx"
5 #include "Exception.hxx"
30 // typedef enum DynType StreamType;
34 /*! \brief Base class for all type objects.
38 * All type objects should be a subclass of TypeCode. Some type objects,
39 * TypeCodeObjref for example, represent one individual type. Other type
40 * objects, such as TypeCodeSeq, are composite types (sequence, here)
47 class TypeCode : public RefCounter
50 TypeCode(DynType kind);
53 const char * getKindRepr() const;
55 virtual TypeCode *clone() const;
56 virtual void putReprAtPlace(char *pt, const char *val, bool deepCpy) const;
57 virtual void destroyZippedAny(char *data) const;
58 virtual AnyPtr getOrBuildAnyFromZippedData(char *data) const;
59 virtual const char * name() const throw(Exception);
60 virtual const char * shortName() const;
61 virtual const char * id() const throw(Exception);
62 virtual const TypeCode * contentType() const throw(Exception);
63 virtual int isA(const char* repositoryId) const throw(Exception);
64 virtual int isA(const TypeCode* tc) const ;
65 virtual int isAdaptable(const TypeCode* tc) const;
66 virtual int isEquivalent(const TypeCode* tc) const;
67 virtual unsigned getSizeInByteOfAnyReprInSeq() const;
69 static const char *getKindRepr(DynType kind);
70 static TypeCode * interfaceTc(const char* id, const char* name);
71 static TypeCode * interfaceTc(const char* id, const char* name, const std::list<TypeCodeObjref *>& ltc);
72 static TypeCode * sequenceTc (const char* id, const char* name, TypeCode *content);
73 static TypeCode * structTc (const char* id, const char* name);
76 // --- These operators are placed here to avoid them being used externally
77 TypeCode(const TypeCode& tc);
78 TypeCode& operator=(const TypeCode& tc);
82 static const char *KIND_STR_REPR [];
85 class TypeCodeComposed : public TypeCode
88 TypeCodeComposed(const TypeCodeComposed& other);
89 TypeCodeComposed(DynType kind, const char* repositoryId, const char* name);
91 const std::string _name;
92 const std::string _repoId;
93 std::string _shortName;
97 /*! \brief Class for reference objects.
102 class TypeCodeObjref : public TypeCodeComposed
104 friend class Visitor;
106 TypeCodeObjref(const char* repositoryId, const char* name);
108 TypeCodeObjref(const char* repositoryId, const char* name, const std::list<TypeCodeObjref *>& ltc);
110 TypeCode *clone() const;
111 void putReprAtPlace(char *pt, const char *val, bool deepCpy) const;
112 void destroyZippedAny(char *data) const;
113 AnyPtr getOrBuildAnyFromZippedData(char *data) const;
114 const char * id() const throw(Exception);
115 const char * name() const throw(Exception);
116 const char * shortName() const;
117 int isA(const char* repositoryId) const throw(Exception);
118 virtual int isA(const TypeCode* tc) const ;
119 virtual int isAdaptable(const TypeCode* tc) const;
120 virtual int isEquivalent(const TypeCode* tc) const;
123 TypeCodeObjref(const TypeCodeObjref& other);
125 std::list<TypeCodeObjref *> _listOfBases;
129 /*! \brief Class for sequence objects.
134 class TypeCodeSeq: public TypeCodeComposed
137 TypeCodeSeq(const char* repositoryId, const char* name, const TypeCode *content);
139 TypeCode *clone() const;
140 void putReprAtPlace(char *pt, const char *val, bool deepCpy) const;
141 void destroyZippedAny(char *data) const;
142 virtual unsigned getSizeInByteOfAnyReprInSeq() const;
143 AnyPtr getOrBuildAnyFromZippedData(char *data) const;
144 const char * id() const throw(Exception);
145 const char * name() const throw(Exception);
146 const char * shortName() const;
148 virtual const TypeCode * contentType() const throw(Exception);
149 virtual int isA(const TypeCode* tc) const ;
150 virtual int isAdaptable(const TypeCode* tc) const;
151 virtual int isEquivalent(const TypeCode* tc) const;
154 TypeCodeSeq(const TypeCodeSeq& tc);
156 const TypeCode *_content;
159 /*! \brief Class for array objects.
164 class TypeCodeArray : public TypeCodeComposed
167 TypeCodeArray(const char* repositoryId, const char* name, const TypeCode *content, unsigned staticLgth);
168 TypeCode *clone() const;
169 void putReprAtPlace(char *pt, const char *val, bool deepCpy) const;
170 void destroyZippedAny(char *data) const;
171 AnyPtr getOrBuildAnyFromZippedData(char *data) const;
172 const char * id() const throw(Exception);
173 const char * name() const throw(Exception);
174 const char * shortName() const;
175 unsigned getStaticLgth() const;
177 virtual const TypeCode * contentType() const throw(Exception);
178 virtual int isA(const TypeCode* tc) const ;
179 virtual int isAdaptable(const TypeCode* tc) const;
180 virtual int isEquivalent(const TypeCode* tc) const;
181 unsigned getSizeInByteOfAnyReprInSeq() const;
184 TypeCodeArray(const TypeCodeArray& tc);
186 const TypeCode *_content;
187 const unsigned _staticLgth;
192 /*! \brief Class for struct type.
197 class TypeCodeStruct : public TypeCodeComposed
199 friend class StructAny;//Access to _members attribute.
201 TypeCodeStruct(const char* repositoryId, const char* name);
202 TypeCode *clone() const;
203 void putReprAtPlace(char *pt, const char *val, bool deepCpy) const;
204 void destroyZippedAny(char *data) const;
205 AnyPtr getOrBuildAnyFromZippedData(char *data) const;
206 const char * id() const throw(Exception);
207 const char * name() const throw(Exception);
208 const char * shortName() const;
209 virtual unsigned getSizeInByteOfAnyReprInSeq() const;
210 const TypeCode * contentType() const throw(Exception);
211 virtual int isA(const char* repositoryId) const throw(Exception);
212 virtual int isA(const TypeCode* tc) const ;
213 virtual int isAdaptable(const TypeCode* tc) const;
214 virtual int isEquivalent(const TypeCode* tc) const;
215 //! The only non const method.
216 virtual void addMember(const std::string& name,TypeCode* tc);
217 const TypeCode *getMember(const std::string& name, unsigned& offset) const;
218 int memberCount() const;
219 const char* memberName(int index) const;
220 TypeCode* memberType(int index) const;
223 TypeCodeStruct(const TypeCodeStruct& tc);
225 std::vector< std::pair<std::string,TypeCode*> > _members;