Class: DBus::Type::Type
- Inherits:
-
Object
- Object
- DBus::Type::Type
- Defined in:
- lib/dbus/type.rb
Overview
D-Bus type conversion class
Helper class for representing a D-Bus type.
Instance Attribute Summary collapse
-
#members ⇒ Object
readonly
Return contained member types.
-
#sigtype ⇒ Object
readonly
Returns the signature type number.
Instance Method Summary collapse
-
#<<(a) ⇒ Object
Add a new member type a.
-
#alignment ⇒ Object
Return the required alignment for the type.
-
#child ⇒ Object
Return the first contained member type.
-
#initialize(sigtype) ⇒ Type
constructor
Create a new type instance for type number sigtype.
- #inspect ⇒ Object
-
#to_s ⇒ Object
Return a string representation of the type according to the D-Bus specification.
Constructor Details
#initialize(sigtype) ⇒ Type
Create a new type instance for type number sigtype.
58 59 60 61 62 63 64 |
# 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 |
Instance Attribute Details
#members ⇒ Object (readonly)
Return contained member types.
55 56 57 |
# File 'lib/dbus/type.rb', line 55 def members @members end |
#sigtype ⇒ Object (readonly)
Returns the signature type number.
53 54 55 |
# File 'lib/dbus/type.rb', line 53 def sigtype @sigtype end |
Instance Method Details
#<<(a) ⇒ Object
Add a new member type a.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# 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 ⇒ Object
Return the required alignment for the type.
67 68 69 |
# File 'lib/dbus/type.rb', line 67 def alignment TypeMapping[@sigtype].last end |
#child ⇒ Object
Return the first contained member type.
109 110 111 |
# File 'lib/dbus/type.rb', line 109 def child @members[0] end |
#inspect ⇒ Object
113 114 115 116 117 118 119 |
# 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 ⇒ Object
Return a string representation of the type according to the D-Bus specification.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# 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 |