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
57 def initialize(sigtype)
58   if !TypeMapping.keys.member?(sigtype)
59     raise SignatureException, "Unknown key in signature: #{sigtype.chr}"
60   end
61   @sigtype = sigtype
62   @members = []
63 end

Public Instance Methods

<<(a) click to toggle source

Add a new member type a.

    # File lib/dbus/type.rb
 89 def <<(a)
 90   if ![STRUCT, ARRAY, DICT_ENTRY].member?(@sigtype)
 91     raise SignatureException
 92   end
 93   raise SignatureException if @sigtype == ARRAY && !@members.empty?
 94   if @sigtype == DICT_ENTRY
 95     if @members.size == 2
 96       raise SignatureException, "Dict entries have exactly two members"
 97     end
 98     if @members.empty?
 99       if [STRUCT, ARRAY, DICT_ENTRY].member?(a.sigtype)
100         raise SignatureException, "Dict entry keys must be basic types"
101       end
102     end
103   end
104   @members << a
105 end
alignment() click to toggle source

Return the required alignment for the type.

   # File lib/dbus/type.rb
66 def alignment
67   TypeMapping[@sigtype].last
68 end
child() click to toggle source

Return the first contained member type.

    # File lib/dbus/type.rb
108 def child
109   @members[0]
110 end
inspect() click to toggle source
    # File lib/dbus/type.rb
112 def inspect
113   s = TypeMapping[@sigtype].first
114   if [STRUCT, ARRAY].member?(@sigtype)
115     s += ": " + @members.inspect
116   end
117   s
118 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
72 def to_s
73   case @sigtype
74   when STRUCT
75     "(" + @members.collect(&:to_s).join + ")"
76   when ARRAY
77     "a" + child.to_s
78   when DICT_ENTRY
79     "{" + @members.collect(&:to_s).join + "}"
80   else
81     if !TypeMapping.keys.member?(@sigtype)
82       raise NotImplementedError
83     end
84     @sigtype.chr
85   end
86 end