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.

Raises:

  • (RuntimeError)


18
19
20
# File 'lib/corba/common/Typecode.rb', line 18

def initialize
  raise RuntimeError, 'not allowed'
end

Instance Attribute Details

#tc_Object (readonly)

Returns the value of attribute tc_.



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

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)


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))
    ## 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

Raises:

  • (RuntimeError)


431
432
433
# File 'lib/corba/cbase/Typecode.rb', line 431

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



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_typeObject



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_typeObject



269
270
271
# File 'lib/corba/common/Typecode.rb', line 269

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

#default_indexObject



253
254
255
256
257
258
259
# File 'lib/corba/common/Typecode.rb', line 253

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

#discriminator_typeObject



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

Returns:

  • (Boolean)

Raises:

  • (ArgumentError)


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

Returns:

  • (Boolean)

Raises:

  • (ArgumentError)


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

#fixed_digitsObject



273
274
275
276
277
278
279
# File 'lib/corba/common/Typecode.rb', line 273

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

#fixed_scaleObject



281
282
283
284
285
286
287
# File 'lib/corba/common/Typecode.rb', line 281

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

#get_compact_typecodeObject



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

#get_typeObject



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

#idObject



205
206
207
208
209
210
211
# File 'lib/corba/common/Typecode.rb', line 205

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

#is_recursive_tc?Boolean

Returns:

  • (Boolean)


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

def is_recursive_tc?
  false
end

#kindObject

Raises:

  • (CORBA::NO_IMPLEMENT)


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

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

#lengthObject



261
262
263
264
265
266
267
# File 'lib/corba/common/Typecode.rb', line 261

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

#member_countObject



221
222
223
224
225
226
227
# File 'lib/corba/common/Typecode.rb', line 221

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

#member_label(index) ⇒ Object

Raises:

  • (CORBA::NO_IMPLEMENT)


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



237
238
239
240
241
242
243
# File 'lib/corba/common/Typecode.rb', line 237

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



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

#nameObject



213
214
215
216
217
218
219
# File 'lib/corba/common/Typecode.rb', line 213

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

instance methods



171
172
173
# File 'lib/corba/common/Typecode.rb', line 171

def resolved_tc
  self
end

#type_modifierObject



297
298
299
300
301
302
303
# File 'lib/corba/common/Typecode.rb', line 297

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

#validate(val) ⇒ Object

Raises:

  • (CORBA::MARSHAL)


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