Class: R2CORBA::CORBA::TypeCode

Inherits:
Object
  • Object
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

#initializeTypeCode

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

#tc_Object (readonly)

Returns the value of attribute tc_.



27
28
29
# File 'lib/corba/common/Typecode.rb', line 27

def tc_
  @tc_
end

Class Method Details

._tcObject



35
36
37
# File 'lib/corba/common/Typecode.rb', line 35

def TypeCode._tc
  CORBA::_tc_TypeCode
end

._wrap_native(ntc) ⇒ Object

Raises:

  • (ArgumentError)


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))
    ## primitive typecode; wrap it
    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

Enum



403
404
405
# File 'lib/corba/cbase/Typecode.rb', line 403

def TypeCode.get_primitive_tc(kind)
  TypeCode._wrap_native(CORBA::Native::TypeCode.get_primitive_tc(kind.to_i))
end

.native_kind(ntc) ⇒ Object

native to ruby



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_typeObject



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_typeObject



274
275
276
# File 'lib/corba/common/Typecode.rb', line 274

def content_type
  CORBA::TypeCode.from_native(self.tc_.content_type)
end

#default_indexObject



258
259
260
261
262
263
264
# File 'lib/corba/common/Typecode.rb', line 258

def default_index
  begin
    self.tc_.default_index
  rescue ::NativeException
    CORBA::Exception.native2r($!)
  end
end

#discriminator_typeObject



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

Returns:

  • (Boolean)

Raises:

  • (ArgumentError)


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

Returns:

  • (Boolean)

Raises:

  • (ArgumentError)


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

#fixed_digitsObject



278
279
280
281
282
283
284
# File 'lib/corba/common/Typecode.rb', line 278

def fixed_digits
  begin
    self.tc_.fixed_digits
  rescue ::NativeException
    CORBA::Exception.native2r($!)
  end
end

#fixed_scaleObject



286
287
288
289
290
291
292
# File 'lib/corba/common/Typecode.rb', line 286

def fixed_scale
  begin
    self.tc_.fixed_scale
  rescue ::NativeException
    CORBA::Exception.native2r($!)
  end
end

#get_compact_typecodeObject



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

#get_typeObject



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

#idObject



210
211
212
213
214
215
216
# File 'lib/corba/common/Typecode.rb', line 210

def id
  begin
    self.tc_.id
  rescue ::NativeException
    CORBA::Exception.native2r($!)
  end
end

#is_recursive_tc?Boolean

Returns:

  • (Boolean)


178
179
180
# File 'lib/corba/common/Typecode.rb', line 178

def is_recursive_tc?
  false
end

#kindObject

Raises:

  • (CORBA::NO_IMPLEMENT)


16
17
18
19
20
21
22
# File 'lib/corba/cbase/Typecode.rb', line 16

def kind
  begin
    self.tc_.kind
  rescue ::NativeException
    CORBA::Exception.native2r($!)
  end
end

#lengthObject



266
267
268
269
270
271
272
# File 'lib/corba/common/Typecode.rb', line 266

def length
  begin
    self.tc_.length
  rescue ::NativeException
    CORBA::Exception.native2r($!)
  end
end

#member_countObject



226
227
228
229
230
231
232
# File 'lib/corba/common/Typecode.rb', line 226

def member_count
  begin
    self.tc_.member_count
  rescue ::NativeException
    CORBA::Exception.native2r($!)
  end
end

#member_label(index) ⇒ Object

Raises:

  • (CORBA::NO_IMPLEMENT)


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_type(index) ⇒ Object



242
243
244
245
246
247
248
# File 'lib/corba/common/Typecode.rb', line 242

def member_type(index)
  begin
    CORBA::TypeCode.from_native(self.tc_.member_type(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

#nameObject



218
219
220
221
222
223
224
# File 'lib/corba/common/Typecode.rb', line 218

def name
  begin
    self.tc_.name
  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_tcObject

instance methods



174
175
176
# File 'lib/corba/common/Typecode.rb', line 174

def resolved_tc
  self
end

#type_modifierObject



302
303
304
305
306
307
308
# File 'lib/corba/common/Typecode.rb', line 302

def type_modifier
  begin
    self.tc_.type_modifier
  rescue ::NativeException
    CORBA::Exception.native2r($!)
  end
end

#validate(val) ⇒ Object

Raises:

  • (CORBA::MARSHAL)


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