Class: R2CORBA::CORBA::TypeCode::WString

Inherits:
R2CORBA::CORBA::TypeCode show all
Defined in:
lib/corba/cbase/Typecode.rb,
lib/corba/jbase/Typecode.rb,
lib/corba/common/Typecode.rb

Overview

String

Constant Summary

Constants inherited from R2CORBA::CORBA::TypeCode

LongLongRange, LongRange, OctetRange, ShortRange, ULongLongRange, ULongRange, UShortRange

Instance Attribute Summary

Attributes inherited from R2CORBA::CORBA::TypeCode

#tc_

Instance Method Summary collapse

Methods inherited from R2CORBA::CORBA::TypeCode

_tc, _wrap_native, #concrete_base_type, #content_type, #default_index, #discriminator_type, #equal?, #equivalent?, #fixed_digits, #fixed_scale, from_native, #get_compact_typecode, get_primitive_tc, #id, #is_recursive_tc?, #kind, #length, #member_count, #member_label, #member_name, #member_type, #member_visibility, #name, native_kind, register_id_type, #resolved_tc, #type_modifier, typecode_for_id, typecodes_for_name

Constructor Details

#initialize(*args) ⇒ WString

Returns a new instance of WString.

Raises:

  • (RuntimeError)


64
65
66
67
68
69
70
71
72
73
74
# File 'lib/corba/cbase/Typecode.rb', line 64

def initialize(*args)
  if CORBA::Native::TypeCode === args.first
    @tc_ = args.first
  else
    begin
      @tc_ = CORBA::Native::TypeCode.create_tc(TK_WSTRING, args.shift.to_i)
    rescue ::NativeException
      CORBA::Exception.native2r($!)
    end
  end
end

Instance Method Details

#get_typeObject



450
451
452
# File 'lib/corba/common/Typecode.rb', line 450

def get_type
  ::Array
end

#in_value(val) ⇒ Object



479
480
481
482
483
484
485
486
487
# File 'lib/corba/common/Typecode.rb', line 479

def in_value(val)
  if val.respond_to?(:to_str)
    a = []
    val.to_str.each_byte { |c| a << c }
    a
  else
    ::Array === val ? val : val.to_ary
  end
end

#needs_conversion(val) ⇒ Object



475
476
477
# File 'lib/corba/common/Typecode.rb', line 475

def needs_conversion(val)
  !(::Array === val) ? true : val.any? { |el| !(::Integer === el) }
end

#validate(val) ⇒ Object

Raises:

  • (::CORBA::MARSHAL)


454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
# File 'lib/corba/common/Typecode.rb', line 454

def validate(val)
  return val if val.nil?
  super(val) unless ::Array === val || val.respond_to?(:to_str) || val.respond_to?(:to_ary)
  val = if ::Array === val
    val
  elsif val.respond_to?(:to_ary)
    val.to_ary
  else
    a = []
    val.to_str.each_byte { |c| a << c }
    a
  end
  raise ::CORBA::MARSHAL.new(
    "widestring size exceeds bound: #{self.length.to_s}",
    1, ::CORBA::COMPLETED_NO) unless (self.length==0 || val.size<=self.length)
  raise ::CORBA::MARSHAL.new(
    "invalid widestring element(s)",
    1, ::CORBA::COMPLETED_NO) if val.any? { |el| !(UShortRange === (el.respond_to?(:to_int) ? el.to_int : el)) }
  val.any? { |el| !(::Integer === el) } ? val.collect { |el| el.to_int } : val
end