ObjectType:queue
From Lavish Software Wiki
Contents |
[edit]
Overview
| queue | |
| Defined By | LavishScript |
| Inherits | objectcontainer |
| Reduces To | NULL |
| Variable Object Type | queue |
| Uses Sub-Types | yes |
| C/C++ Type | LSQueue * |
A queue is a first-in first-out (as if waiting in a line) list of objects.
[edit]
Members
- sub-type Peek: Retrieves the first object in the queue (first in line)
[edit]
Methods
- Queue[...]: Adds an object to the queue, passing any parameters to the initialization for the given object type
- Dequeue: Removes the first object in the queue
- Clear: Clears all objects in the queue
[edit]
Declaring queue Variables
Queue objects require a sub-type -- an object type to be a queue of. Append the sub-type to the word queue, with a colon separating the words. It is possible to have sub-subtypes (such as queue:queue:int for a queue of queues of ints).
[edit]
Example 1
Declaring a queue of "int"
variable queue:int MyQueue
[edit]
Adding items to a queue
To add an item to a queue, use the Queue method, as demonstrated in this example
[edit]
Example 1
variable queue:int MyQueue MyQueue:Queue[15] MyQueue:Queue[25]
[edit]
Removing items from a queue
Items are removed in the order queued -- the first item queued is the first that will be removed. To remove an item, use the Dequeue method, as demonstrated in this example
[edit]
Example 1
variable queue:int MyQueue MyQueue:Queue[15] MyQueue:Queue[25] MyQueue:Dequeue /* Only 25 is now in the queue */
[edit]
Viewing the queue
To access the first object in the queue (e.g. the first person in line), use the Peek member, as demonstrated in this example
[edit]
Example 1
variable queue:int MyQueue
MyQueue:Queue[15]
MyQueue:Queue[25]
echo \${MyQueue.Peek} should be 15: ${MyQueue.Peek}
MyQueue:Dequeue
/* Only 25 is now in the queue */
echo \${MyQueue.Peek} should be 25: ${MyQueue.Peek}
[edit]
