Class DBus::Type::Type
In: lib/dbus/type.rb
Parent: Object

D-Bus type conversion class

Helper class for representing a D-Bus type.

Methods

<<   alignment   child   inspect   new   to_s  

Attributes

members  [R]  Return contained member types.
sigtype  [R]  Returns the signature type number.

Public Class methods

Create a new type instance for type number sigtype.

[Source]

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

Public Instance methods

Add a new member type a.

[Source]

# File lib/dbus/type.rb, line 121
    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

Return the required alignment for the type.

[Source]

# File lib/dbus/type.rb, line 81
    def alignment
      {
        BYTE => 1,
        BOOLEAN => 4,
        INT16 => 2,
        UINT16 => 2,
        INT32 => 4,
        UINT32 => 4,
        INT64 => 8,
        UINT64 => 8,
        STRUCT => 8,
        DICT_ENTRY => 8,
        DOUBLE => 8,
        ARRAY => 4,
        VARIANT => 1,
        OBJECT_PATH => 4,
        STRING => 4,
        SIGNATURE => 1,
      }[@sigtype]
    end

Return the first contained member type.

[Source]

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

[Source]

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

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

[Source]

# File lib/dbus/type.rb, line 104
    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 TypeName.keys.member?(@sigtype)
          raise NotImplementedError
        end
        @sigtype.chr
      end
    end

[Validate]