List template

From Solid Graphics Wiki

(Redirected from List)
Jump to: navigation, search
List template
Namespace: SKL
Base type: (None)
Include: SklList.h
Lib (Release): SKL.lib
Lib (Debug): SKL_D.lib


The List template is a C++ template for making one-dimensional arrays/lists. The template is defined as:

template < class T, bool useConstructorAndDestructor = true > class List;

The T is type of the objects in the list, the useConstructorAndDestructor template argument specifies whether the methods of the template should use constructor and destructors while adding, copying, and deleting the T objects into/in/from the list. If the useConstructorAndDestructor is specified as false then the template uses memcpy functions to copy/clone objects and does not call a destructor when an object is removed from the list.


Constructors

The List template provide constructor with no parameters, copy constructor to allow initialize the list from another list, a constructor for allocating the list using initial capacity, or to initialize the list from C array of T objects.

Fields

The template providesno public fields.

Methods

Method name Description
Clear Removes all the items from the list and sets the list capacity to zero.
Reserve Sets the list capacity to specified value. Setting the capacity first ensures that the internal data buffer for the list items won't be reallocated if number of items added to the list does not exceed teh capacity value.
Append Appends a item to th end of the list. If the capacity of the list is not big enough to hold the new item then the capacity of the list is doubled.
Insert Inserts list item to the specified position in the list. If the capacity of the list is not big enough to hold the new item then the capacity of the list is doubled.
InsertSorted To use this method the items in the list must be sorted in ascending order. The InsertSorted method inserts the specified value into the list so the list remains sorted. If the capacity of the list is not big enough to hold the new item then the capacity of the list is doubled.
InsertOrReplace To use this method the items in the list must be sorted in ascending order. The InsertOrReplace method inserts the specified value into the list so the list remains sorted. If the list already contais the specified value then the old value is replaced with the new value. If the capacity of the list is not big enough to hold the new item then the capacity of the list is doubled.
SetTo Sets either all item values in the list to specified value, or sets the list to values and count from the specified C array of the values.
SwapItems Swaps two items in the list.
QuickErase Erases item at specified index. If the item is not a last item then the last list item is copied into the erased item's position, rather than shifting the rest of the items in memory. Be aware that this method does not keet the list's items order.
Erase Erases the list item while keeping the list's sort order.
EraseLast Erases last item from the list.
EraseSortedValue To use this method the items in the list must be sorted in ascending order. The method erases specified item value from the list. It uses the binary-search algorithm to find the item's position rather than linearly scanning through the list to find the item. If the list contains more items with the same value then the method does not necessarily erase the first such value. If the item value was erasd the method returns true, if the value was not found in the list the method returns false.
EraseValue Erases specified value from the list. It uses linear search from beginning of the list to find the item's index. If the value is found and erased the method returns true, if not then it returns false.
EraseDuplicates To use this method the items in the list must be sorted in ascending order. The method erases all duplicate values from the list. For example in list of integer values, if the list contains values { 1, 2, 2, 4, 5, 5, 5, 7 }, then after running the method the list will contain values { 1, 2, 4, 5, 7 }.
Reverse Reverses order of the items in the list.
Count Returns current number of items in the list.
Capacity Returns current list's capacity. The capacity of the list is the size of the list's internal buffer allocated for holding the items.
IsEmpty Returns true if number of items in the list is zero, otherwise returns false.
Sort Sorts the items in the list in ascending order.
Find Finds index of the first item of specified value in the list using linear search from beginning og the list. If the value is not found then the method returns -1.
FindSorted To use this method the items in the list must be sorted in ascending order. The method returns index of an item with specified value using binary search algorithm. If the list contain more items with the same value then the method does not necessarily return index of first such value. If the value is not found then the method returns -1.
FindEqualOrGreater To use this method the items in the list must be sorted in ascending order. The method finds index of item with value equal or greater than the specified value using binary-search algorithm. If the list contain more items with the same value then the method does not necessarily return index of first such value. If the list is empty the method return value is 0.
LastItem Returns value of the last list item.
Data Returns C pointer to list items. The pointer can be used to get or set list values - while it can be faster it is considered less safe practice. Do not cache returned pointer value as the list's buffer might be reallocated when new items are added to the list or it's capacity is increased!
SetCount Sets list's count to specified value. If the value is less than current count then the item past the specified count are erased. If the value is more than current count then new list items are initialized by item's type constructor. If the list is defined with useConstructorAndDestructor argumend as false then the new list items are left uninitialized.

Operators

= Assigns one list to another.
[ ] Inline mothod which allows to access list items by the item index.
== Compares two lists, if the lists contain the same items count and the same item values in the same order - then the operator returns true, otherwise returns false.
!= Compares two lists, if the lists do not contain the same items count. or the same item values in the same order - then the operator returns false, otherwise returns false.

See Also


   


SolidKit Library Documentation

Personal tools