OSDN Git Service

FIRST REPOSITORY
[eos/hostdependOTHERS.git] / I386LINUX / util / I386LINUX / include / mico / typecode.h
1 // -*- c++ -*-
2 /*
3  *  MICO --- an Open Source CORBA implementation
4  *  Copyright (c) 1997-2001 by The Mico Team
5  *
6  *  This library is free software; you can redistribute it and/or
7  *  modify it under the terms of the GNU Library General Public
8  *  License as published by the Free Software Foundation; either
9  *  version 2 of the License, or (at your option) any later version.
10  *
11  *  This library is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  *  Library General Public License for more details.
15  *
16  *  You should have received a copy of the GNU Library General Public
17  *  License along with this library; if not, write to the Free
18  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  *  For more information, visit the MICO Home Page at
21  *  http://www.mico.org/
22  */
23
24 #ifndef __mico_typecode_h__
25 #define __mico_typecode_h__
26
27 namespace CORBA {
28
29 class TypeCode : public ServerlessObject {
30     TCKind tckind;
31     std::string repoid;
32     std::string tcname;
33     std::vector<std::string> namevec;
34     std::vector<TypeCode_ptr> tcvec;
35     std::vector<Any *> labelvec;
36     std::vector<Visibility> visvec;
37     TypeCode_ptr content;
38     TypeCode_ptr discriminator;
39     TypeCode_ptr recurse_tc;
40     Long defidx;
41     Long len;
42     Long recurse_depth;
43     Boolean isconst;
44     UShort digits;
45     Short scale;
46     ValueModifier value_mod;
47
48     void init ();
49     void copy (const TypeCode &);
50     void free ();
51
52     typedef std::pair<TypeCode_ptr, TypeCode_ptr> PairTC;
53     typedef std::set<PairTC, std::less<PairTC> > SetTC;
54     typedef std::map<ULong, std::pair<ULong, TypeCode_ptr>, std::less<ULong> >
55     MapPosTC;
56     typedef std::map<const TypeCode *, ULong, std::less<const TypeCode *> >
57     MapTCPos;
58
59     TypeCode_ptr resolve_recursion() const;
60     void strip();
61     void connect (TypeCode_ptr, Long depth = 0);
62     CORBA::ULong get_recurse_depth();
63     static CORBA::Any *convert_case_label (CORBA::TypeCode_ptr disc,
64                                            const CORBA::Any &);
65 public:
66     // begin-mico-extension
67     void disconnect (TypeCode_ptr);
68     TypeCode (const std::string &);
69     TypeCode (); // for vector<TypeCode>
70     ~TypeCode ();
71     TypeCode (TCKind);
72     TypeCode (const TypeCode &);
73     TypeCode (DataDecoder &);
74     TypeCode &operator= (const TypeCode &);
75     Boolean from_string (const char *);
76
77     static TypeCode_ptr create_basic_tc (TCKind);
78     static TypeCode_ptr create_struct_tc (const char *rep_id, const char *name,
79                                           const StructMemberSeq &members);
80     static TypeCode_ptr create_exception_tc (const char *rep_id,
81                                              const char *name,
82                                              const StructMemberSeq &members);
83     static TypeCode_ptr create_union_tc (const char *rep_id, const char *name,
84                                          TypeCode_ptr disc_type,
85                                          const UnionMemberSeq &members);
86     static TypeCode_ptr create_enum_tc (const char *rep_id, const char *name,
87                                         const EnumMemberSeq &members);
88     static TypeCode_ptr create_alias_tc (const char *rep_id, const char *name,
89                                          TypeCode_ptr orig_type);
90     static TypeCode_ptr create_interface_tc (const char *rep_id,
91                                              const char *name);
92     static TypeCode_ptr create_string_tc (ULong bound);
93     static TypeCode_ptr create_wstring_tc (ULong bound);
94     static TypeCode_ptr create_sequence_tc (ULong bound, TypeCode_ptr el_type);
95     static TypeCode_ptr create_array_tc (ULong bound, TypeCode_ptr el_type);
96     static TypeCode_ptr create_recursive_sequence_tc (ULong bound,
97                                                       ULong offset);
98     static TypeCode_ptr create_fixed_tc (UShort digits, Short scale);
99     static TypeCode_ptr create_value_tc (const char *rep_id, const char *name,
100                                          ValueModifier mod,
101                                          TypeCode_ptr concrete_base,
102                                          const ValueMemberSeq &members);
103     static TypeCode_ptr create_value_box_tc (const char *rep_id,
104                                              const char *name,
105                                              TypeCode_ptr boxed_type);
106     static TypeCode_ptr create_native_tc (const char *rep_id,
107                                           const char *name);
108     static TypeCode_ptr create_recursive_tc (const char *rep_id);
109     static TypeCode_ptr create_abstract_interface_tc (const char *rep_id,
110                                                       const char *name);
111     static TypeCode_ptr create_local_interface_tc (const char *rep_id,
112                                                    const char *name);
113     // end-mico-extension
114
115     typedef CORBA::TypeCode_Bounds Bounds;
116     typedef CORBA::TypeCode_Bounds_catch Bounds_catch;
117
118     typedef CORBA::TypeCode_BadKind BadKind;
119     typedef CORBA::TypeCode_BadKind_catch BadKind_catch;
120
121     TCKind kind () const;
122     Boolean equal (TypeCode_ptr, Boolean remove_aliases = FALSE,
123                                  Boolean ignore_string_bounds = FALSE) const;
124     Boolean equaltype (TypeCode_ptr, SetTC * = 0);
125     Boolean equivalent (TypeCode_ptr tc);
126
127     const char *id () const;
128     const char *name () const;
129
130     Long member_index (const Any &);
131     Long member_index (const char *);
132     ULong member_count () const;
133     const char *member_name (ULong idx) const;
134     TypeCode_ptr member_type (ULong idx) const;
135     Any *member_label (ULong idx) const;
136     TypeCode_ptr discriminator_type () const;
137     Long default_index () const;
138
139     ULong length () const;
140     
141     TypeCode_ptr content_type () const;
142
143     UShort fixed_digits () const;
144     Short fixed_scale () const;
145
146     Visibility member_visibility (ULong idx) const;
147     ValueModifier type_modifier() const;
148     TypeCode_ptr concrete_base_type() const;
149     TypeCode_ptr get_compact_typecode() const;
150
151     ULong member_count_inherited () const;
152     const char *member_name_inherited (ULong idx) const;
153     TypeCode_ptr member_type_inherited (ULong idx) const;
154     Visibility member_visibility_inherited (ULong idx) const;
155
156     Long param_count () const;
157     Any *parameter (Long) const;
158
159     // begin-mico-extension
160     ULong array_size ();
161     TypeCode_ptr array_type ();
162     Boolean is_constant () const;
163     TypeCode_ptr mk_constant ();
164     TypeCode_ptr unalias ();
165
166     void encode (DataEncoder &, MapTCPos * = NULL) const;
167     Boolean decode (DataDecoder &, MapPosTC * = NULL, ULong level = 0);
168
169     std::string stringify () const;
170
171     Boolean is_recursive_seq ();
172     Boolean is_freestanding();
173     Boolean is_freestanding( ULong depth, TypeCode_ptr tc );
174
175
176     Boolean is_base_type();
177     Boolean is_char();
178     Boolean is_wchar();
179     Boolean is_octet();
180     Boolean is_bool();
181     Boolean is_enum();
182     Boolean is_string();
183     Boolean is_wstring();
184     Boolean is_any();
185     Boolean is_type_code();
186     Boolean is_alias();
187     Boolean is_variable();
188     Boolean is_objref();
189     Boolean is_object();
190     Boolean is_sequence();
191     Boolean is_array();
192     Boolean is_valuetype();
193     Boolean is_native();
194     Boolean is_abstract_interface();
195     // end-mico-extension
196
197     static TypeCode_ptr _duplicate (TypeCode_ptr);
198     static TypeCode_ptr _nil ()
199     {
200         return 0;
201     }
202 };
203 extern void release (TypeCode_ptr);
204
205 //typedef ObjVar<TypeCode> TypeCode_var;
206
207
208 // begin-mico-extension
209 class LevelRecord {
210 public:
211     enum Level {
212         LNone, LArray, LSequence, LStruct, LExcept, LUnion, LValue, LValueBox
213     };
214 private:
215     TypeCode_ptr _tc;
216     Level _level;
217 public:
218     Long i, n, x, last_i;
219
220     LevelRecord (Level, TypeCode_ptr, Long n = 0, Long i = 0, Long x = 0);
221     LevelRecord (const LevelRecord &);
222     LevelRecord ();
223     ~LevelRecord ();
224     LevelRecord &operator= (const LevelRecord &);
225     Level level () const;
226     TypeCode_ptr tc ();
227 };
228
229 class TypeCodeChecker {
230     TypeCode_ptr _top;
231     TypeCode_ptr _tc;
232     Boolean done;
233     std::vector<LevelRecord> levelvec;
234
235     LevelRecord *level ();
236     Boolean advance ();
237     Boolean nexttc ();
238     Boolean leave (LevelRecord::Level, Boolean sloppy = FALSE);
239     void enter (const LevelRecord &);
240     void tc (TypeCode_ptr);
241     void override_tc (TypeCode_ptr);
242 public:
243     TypeCodeChecker ();
244     TypeCodeChecker (TypeCode_ptr);
245     TypeCodeChecker (const TypeCodeChecker &);
246     TypeCodeChecker &operator= (const TypeCodeChecker &);
247     ~TypeCodeChecker ();
248
249     TypeCode_ptr tc ();
250     Boolean inside (TCKind);
251     Boolean level_finished ();
252
253     Boolean basic (TypeCode_ptr);
254     Boolean enumeration (Long val);
255     Boolean abstract_interface (TypeCode_ptr override);
256
257     Boolean union_begin ();
258     Boolean union_selection (Long idx = -1L);
259     Boolean union_end (Boolean sloppy = FALSE);
260
261     Boolean struct_begin ();
262     Boolean struct_end (Boolean sloppy = FALSE);
263
264     Boolean except_begin ();
265     Boolean except_end (Boolean sloppy = FALSE);
266
267     Boolean seq_begin (ULong len);
268     Boolean seq_end (Boolean sloppy = FALSE);
269
270     Boolean arr_begin ();
271     Boolean arr_end (Boolean sloppy = FALSE);
272
273     Boolean value_begin (TypeCode_ptr override = 0);
274     Boolean value_end ();
275
276     Boolean valuebox_begin ();
277     Boolean valuebox_end ();
278
279     void finish ();
280     Boolean completed () const;
281     void restart (TypeCode_ptr);
282     void restart ();
283     ULong level_count () const;
284 };
285 // end-mico-extension
286
287
288 extern MICO_EXPORT TypeCode_ptr _tc_null;
289 extern MICO_EXPORT TypeCode_ptr _tc_void;
290 extern MICO_EXPORT TypeCode_ptr _tc_short;
291 extern MICO_EXPORT TypeCode_ptr _tc_long;
292 extern MICO_EXPORT TypeCode_ptr _tc_longlong;
293 extern MICO_EXPORT TypeCode_ptr _tc_ushort;
294 extern MICO_EXPORT TypeCode_ptr _tc_ulong;
295 extern MICO_EXPORT TypeCode_ptr _tc_ulonglong;
296 extern MICO_EXPORT TypeCode_ptr _tc_float;
297 extern MICO_EXPORT TypeCode_ptr _tc_double;
298 extern MICO_EXPORT TypeCode_ptr _tc_longdouble;
299 extern MICO_EXPORT TypeCode_ptr _tc_boolean;
300 extern MICO_EXPORT TypeCode_ptr _tc_char;
301 extern MICO_EXPORT TypeCode_ptr _tc_wchar;
302 extern MICO_EXPORT TypeCode_ptr _tc_octet;
303 extern MICO_EXPORT TypeCode_ptr _tc_any;
304 extern MICO_EXPORT TypeCode_ptr _tc_TypeCode;
305 extern MICO_EXPORT TypeCode_ptr _tc_Principal;
306 extern MICO_EXPORT TypeCode_ptr _tc_Context; // extension
307 extern MICO_EXPORT TypeCode_ptr _tc_NamedValue; // extension
308 extern MICO_EXPORT TypeCode_ptr _tc_Object;
309 extern MICO_EXPORT TypeCode_ptr _tc_ValueBase;
310 extern MICO_EXPORT TypeCode_ptr _tc_AbstractBase; // extension
311 extern MICO_EXPORT TypeCode_ptr _tc_string;
312 extern MICO_EXPORT TypeCode_ptr _tc_wstring;
313
314 }
315
316 #endif // __mico_typecode_h__