Class: Phidgets::Dictionary
- Defined in:
- lib/phidgets/dictionary.rb,
ext/phidgets/phidgets_dictionary.c
Instance Method Summary collapse
-
#add(key, value) ⇒ Object
Adds a new key value pair to the dictionary.
-
#get(key) ⇒ Object
Gets a key value.
-
#new ⇒ Object
constructor
Creates a Phidget Dictionary object.
-
#remove(key) ⇒ Object
Removes the key from the dictionary.
-
#removeAll ⇒ Object
(also: #remove_all)
Removes every key from the dictionary.
-
#scan(start_key) ⇒ Object
Scans the keys in the dictionary, indexed by start or the first key in the dictionary if start is NULL or an empty String.
-
#set(key, value) ⇒ Object
Sets the value of a key, or creates the key value pair if the key does not already exist.
-
#setOnAddHandler(cb_proc = nil, &cb_block) ⇒ Object
(also: #on_add)
call-seq: setOnAddHandler(proc=nil, &block).
-
#setOnRemoveHandler(cb_proc = nil, &cb_block) ⇒ Object
(also: #on_remove)
call-seq: setOnRemoveHandler(proc=nil, &block).
-
#setOnUpdateHandler(cb_proc = nil, &cb_block) ⇒ Object
(also: #on_update)
call-seq: setOnUpdateHandler(proc=nil, &block).
-
#update(key, value) ⇒ Object
Updates a key value pair in the dictionary.
Methods inherited from Common
#close, #getAttached, #getChannel, #getChannelClass, #getChannelClassName, #getChannelName, #getChannelSubclass, #getDataInterval, #getDeviceChannelCount, #getDeviceClass, #getDeviceClassName, #getDeviceID, #getDeviceLabel, #getDeviceName, #getDeviceSKU, #getDeviceSerialNumber, #getDeviceVersion, #getHubPort, #getHubPortCount, #getIsChannel, #getIsHubPortDevice, #getIsLocal, #getIsRemote, #getServerHostname, #getServerName, #getServerPeerName, #getServerUniqueName, #open, #openWaitForAttachment, #setChannel, #setDataInterval, #setDeviceLabel, #setDeviceSerialNumber, #setHubPort, #setIsHubPortDevice, #setIsLocal, #setIsRemote, #setOnAttachHandler, #setOnDetachHandler, #setOnErrorHandler, #setOnPropertyChangeHandler, #setServerName, #writeDeviceLabel
Constructor Details
#new ⇒ Object
Creates a Phidget Dictionary object.
11 12 13 14 15 |
# File 'ext/phidgets/phidgets_dictionary.c', line 11
VALUE ph_dictionary_init(VALUE self) {
ph_data_t *ph = get_ph_data(self);
ph_raise(PhidgetDictionary_create((PhidgetDictionaryHandle *)(&(ph->handle))));
return self;
}
|
Instance Method Details
#add(key, value) ⇒ Object
Adds a new key value pair to the dictionary. It is an error if the key already exits.
17 18 19 20 |
# File 'ext/phidgets/phidgets_dictionary.c', line 17
VALUE ph_dictionary_add(VALUE self, VALUE key, VALUE value) {
ph_raise(PhidgetDictionary_add((PhidgetDictionaryHandle)get_ph_handle(self), StringValueCStr(key), StringValueCStr(value)));
return Qnil;
}
|
#get(key) ⇒ Object
Gets a key value. If more then one key matches, only the first value is returned.
22 23 24 25 26 |
# File 'ext/phidgets/phidgets_dictionary.c', line 22
VALUE ph_dictionary_get(VALUE self, VALUE key) {
char value[DICTIONARY_VALUE_LEN];
ph_raise(PhidgetDictionary_get((PhidgetDictionaryHandle)get_ph_handle(self), StringValueCStr(key), value, DICTIONARY_VALUE_LEN));
return rb_str_new2(value);
}
|
#remove(key) ⇒ Object
Removes the key from the dictionary.
28 29 30 31 |
# File 'ext/phidgets/phidgets_dictionary.c', line 28
VALUE ph_dictionary_remove(VALUE self, VALUE key) {
ph_raise(PhidgetDictionary_remove((PhidgetDictionaryHandle)get_ph_handle(self), StringValueCStr(key)));
return Qnil;
}
|
#removeAll ⇒ Object Also known as: remove_all
Removes every key from the dictionary.
33 34 35 36 |
# File 'ext/phidgets/phidgets_dictionary.c', line 33
VALUE ph_dictionary_remove_all(VALUE self) {
ph_raise(PhidgetDictionary_removeAll((PhidgetDictionaryHandle)get_ph_handle(self)));
return Qnil;
}
|
#scan(start_key) ⇒ Object
Scans the keys in the dictionary, indexed by start or the first key in the dictionary if start is NULL or an empty String. The result is formated as a newline seperated list of keys The list begins at the key following the start key The list might not contain all of the keys in the dictionary To continue scanning, call the method again with the last entry from the previous result When all of the keys have been scanned, a zero length string is returned Keys added during the scan may be missed, and keys deleted during the scan may be included.
38 39 40 41 42 |
# File 'ext/phidgets/phidgets_dictionary.c', line 38
VALUE ph_dictionary_scan(VALUE self, VALUE start_key) {
char list[DICTIONARY_VALUE_LEN * 10];
ph_raise(PhidgetDictionary_scan((PhidgetDictionaryHandle)get_ph_handle(self), StringValueCStr(start_key), list, DICTIONARY_VALUE_LEN * 10));
return rb_str_new2(list);
}
|
#set(key, value) ⇒ Object
Sets the value of a key, or creates the key value pair if the key does not already exist.
44 45 46 47 |
# File 'ext/phidgets/phidgets_dictionary.c', line 44
VALUE ph_dictionary_set(VALUE self, VALUE key, VALUE value) {
ph_raise(PhidgetDictionary_set((PhidgetDictionaryHandle)get_ph_handle(self), StringValueCStr(key), StringValueCStr(value)));
return Qnil;
}
|
#setOnAddHandler(cb_proc = nil, &cb_block) ⇒ Object Also known as: on_add
call-seq:
setOnAddHandler(proc=nil, &block)
Assigns a handler that will be called when the Add event occurs.
10 11 12 13 14 |
# File 'lib/phidgets/dictionary.rb', line 10 def setOnAddHandler(cb_proc = nil, &cb_block) @on_add_thread.kill if defined? @on_add_thread and @on_add_thread.alive? callback = cb_proc || cb_block @on_add_thread = Thread.new {ext_setOnAddHandler(callback)} end |
#setOnRemoveHandler(cb_proc = nil, &cb_block) ⇒ Object Also known as: on_remove
call-seq:
setOnRemoveHandler(proc=nil, &block)
Assigns a handler that will be called when the Remove event occurs.
21 22 23 24 25 |
# File 'lib/phidgets/dictionary.rb', line 21 def setOnRemoveHandler(cb_proc = nil, &cb_block) @on_remove_thread.kill if defined? @on_remove_thread and @on_remove_thread.alive? callback = cb_proc || cb_block @on_remove_thread = Thread.new {ext_setOnRemoveHandler(callback)} end |
#setOnUpdateHandler(cb_proc = nil, &cb_block) ⇒ Object Also known as: on_update
call-seq:
setOnUpdateHandler(proc=nil, &block)
Assigns a handler that will be called when the Update event occurs.
32 33 34 35 36 |
# File 'lib/phidgets/dictionary.rb', line 32 def setOnUpdateHandler(cb_proc = nil, &cb_block) @on_update_thread.kill if defined? @on_update_thread and @on_update_thread.alive? callback = cb_proc || cb_block @on_update_thread = Thread.new {ext_setOnUpdateHandler(callback)} end |
#update(key, value) ⇒ Object
Updates a key value pair in the dictionary. It is an error if the key does not exist.
49 50 51 52 |
# File 'ext/phidgets/phidgets_dictionary.c', line 49
VALUE ph_dictionary_update(VALUE self, VALUE key, VALUE value) {
ph_raise(PhidgetDictionary_update((PhidgetDictionaryHandle)get_ph_handle(self), StringValueCStr(key), StringValueCStr(value)));
return Qnil;
}
|