Class: R2CORBA::CORBA::TypeCode::Enum

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

Overview

Union

Constant Summary

Constants inherited from R2CORBA::CORBA::TypeCode

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

Instance Attribute Summary collapse

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_label, #member_type, #member_visibility, #name, native_kind, register_id_type, #resolved_tc, #type_modifier, typecode_for_id, typecodes_for_name

Constructor Details

#initialize(*args) ⇒ Enum

Returns a new instance of Enum.

Raises:

  • (RuntimeError)


409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
# File 'lib/corba/cbase/Typecode.rb', line 409

def initialize(*args)
  if CORBA::Native::TypeCode === args.first
    @tc_ = args.first
    @range = (0..@tc_.member_count).freeze
    @members = @range.to_a.collect {|i| @tc_.member_name(i) }
    super(@tc_.id)
  else
    id, name, members_ = args
    raise CORBA::BAD_PARAM unless members_.is_a? ::Array
    @members = members_.collect {|m| m.to_s}
    @range = (0...@members.size).freeze
    begin
      @tc_ = CORBA::Native::TypeCode.create_tc(TK_ENUM, id.to_s, name.to_s, @members)
    rescue ::NativeException
      CORBA::Exception.native2r($!)
    end
    super(id)
  end
end

Instance Attribute Details

#membersObject (readonly)

Returns the value of attribute members.



1002
1003
1004
# File 'lib/corba/common/Typecode.rb', line 1002

def members
  @members
end

Instance Method Details

#get_typeObject



1006
1007
1008
# File 'lib/corba/common/Typecode.rb', line 1006

def get_type
  ::Integer
end

#member_countObject



1022
1023
1024
# File 'lib/corba/common/Typecode.rb', line 1022

def member_count
  @members.size
end

#member_name(index) ⇒ Object



1025
1026
1027
1028
# File 'lib/corba/common/Typecode.rb', line 1025

def member_name(index)
  raise CORBA::TypeCode::Bounds.new if (index<0) || (index>=@members.size)
  @members[index]
end

#needs_conversion(val) ⇒ Object



1018
1019
1020
# File 'lib/corba/common/Typecode.rb', line 1018

def needs_conversion(val)
  !(::Integer === val)
end

#validate(val) ⇒ Object

Raises:

  • (CORBA::MARSHAL)


1010
1011
1012
1013
1014
1015
1016
# File 'lib/corba/common/Typecode.rb', line 1010

def validate(val)
  super(val) if !val.respond_to?(:to_int)
  raise CORBA::MARSHAL.new(
    "value (#{val}) out of range (#{@range}) for enum: #{name}",
    1, CORBA::COMPLETED_NO) unless @range === (::Integer === val ? val : val.to_int)
  (::Integer === val ? val : val.to_int)
end