]> SALOME platform Git repositories - modules/yacs.git/blob - src/engine/TypeCode.hxx
Salome HOME
1cdd434e75d4789764d031f279e3202b2340b680
[modules/yacs.git] / src / engine / TypeCode.hxx
1 #ifndef __TYPECODE_HXX__
2 #define __TYPECODE_HXX__
3
4 #include "RefCounter.hxx"
5 #include "Exception.hxx"
6 #include "Any.hxx"
7
8 #include <string>
9 #include <list>
10
11 namespace YACS
12 {
13   namespace ENGINE
14   {
15     class Visitor;
16
17     typedef enum
18       {
19         NONE     = 0,
20         Double   = 1,
21         Int      = 2,
22         String   = 3,
23         Bool     = 4,
24         Objref   = 5,
25         Sequence = 6,
26         Array    = 7,
27         Struct   = 8
28       } DynType;
29
30 //     typedef enum DynType StreamType;
31
32     class TypeCodeObjref;
33
34 /*! \brief Base class for all type objects.
35  *
36  * \ingroup TypeCodes
37  *
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)
41  *
42  * \see TypeCodeObjref
43  * \see TypeCodeSeq
44  * \see TypeCodeStruct
45  * \see TypeCodeArray
46  */
47     class TypeCode : public RefCounter
48     {
49     public:
50       TypeCode(DynType kind);
51
52       DynType kind() const;
53       const char * getKindRepr() const;
54       
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;
68
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);
74
75     protected:
76       // --- These operators are placed here to avoid them being used externally
77       TypeCode(const TypeCode& tc);
78       TypeCode& operator=(const TypeCode& tc);
79       virtual ~TypeCode();
80     protected:
81       const DynType _kind;
82       static const char *KIND_STR_REPR [];
83     };
84
85     class TypeCodeComposed : public TypeCode
86     {
87     protected:
88       TypeCodeComposed(const TypeCodeComposed& other);
89       TypeCodeComposed(DynType kind, const char* repositoryId, const char* name);
90     protected:
91       const std::string _name;
92       const std::string _repoId;
93       std::string _shortName;
94     };
95
96
97 /*! \brief Class for reference objects.
98  *
99  * \ingroup TypeCodes
100  *
101  */
102     class TypeCodeObjref : public TypeCodeComposed
103     {
104       friend class Visitor;
105     public:
106       TypeCodeObjref(const char* repositoryId, const char* name);
107
108       TypeCodeObjref(const char* repositoryId, const char* name, const std::list<TypeCodeObjref *>& ltc);
109
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;
121     protected:
122       ~TypeCodeObjref();
123       TypeCodeObjref(const TypeCodeObjref& other);
124     private:
125       std::list<TypeCodeObjref *> _listOfBases;
126     };
127
128
129 /*! \brief Class for sequence objects.
130  *
131  * \ingroup TypeCodes
132  *
133  */
134     class TypeCodeSeq: public TypeCodeComposed
135     {
136     public:
137       TypeCodeSeq(const char* repositoryId, const char* name, const TypeCode *content);
138
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;
147
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;
152     protected:
153       ~TypeCodeSeq();
154       TypeCodeSeq(const TypeCodeSeq& tc);
155     private:
156       const TypeCode  *_content;
157     };
158
159 /*! \brief Class for array objects.
160  *
161  * \ingroup TypeCodes
162  *
163  */
164     class TypeCodeArray : public TypeCodeComposed
165     {
166     public:
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;
176
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;
182     protected:
183       ~TypeCodeArray();
184       TypeCodeArray(const TypeCodeArray& tc);
185     private:
186       const TypeCode  *_content;
187       const unsigned _staticLgth;
188     };
189
190     class StructAny;
191
192 /*! \brief Class for struct type.
193  *
194  * \ingroup TypeCodes
195  *
196  */
197     class TypeCodeStruct : public TypeCodeComposed
198     {
199       friend class StructAny;//Access to _members attribute.
200     public:
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;
221     protected:
222       ~TypeCodeStruct();
223       TypeCodeStruct(const TypeCodeStruct& tc);
224     private:
225       std::vector< std::pair<std::string,TypeCode*> > _members;
226     };
227
228   }
229 }
230 #endif