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.
74 75 76 77 78 79 80 |
# File 'lib/dbus/type.rb', line 74 def initialize(sigtype) if not TypeName.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.
71 72 73 |
# File 'lib/dbus/type.rb', line 71 def members @members end |
#sigtype ⇒ Object (readonly)
Returns the signature type number.
69 70 71 |
# File 'lib/dbus/type.rb', line 69 def sigtype @sigtype end |
Instance Method Details
#<<(a) ⇒ Object
Add a new member type a.
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/dbus/type.rb', line 124 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.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/dbus/type.rb', line 83 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, UNIX_FD => 4, }[@sigtype] end |
#child ⇒ Object
Return the first contained member type.
143 144 145 |
# File 'lib/dbus/type.rb', line 143 def child @members[0] end |
#inspect ⇒ Object
147 148 149 150 151 152 153 |
# File 'lib/dbus/type.rb', line 147 def inspect s = TypeName[@sigtype] 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.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/dbus/type.rb', line 107 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 |