Salome HOME
PR: merge from BR_DATACONV_PR tag "mergeto_trunk_25oct06"
[modules/yacs.git] / src / engine / TypeCode.cxx
1
2 #include "TypeCode.hxx"
3
4 using namespace YACS::ENGINE;
5 using namespace std;
6
7 // --- TypeCode
8
9 TypeCode::TypeCode(DynType kind)
10 {
11   _kind=kind;
12 }
13
14 TypeCode::~TypeCode()
15 {
16 }
17
18 DynType TypeCode::kind() const
19 {
20   return _kind;
21 }
22
23 const char * TypeCode::name() const throw(Exception)
24 {
25   throw Exception("No name");
26 }
27
28
29 const char * TypeCode::id() const throw(Exception)
30 {
31   switch(_kind)
32     {
33     case Double:
34       return "Double";
35     case Int:
36       return "Int";
37     case String:
38       return "String";
39     default:
40       return "";
41     }
42 }
43
44 int TypeCode::is_a(const char* id)
45 {
46   throw Exception("Not implemented for this type");
47 }
48
49 int TypeCode::is_a(TypeCode* tc)
50 {
51   if(_kind == tc->kind()) return 1;
52   return 0;
53 }
54
55 TypeCode * TypeCode::content_type() const throw(Exception)
56 {
57   throw Exception("No content type");
58 };
59
60 /**
61  * static factory of object reference types
62  */
63
64 TypeCode * TypeCode::interface_tc(const char* id,
65                                   const char* name)
66 {
67   return new TypeCode_objref(id, name);
68 };
69
70 TypeCode * TypeCode::interface_tc(const char* id,
71                                   const char* name,
72                                   list<TypeCode_objref *> ltc)
73 {
74   return new TypeCode_objref(id, name,ltc);
75 }
76
77
78 /**
79  * static factory of sequence types
80  */
81
82 TypeCode * TypeCode::sequence_tc(const char* id,
83                                  const char* name,
84                                  TypeCode *content)
85 {
86   return new TypeCode_seq(id, name,content);
87 };
88
89
90 // --- TypeCode_objref
91
92
93 TypeCode_objref::TypeCode_objref(const char* repositoryId, 
94                                  const char* name)
95   : TypeCode(Objref)
96 {
97   _repoId = repositoryId;
98   _name = name;
99 }
100
101
102 TypeCode_objref::~TypeCode_objref()
103 {
104 }
105
106 const char * TypeCode_objref::id() const throw(Exception)
107 {
108   return _repoId.c_str();
109 };
110
111 const char * TypeCode_objref::name() const throw(Exception)
112 {
113   return _name.c_str();
114 }
115
116 TypeCode_objref::TypeCode_objref(const char* repositoryId,
117                                  const char* name,
118                                  list<TypeCode_objref *> ltc)
119   : TypeCode(Objref)
120 {
121   _repoId = repositoryId;
122   _name = name;
123   _listOfBases=ltc;
124 }
125
126 int TypeCode_objref::is_a(const char* id) throw(Exception)
127 {
128   if(_repoId.c_str() == id)return 1;
129   list<TypeCode_objref *>::iterator iter;
130   for(iter=_listOfBases.begin();iter != _listOfBases.end(); iter++)
131     {
132       if ((*iter)->is_a(id)) return 1;
133     }
134   return 0;
135 }
136
137 int TypeCode_objref::is_a(TypeCode* tc) throw(Exception)
138 {
139   return is_a(tc->id());
140 }
141
142 // --- TypeCode_seq
143
144
145 TypeCode_seq::TypeCode_seq(const char* repositoryId,
146                            const char* name, 
147                            TypeCode *content)
148   : TypeCode(Sequence)
149 {
150   _repoId = repositoryId;
151   _name = name;
152   _content= content;
153 }
154
155 TypeCode_seq::~TypeCode_seq()
156 {
157 }
158
159 const char * TypeCode_seq::id() const throw(Exception)
160 {
161   return _repoId.c_str();
162 }
163
164 const char * TypeCode_seq::name() const throw(Exception)
165 {
166   return _name.c_str();
167 }
168
169 TypeCode * TypeCode_seq::content_type() const throw(Exception)
170 {
171   return _content;
172 }
173
174 int TypeCode_seq::is_a(TypeCode* tc)
175 {
176   if(_kind == tc->kind())
177     {
178       if(_content->is_a(tc->content_type())) return 1;
179     }
180   return 0;
181 }