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.



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/corba/cbase/Typecode.rb', line 57

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



458
459
460
# File 'lib/corba/common/Typecode.rb', line 458

def get_type
  ::Array
end

#in_value(val) ⇒ Object



488
489
490
491
492
493
494
495
496
# File 'lib/corba/common/Typecode.rb', line 488

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



484
485
486
# File 'lib/corba/common/Typecode.rb', line 484

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

#validate(val) ⇒ Object

Raises:

  • (::CORBA::MARSHAL)


462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
# File 'lib/corba/common/Typecode.rb', line 462

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