Description | Method Name | Method Procedure |
Extend a list | TM_LIST_EXTEND | TmListExtend |
Append to a list | TM_LIST_APPEND | TmListAppend |
Insert in a list | TM_LIST_INSERT | TmListInsert |
Retrieve from a list | TM_LIST_RETRIEVE | TmListRetrieve |
Replace a list element | TM_LIST_REPLACE | TmListReplace |
Delete (Undo) previous change to a list | TM_LIST_DELETE | TmListDelete |
Clear list elements | TM_LIST_CLEAR | TmListClear |
Destroy list elements | TM_LIST_DESTROY | TmListDestroy |
note | Code for the default list method procedures are contained in the file, where WAVE_DIR is the the main PV‑WAVE directory. |
; Create the method procedure.
PRO MyListAppend, tool_name, list_name, item
DECLARE FUNC, TmGetAttribute
DECLARE FUNC, TmSetAttribute
items = TmGetAttribute(tool_name, list_name, 'ITEMS')
free = TmGetAttribute(tool_name, list_name, 'FREE')
IF free GE N_ELEMENTS(items) THEN BEGIN
TmListExtend, tool_name, list_name
items = TmGetAttribute(tool_name, list_name, 'ITEMS')
ENDIF
IF item NE 'Dont_Add' THEN BEGIN
items(free) = item
s = TmSetAttribute(tool_name, list_name, 'ITEMS', items)
s = TmSetAttribute(tool_name, list_name, 'FREE', free+1)
ENDIF
END
; Create a list and append to it.
list_name = TmList(tool_name)
TmListSetMethod, tool_name, list_name, 'TM_LIST_APPEND', $
'MyListAppend'
TmListAppend, tool_name, list_name, 'First Item'
INFO, TmListRetrieve(tool_name, list_name), /Full
; PV-WAVE prints the following:
; <Expression> LIST = List(1)
; STRING = 'First Item'
; TmListAppend, tool_name, list_name, 'Dont_Add'
INFO, TmListRetrieve(tool_name, list_name), /Full
; PV-WAVE prints the following:
; <Expression> LIST = List(1)
; STRING = 'First Item'
; Use TmListGetMethod to access the name of the method and
; execute it explicitly.
new_var = 'Second Item'
var_name = 'new_var'
method = TmListGetMethod(tool_name, list_name, 'TM_LIST_APPEND')
INFO, method
; PV-WAVE prints: METHOD STRING = 'MyListAppend'
s = EXECUTE(method + ', tool_name, list_name, ' + var_name)
INFO, TmListRetrieve(tool_name, list_name), /Full
; PV-WAVE prints the following:
; <Expression> LIST = List(2)
; STRING = 'First Item'
; STRING = 'Second Item'