STL Container IB Reference

From CometWiki

Revision as of 00:07, 23 November 2011 by Skrach (Talk | contribs)
Jump to: navigation, search

Contents

Core Functions

Vector

stlPushBack( <container-name>, <data> ) adds an element to the end of the vector
stlPopBack( <container-name> ) removes the element at the end of the vector
stlFront( <container-name> ) gets the element at the front of the vector
stlBack( <container-name> ) gets the element at the end of the vector
stlSet <container-name> <index> <data> sets the element at the index specified
<container-name>( <index> ) gets the element at the index specified

Similar to arrays, vectors are mostly used to access data based on a numeric index, thus the () operator and stlSet are going to be your bread and butter functions for this container. stlPushBack is a great way to programatically build a vector - it will append the specified data to the end of the vector, and increase its size by 1. If you want to remove the last element, you would use stlPopBack. Then the stlFront and stlBack functions have been included as shortcuts for accessing the first and last elements respectively.

List

stlPushBack( <container-name>, <data> ) adds an element to the end of the list
stlPopBack( <container-name> ) removes the element at the end of the list
stlPushFront( <container-name>, <data> ) adds an element to the beginning of the list
stlPopFront( <container-name> ) removes the element at the beginning of the list
stlFront( <container-name> ) gets the element at the beginning of the list
stlBack( <container-name> ) gets the element at the end of the list

Map

stlSet <container-name> <key> <data> sets the element at the key specified
<container-name>( <key> ) gets the element at the key specified

Stack/Queue

stlPush( <container-name>, <data> ) adds an element to the container
stlPop( <container-name> ) removes the next element from the container
stlPeek( <container-name> ) gets the next element from the container
stlSet <container-name> <index> <data> sets the element at the index specified
<container-name>( <index> ) gets the element at the index specified

Both stacks and queues utilize the same set of functions, but perform differently depending on which container you have implemented. In general, the stlPush, stlPop, and stlPeek functions are going to be the most important of these functions. They perform the basic operations associated with these containers. For stacks, stlPush and stlPop adds and removes from the end of the container. For queues, stlPush adds to the end of the container, and stlPop removes from the front of the container. For both containers, stlPeek will get the "next" element in the container (i.e. the last element for stacks, the first element for queues).

Because these containers are implemented with deques internally, we also provide access via numeric indexes with the stlSet and () operator. These functions behave similarly to the vector functions of the same name, by getting and setting the elements at the specified index.

Iteration Functions

These functions are used to iterate over the elements of a container.

stlfirst( <container-name> ) sets the iterator position at the beginning
stlLast( <container-name> ) sets the iterator position at the end
stlNext( <container-name> ) moves the iterator position forward one element
stlPrev( <container-name> ) moves the iterator position back one element
stlRead( <container-name> ) gets the element at the current iterator position
stlWrite( <container-name>, <data> ) - sets the element at the current iterator position

Utility Functions

These are basic functions that return information about the specified container.

stlSize( <container-name> ) returns the size of the container
stlEmpty( <container-name> ) returns whether the container is empty
stlClear( <container-name> ) empties the specified container
stlReset( <container-name> ) resets the container to its initial values

Meta Functions

These functions perform some action either on all of the elements in the container, or using all the elements in the container.

Personal tools