Class: R2CORBA::CORBA::TypeCode
- Inherits:
-
Object
- Object
- R2CORBA::CORBA::TypeCode
show all
- Defined in:
- lib/corba/cbase/Typecode.rb,
lib/corba/jbase/Typecode.rb,
lib/corba/common/Typecode.rb
Defined Under Namespace
Classes: AbstractInterface, Alias, Array, BadKind, Bounds, Enum, Eventtype, Except, Fixed, IdentifiedTypeCode, ObjectRef, Recursive, Sequence, String, Struct, SysExcept, Union, Valuebox, Valuetype, WString
Constant Summary
collapse
- OctetRange =
(0..0xFF).freeze
- UShortRange =
(0..0xFFFF).freeze
- ULongRange =
(0..0xFFFFFFFF).freeze
- ULongLongRange =
(0..0xFFFFFFFFFFFFFFFF).freeze
- ShortRange =
(-0x8000...0x8000).freeze
- LongRange =
(-0x80000000...0x80000000).freeze
- LongLongRange =
(-0x8000000000000000...0x8000000000000000).freeze
- @@wrapper_klass =
Class.new(CORBA::TypeCode) do
def initialize(ntc)
@tc_ = ntc
end
end
- @@typecode_registry =
(Class.new(Monitor) do
def initialize
@id_types = {}
@name_types = {}
super
end
def []=(id, tc)
synchronize do
@id_types[id] = tc
types_for_name_ = @name_types[tc.name] || []
types_for_name_ << tc
@name_types[tc.name] = types_for_name_
end
end
def [](id)
tc = nil
synchronize do
tc = @id_types[id]
end
tc
end
def types_for_name(name)
tcs = nil
synchronize do
tcs = @name_types[name]
end
tcs
end
end).new
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of TypeCode.
17
18
19
|
# File 'lib/corba/common/Typecode.rb', line 17
def initialize
raise 'not allowed'
end
|
Instance Attribute Details
Returns the value of attribute tc_.
27
28
29
|
# File 'lib/corba/common/Typecode.rb', line 27
def tc_
@tc_
end
|
Class Method Details
._wrap_native(ntc) ⇒ Object
29
30
31
32
33
|
# File 'lib/corba/common/Typecode.rb', line 29
def self._wrap_native(ntc)
raise ArgumentError, 'Expected org.omg.CORBA.TypeCode' unless ntc.nil? || ntc.is_a?(Native::TypeCode)
ntc.nil? ? ntc : @@wrapper_klass.new(ntc)
end
|
.from_native(ntc) ⇒ Object
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
# File 'lib/corba/common/Typecode.rb', line 98
def TypeCode.from_native(ntc)
if [TK_NULL, TK_VOID, TK_ANY, TK_BOOLEAN, TK_SHORT, TK_LONG, TK_USHORT,
TK_WCHAR, TK_ULONG, TK_LONGLONG, TK_ULONGLONG, TK_OCTET,
TK_FLOAT, TK_DOUBLE, TK_LONGDOUBLE, TK_CHAR,
TK_TYPECODE, TK_PRINCIPAL].include?(native_kind(ntc))
return TypeCode._wrap_native(ntc)
else
rtc = nil
case native_kind(ntc)
when TK_STRING
rtc = TypeCode::String.new(ntc)
when TK_WSTRING
rtc = TypeCode::WString.new(ntc)
when TK_FIXED
rtc = TypeCode::Fixed.new(ntc)
when TK_ALIAS
rtc = TypeCode.typecode_for_id(ntc.id)
unless rtc
rtc = TypeCode::Alias.new(ntc)
end
when TK_ENUM
rtc = TypeCode.typecode_for_id(ntc.id)
unless rtc
rtc = TypeCode::Enum.new(ntc)
end
when TK_ARRAY
rtc = TypeCode::Array.new(ntc)
when TK_SEQUENCE
rtc = TypeCode::Sequence.new(ntc)
when TK_STRUCT
rtc = TypeCode.typecode_for_id(ntc.id)
unless rtc
rtc = TypeCode::Struct.new(ntc)
end
when TK_EXCEPT
rtc = TypeCode.typecode_for_id(ntc.id)
unless rtc
rtc = TypeCode::Except.new(ntc)
end
when TK_UNION
rtc = TypeCode.typecode_for_id(ntc.id)
unless rtc
rtc = TypeCode::Union.new(ntc)
end
when TK_OBJREF
rtc = TypeCode.typecode_for_id(ntc.id)
unless rtc
rtc = TypeCode::ObjectRef.new(ntc)
end
when TK_ABSTRACT_INTERFACE
rtc = TypeCode.typecode_for_id(ntc.id)
unless rtc
rtc = TypeCode::AbstractInterface.new(ntc)
end
when TK_VALUE_BOX
rtc = TypeCode.typecode_for_id(ntc.id)
unless rtc
rtc = TypeCode::Valuebox.new(ntc)
end
when TK_VALUE
rtc = TypeCode.typecode_for_id(ntc.id)
unless rtc
rtc = TypeCode::Valuetype.new(ntc)
end
when TK_NATIVE
raise CORBA::NO_IMPLEMENT.new('typecode #{native_kind(ntc)} not supported', 0, CORBA::COMPLETED_NO)
else
raise CORBA::MARSHAL.new("unknown kind [#{native_kind(ntc)}]", 0, CORBA::COMPLETED_NO)
end
return rtc
end
end
|
.get_primitive_tc(kind) ⇒ Object
.native_kind(ntc) ⇒ Object
94
95
96
|
# File 'lib/corba/common/Typecode.rb', line 94
def TypeCode.native_kind(ntc)
ntc.kind.value
end
|
.register_id_type(id, tc) ⇒ Object
80
81
82
|
# File 'lib/corba/common/Typecode.rb', line 80
def TypeCode.register_id_type(id, tc)
@@typecode_registry[id] = tc
end
|
.typecode_for_id(id) ⇒ Object
84
85
86
|
# File 'lib/corba/common/Typecode.rb', line 84
def TypeCode.typecode_for_id(id)
@@typecode_registry[id]
end
|
.typecodes_for_name(name) ⇒ Object
88
89
90
|
# File 'lib/corba/common/Typecode.rb', line 88
def TypeCode.typecodes_for_name(name)
@@typecode_registry.types_for_name(name)
end
|
Instance Method Details
#concrete_base_type ⇒ Object
310
311
312
313
|
# File 'lib/corba/common/Typecode.rb', line 310
def concrete_base_type
ntc = self.tc_.concrete_base_type
ntc.nil? ? nil : CORBA::TypeCode.from_native(ntc)
end
|
#content_type ⇒ Object
274
275
276
|
# File 'lib/corba/common/Typecode.rb', line 274
def content_type
CORBA::TypeCode.from_native(self.tc_.content_type)
end
|
#discriminator_type ⇒ Object
254
255
256
|
# File 'lib/corba/common/Typecode.rb', line 254
def discriminator_type
CORBA::TypeCode.from_native(self.tc_.discriminator_type)
end
|
#equal?(tc) ⇒ Boolean
190
191
192
193
194
195
196
197
198
|
# File 'lib/corba/common/Typecode.rb', line 190
def equal?(tc)
raise ArgumentError, 'expected CORBA::TypeCode' unless tc.is_a?(CORBA::TypeCode)
begin
self.tc_.equal(tc.tc_)
rescue ::NativeException
CORBA::Exception.native2r($!)
end
end
|
#equivalent?(tc) ⇒ Boolean
200
201
202
203
204
205
206
207
208
|
# File 'lib/corba/common/Typecode.rb', line 200
def equivalent?(tc)
raise ArgumentError, 'expected CORBA::TypeCode' unless tc.is_a?(CORBA::TypeCode)
begin
self.tc_.equivalent(tc.tc_)
rescue ::NativeException
CORBA::Exception.native2r($!)
end
end
|
#get_compact_typecode ⇒ Object
186
187
188
|
# File 'lib/corba/common/Typecode.rb', line 186
def get_compact_typecode
CORBA::TypeCode.from_native(self.tc_.get_compact_typecode)
end
|
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
|
# File 'lib/corba/common/Typecode.rb', line 315
def get_type
@type ||= case self.kind
when TK_SHORT, TK_LONG, TK_USHORT, TK_ULONG
FIXNUM_KLASS
when TK_LONGLONG, TK_ULONGLONG
BIGNUM_KLASS
when TK_FLOAT, TK_DOUBLE
::Float
when TK_LONGDOUBLE
::CORBA::LongDouble
when TK_BOOLEAN
::TrueClass
when TK_CHAR, TK_STRING
::String
when TK_WCHAR, TK_OCTET
FIXNUM_KLASS
when TK_VOID, TK_NULL
::NilClass
when TK_ANY
::Object
when TK_TYPECODE
CORBA::TypeCode
when TK_OBJREF
CORBA::Object
when TK_ABSTRACT_INTERFACE
::Object
else
nil
end
end
|
#is_recursive_tc? ⇒ Boolean
178
179
180
|
# File 'lib/corba/common/Typecode.rb', line 178
def is_recursive_tc?
false
end
|
#member_label(index) ⇒ Object
24
25
26
27
28
29
30
|
# File 'lib/corba/cbase/Typecode.rb', line 24
def member_label(index)
begin
self.tc_.member_label(index.to_i)
rescue ::NativeException
CORBA::Exception.native2r($!)
end
end
|
#member_name(index) ⇒ Object
234
235
236
237
238
239
240
|
# File 'lib/corba/common/Typecode.rb', line 234
def member_name(index)
begin
self.tc_.member_name(index.to_i)
rescue ::NativeException
CORBA::Exception.native2r($!)
end
end
|
#member_visibility(index) ⇒ Object
294
295
296
297
298
299
300
|
# File 'lib/corba/common/Typecode.rb', line 294
def member_visibility(index)
begin
self.tc_.member_visibility(index.to_i)
rescue ::NativeException
CORBA::Exception.native2r($!)
end
end
|
#needs_conversion(val) ⇒ Object
383
384
385
386
387
388
389
390
391
392
393
394
|
# File 'lib/corba/common/Typecode.rb', line 383
def needs_conversion(val)
case self.kind
when TK_SHORT, TK_LONG,
TK_USHORT, TK_WCHAR,
TK_ULONG, TK_LONGLONG, TK_ULONGLONG,
TK_OCTET
return !(::Integer === val)
when TK_CHAR
return !(::String === val)
end
false
end
|
#resolved_tc ⇒ Object
174
175
176
|
# File 'lib/corba/common/Typecode.rb', line 174
def resolved_tc
self
end
|
#validate(val) ⇒ Object
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
|
# File 'lib/corba/common/Typecode.rb', line 346
def validate(val)
case self.kind
when TK_ANY
return CORBA::Any === val ? val : Any.to_any(val)
when TK_BOOLEAN
return val if (val.is_a? TrueClass) || (val.is_a? FalseClass)
when TK_SHORT
return val.to_int if val.respond_to?(:to_int) && ShortRange === val.to_int
when TK_LONG
return val.to_int if val.respond_to?(:to_int) && LongRange === val.to_int
when TK_USHORT, TK_WCHAR
return val.to_int if val.respond_to?(:to_int) && UShortRange === val.to_int
when TK_ULONG
return val.to_int if val.respond_to?(:to_int) && ULongRange === val.to_int
when TK_LONGLONG
return val.to_int if val.respond_to?(:to_int) && LongLongRange === val.to_int
when TK_ULONGLONG
return val.to_int if val.respond_to?(:to_int) && ULongLongRange === val.to_int
when TK_OCTET
return val.to_int if val.respond_to?(:to_int) && OctetRange === val.to_int
when TK_FLOAT, TK_DOUBLE
return val if val.is_a?(::Float)
when TK_LONGDOUBLE
return val if val.is_a?(::CORBA::LongDouble)
when TK_CHAR
if (val.respond_to?(:to_str) && (val.to_str.size == 1)) ||
(val.respond_to?(:to_int) && OctetRange === val.to_int)
return val.respond_to?(:to_str) ? val.to_str : val.to_int.chr
end
else
return val if val.nil? || val.is_a?(self.get_type)
end
raise CORBA::MARSHAL.new(
"value does not match type: value = #{val}, value type == #{val.class.name}, type == #{get_type.name}",
1, CORBA::COMPLETED_NO)
end
|