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.
18
19
20
|
# File 'lib/corba/common/Typecode.rb', line 18
def initialize
raise RuntimeError, 'not allowed'
end
|
Instance Attribute Details
Returns the value of attribute tc_.
28
29
30
|
# File 'lib/corba/common/Typecode.rb', line 28
def tc_
@tc_
end
|
Class Method Details
._wrap_native(ntc) ⇒ Object
30
31
32
33
|
# File 'lib/corba/common/Typecode.rb', line 30
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
95
96
97
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
|
# File 'lib/corba/common/Typecode.rb', line 95
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
91
92
93
|
# File 'lib/corba/common/Typecode.rb', line 91
def TypeCode.native_kind(ntc)
ntc.kind.value
end
|
.register_id_type(id, tc) ⇒ Object
77
78
79
|
# File 'lib/corba/common/Typecode.rb', line 77
def TypeCode.register_id_type(id, tc)
@@typecode_registry[id] = tc
end
|
.typecode_for_id(id) ⇒ Object
81
82
83
|
# File 'lib/corba/common/Typecode.rb', line 81
def TypeCode.typecode_for_id(id)
@@typecode_registry[id]
end
|
.typecodes_for_name(name) ⇒ Object
85
86
87
|
# File 'lib/corba/common/Typecode.rb', line 85
def TypeCode.typecodes_for_name(name)
@@typecode_registry.types_for_name(name)
end
|
Instance Method Details
#concrete_base_type ⇒ Object
305
306
307
308
|
# File 'lib/corba/common/Typecode.rb', line 305
def concrete_base_type
ntc = self.tc_.concrete_base_type
ntc.nil? ? nil : CORBA::TypeCode.from_native(ntc)
end
|
#content_type ⇒ Object
269
270
271
|
# File 'lib/corba/common/Typecode.rb', line 269
def content_type
CORBA::TypeCode.from_native(self.tc_.content_type)
end
|
#discriminator_type ⇒ Object
249
250
251
|
# File 'lib/corba/common/Typecode.rb', line 249
def discriminator_type
CORBA::TypeCode.from_native(self.tc_.discriminator_type)
end
|
#equal?(tc) ⇒ Boolean
187
188
189
190
191
192
193
194
|
# File 'lib/corba/common/Typecode.rb', line 187
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
196
197
198
199
200
201
202
203
|
# File 'lib/corba/common/Typecode.rb', line 196
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
183
184
185
|
# File 'lib/corba/common/Typecode.rb', line 183
def get_compact_typecode
CORBA::TypeCode.from_native(self.tc_.get_compact_typecode)
end
|
310
311
312
313
314
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
|
# File 'lib/corba/common/Typecode.rb', line 310
def get_type
@type ||= case self.kind
when TK_SHORT, TK_LONG, TK_USHORT, TK_ULONG
::Fixnum
when TK_LONGLONG, TK_ULONGLONG
::Bignum
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
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
175
176
177
|
# File 'lib/corba/common/Typecode.rb', line 175
def is_recursive_tc?
false
end
|
#member_label(index) ⇒ Object
26
27
28
29
30
31
32
|
# File 'lib/corba/cbase/Typecode.rb', line 26
def member_label(index)
begin
self.tc_.member_label(index.to_i)
rescue ::NativeException
CORBA::Exception.native2r($!)
end
end
|
#member_name(index) ⇒ Object
229
230
231
232
233
234
235
|
# File 'lib/corba/common/Typecode.rb', line 229
def member_name(index)
begin
self.tc_.member_name(index.to_i)
rescue ::NativeException
CORBA::Exception.native2r($!)
end
end
|
#member_visibility(index) ⇒ Object
289
290
291
292
293
294
295
|
# File 'lib/corba/common/Typecode.rb', line 289
def member_visibility(index)
begin
self.tc_.member_visibility(index.to_i)
rescue ::NativeException
CORBA::Exception.native2r($!)
end
end
|
#needs_conversion(val) ⇒ Object
378
379
380
381
382
383
384
385
386
387
388
389
|
# File 'lib/corba/common/Typecode.rb', line 378
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
171
172
173
|
# File 'lib/corba/common/Typecode.rb', line 171
def resolved_tc
self
end
|
#validate(val) ⇒ Object
341
342
343
344
345
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
|
# File 'lib/corba/common/Typecode.rb', line 341
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
|