# class DBus::Type::Type

# D-Bus type conversion class¶ ↑

Helper class for representing a D-Bus type.

### Attributes

members[R]

Return contained member types.

sigtype[R]

Returns the signature type number.

### Public Class Methods

new(sigtype) click to toggle source

Create a new type instance for type number sigtype.

    # File lib/dbus/type.rb, line 58
    def initialize(sigtype)
      if not TypeMapping.keys.member?(sigtype)
        raise SignatureException, "Unknown key in signature: #{sigtype.chr}"
      end
      @sigtype = sigtype
      @members = Array.new
    end

### Public Instance Methods

<<(a) click to toggle source

Add a new member type a.

    # File lib/dbus/type.rb, line 90
    def <<(a)
      if not [STRUCT, ARRAY, DICT_ENTRY].member?(@sigtype)
        raise SignatureException
      end
      raise SignatureException if @sigtype == ARRAY and @members.size > 0
      if @sigtype == DICT_ENTRY
        if @members.size == 2
          raise SignatureException, "Dict entries have exactly two members"
        end
        if @members.size == 0
          if [STRUCT, ARRAY, DICT_ENTRY].member?(a.sigtype)
            raise SignatureException, "Dict entry keys must be basic types"
          end
        end
      end
      @members << a
    end

alignment() click to toggle source

Return the required alignment for the type.

    # File lib/dbus/type.rb, line 67
    def alignment
      TypeMapping[@sigtype].last
    end

child() click to toggle source

Return the first contained member type.

    # File lib/dbus/type.rb, line 109
    def child
      @members[0]
    end

inspect() click to toggle source

    # File lib/dbus/type.rb, line 113
    def inspect
      s = TypeMapping[@sigtype].first
      if [STRUCT, ARRAY].member?(@sigtype)
        s += ": " + @members.inspect
      end
      s
    end

to_s() click to toggle source

Return a string representation of the type according to the D-Bus specification.

    # File lib/dbus/type.rb, line 73
    def to_s
      case @sigtype
      when STRUCT
        "(" + @members.collect { |t| t.to_s }.join + ")"
      when ARRAY
        "a" + child.to_s
      when DICT_ENTRY
        "{" + @members.collect { |t| t.to_s }.join + "}"
      else
        if not TypeMapping.keys.member?(@sigtype)
          raise NotImplementedError
        end
        @sigtype.chr
      end
    end