Salome HOME
copy tag mergefrom_BR_V0_1_CC_Salome_04oct07
[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 unsigned getSizeInByteOfAnyReprInSeq() const;
67
68       static const char *getKindRepr(DynType kind);
69       static TypeCode * interfaceTc(const char* id, const char* name);
70       static TypeCode * interfaceTc(const char* id, const char* name, const std::list<TypeCodeObjref *>& ltc);
71       static TypeCode * sequenceTc (const char* id, const char* name, TypeCode *content);
72       static TypeCode * structTc (const char* id, const char* name);
73
74     protected:
75       // --- These operators are placed here to avoid them being used externally
76       TypeCode(const TypeCode& tc);
77       TypeCode& operator=(const TypeCode& tc);
78       virtual ~TypeCode();
79     protected:
80       DynType _kind;
81       static const char *KIND_STR_REPR [];
82     };
83
84
85 /*! \brief Class for reference objects.
86  *
87  * \ingroup TypeCodes
88  *
89  */
90     class TypeCodeObjref: public TypeCode
91     {
92       friend class Visitor;
93     public:
94       TypeCodeObjref(const char* repositoryId, const char* name);
95
96       TypeCodeObjref(const char* repositoryId, const char* name, const std::list<TypeCodeObjref *>& ltc);
97
98       TypeCode *clone() const;
99       void putReprAtPlace(char *pt, const char *val, bool deepCpy) const;
100       void destroyZippedAny(char *data) const;
101       AnyPtr getOrBuildAnyFromZippedData(char *data) const;
102       const char * id() const   throw(Exception);
103       const char * name() const throw(Exception);
104       const char * shortName() const;
105       int isA(const char* repositoryId) const throw(Exception);
106       virtual int isA(const TypeCode* tc) const ;
107       virtual int isAdaptable(const TypeCode* tc) const;
108     protected:
109       ~TypeCodeObjref();
110       TypeCodeObjref(const TypeCodeObjref& other);
111     private:
112       std::string _name;
113       std::string _shortName;
114       std::string _repoId;
115       std::list<TypeCodeObjref *> _listOfBases;
116     };
117
118
119 /*! \brief Class for sequence objects.
120  *
121  * \ingroup TypeCodes
122  *
123  */
124     class TypeCodeSeq: public TypeCode
125     {
126     public:
127       TypeCodeSeq(const char* repositoryId, const char* name, const TypeCode *content);
128
129       TypeCode *clone() const;
130       void putReprAtPlace(char *pt, const char *val, bool deepCpy) const;
131       void destroyZippedAny(char *data) const;
132       AnyPtr getOrBuildAnyFromZippedData(char *data) const;
133       const char * id()   const throw(Exception);
134       const char * name() const throw(Exception);
135       const char * shortName() const;
136
137       virtual const TypeCode * contentType() const throw(Exception);
138       virtual int isA(const TypeCode* tc) const ;
139       virtual int isAdaptable(const TypeCode* tc) const;
140     protected:
141       ~TypeCodeSeq();
142       TypeCodeSeq(const TypeCodeSeq& tc);
143     private:
144       std::string _name;
145       std::string _shortName;
146       std::string _repoId;
147       const TypeCode  *_content;
148     };
149
150 /*! \brief Class for array objects.
151  *
152  * \ingroup TypeCodes
153  *
154  */
155     class TypeCodeArray : public TypeCode
156     {
157     public:
158       TypeCodeArray(const char* repositoryId, const char* name, const TypeCode *content, unsigned staticLgth);
159       TypeCode *clone() const;
160       void putReprAtPlace(char *pt, const char *val, bool deepCpy) const;
161       void destroyZippedAny(char *data) const;
162       AnyPtr getOrBuildAnyFromZippedData(char *data) const;
163       const char * id()   const throw(Exception);
164       const char * name() const throw(Exception);
165       const char * shortName() const;
166       unsigned getStaticLgth() const;
167
168       virtual const TypeCode * contentType() const throw(Exception);
169       virtual int isA(const TypeCode* tc) const ;
170       virtual int isAdaptable(const TypeCode* tc) const;
171       unsigned getSizeInByteOfAnyReprInSeq() const;
172     protected:
173       ~TypeCodeArray();
174       TypeCodeArray(const TypeCodeArray& tc);
175     private:
176       std::string _name;
177       std::string _shortName;
178       std::string _repoId;
179       unsigned _staticLgth;
180       const TypeCode  *_content;
181     };
182
183 /*! \brief Class for struct type.
184  *
185  * \ingroup TypeCodes
186  *
187  */
188     class TypeCodeStruct : public TypeCode
189     {
190     public:
191       TypeCodeStruct(const char* repositoryId, const char* name);
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       virtual int isA(const char* repositoryId) const throw(Exception);
200       virtual int isA(const TypeCode* tc) const ;
201       virtual int isAdaptable(const TypeCode* tc) const;
202       virtual void addMember(const std::string& name,TypeCode* tc);
203       int memberCount() const;
204       const char*  memberName(int index) const;
205       TypeCode*  memberType(int index) const;
206     protected:
207       ~TypeCodeStruct();
208       TypeCodeStruct(const TypeCodeStruct& tc);
209     private:
210       std::string _name;
211       std::string _shortName;
212       std::string _repoId;
213       std::vector< std::pair<std::string,TypeCode*> > _members;
214     };
215
216   }
217 }
218 #endif