Read lifo

Purpose: Reads key/value pair from a LIFO list.

 read-lifo <list> \
     key <key> \
     value <value> \
     [ status <status> ]

read-lifo retrieves an element from the LIFO <list> into <key> string  (in "key" clause) and <value> string (in "value" clause).

Once an element has been retrieved, the next use of read-lifo will obtain the following one, in the reverse order they were put in. read-lifo starts with the last element put in, and moves backwards from there, unless rewind-lifo is called, which positions back to the last one. Note that write-lifo will cause the next read-lifo to start with the element just written, i.e. it implicitly calls rewind-lifo.

If the element is successfuly retrieved, <status> number (in "status" clause) is GG_OKAY, otherwise it is GG_ERR_EXIST, which means there are no more elements to retrieve.
Examples
In this example, a LIFO list is created, and two key/value pairs added. They are then retrieved in a loop and printed out (twice with rewind), and then the list is purged:
 %% /lifo
     new-lifo mylist

     // Add data to the list
     write-lifo mylist key "key1" value "value1"
     write-lifo mylist key "some2" value "other2"

     start-loop
        // Get data from the list
        read-lifo mylist key k value v status st

        // Check if no more data
        if-true st not-equal GG_OKAY
            break-loop
        end-if

        @Obtained key <<p-out k>> with value <<p-out v>>
     end-loop

     // Go through the list again, use rewind-lifo for that
     rewind-lifo mylist

     start-loop
        read-lifo mylist key k value v status st
        if-true st not-equal GG_OKAY
            break-loop
        end-if
        @Again obtained key <<p-out k>> with value <<p-out v>>
     end-loop

     // Delete all in LIFO
     purge-lifo mylist
     // Verify nothing is left
     rewind-lifo mylist
     read-lifo mylist key k value v status st
     if-true st not-equal GG_OKAY
        @LIFO is empty
     end-if
 %%

See also
LIFO
delete-lifo  
new-lifo  
purge-lifo  
read-lifo  
rewind-lifo  
write-lifo  
See all
documentation


Copyright (c) 2019-2024 Gliim LLC. All contents on this web site is "AS IS" without warranties or guarantees of any kind.