#include <Container.hpp>
Pros : Almost as fast as array's access time once constructed. Element order is always preserved. Cons : Construction / Adding and Remove operations are slow (but faster than array) because of some copying is done for each pointer in the list
It's best if used like
// Create an index list IndexList<MyObj> myList; myList.Append(new MyObj(something)); // This will delete the inserted object by using the selected policy (delete in this example) myList.Remove(0); myList.insertBefore(2, new MyObj(foo)); // Index can be out of range myList.insertBefore(0, new MyObj(bar)); // Get a reference on the list element const MyObj & ref = myList[1]; // Search for an element based on its address assert(1 == myList.indexOf(&ref)); // Search for an element based on its value (much slower) assert(1 == myList.indexOfMatching(ref));
Policy must follow the MemoryPolicy interface
Public Member Functions | |
| void | Append (const TPtr &ref) throw () |
| Append an element to the end of the array. | |
| void | Clear () |
| Clear the array, and destruct any remaining objects. | |
| TPtr & | getElementAtUncheckedPosition (uint32 index) |
| Fast access operator, but doesn't check the index given in. | |
| size_t | getSize () const |
| Access size member. | |
| IndexList (const IndexList &other) | |
| Copy constructor. | |
| IndexList () | |
| Default Constructor. | |
| uint32 | indexOf (const TPtr &objectToSearch) |
| Search operator. | |
| uint32 | indexOfMatching (const TElem &objectToSearch) |
| Search operator. | |
| void | insertBefore (uint32 index, const TPtr &ref) throw () |
| Insert an element just before the given index. | |
| uint32 | lastIndexOf (const TPtr &objectToSearch) |
| Reverse search operator. | |
| const IndexList & | operator= (const IndexList &other) |
| Classic copy operator. | |
| bool | operator== (const IndexList &other) |
| Compare operator. | |
| TElem & | operator[] (uint32 index) |
| Access operator. | |
| void | Remove (uint32 index) throw () |
| Remove an object from the array. | |
| ~IndexList () | |
| Destructor. | |
| Container::PrivateGenericImplementation::IndexList< TElem, Policy, ExactSize >::IndexList | ( | ) | [inline] |
Default Constructor.
| Container::PrivateGenericImplementation::IndexList< TElem, Policy, ExactSize >::IndexList | ( | const IndexList< TElem, Policy, ExactSize > & | other | ) | [inline] |
Copy constructor.
| Container::PrivateGenericImplementation::IndexList< TElem, Policy, ExactSize >::~IndexList | ( | ) | [inline] |
Destructor.
| void Container::PrivateGenericImplementation::IndexList< TElem, Policy, ExactSize >::Append | ( | const TPtr & | ref | ) | throw () [inline] |
Append an element to the end of the array.
| void Container::PrivateGenericImplementation::IndexList< TElem, Policy, ExactSize >::Clear | ( | ) | [inline] |
Clear the array, and destruct any remaining objects.
| TPtr& Container::PrivateGenericImplementation::IndexList< TElem, Policy, ExactSize >::getElementAtUncheckedPosition | ( | uint32 | index | ) | [inline] |
Fast access operator, but doesn't check the index given in.
| size_t Container::PrivateGenericImplementation::IndexList< TElem, Policy, ExactSize >::getSize | ( | ) | const [inline] |
Access size member.
| uint32 Container::PrivateGenericImplementation::IndexList< TElem, Policy, ExactSize >::indexOf | ( | const TPtr & | objectToSearch | ) | [inline] |
Search operator.
| objectToSearch | The object to look for in the array based on the given address |
| uint32 Container::PrivateGenericImplementation::IndexList< TElem, Policy, ExactSize >::indexOfMatching | ( | const TElem & | objectToSearch | ) | [inline] |
Search operator.
| objectToSearch | The object to look for in the array |
| void Container::PrivateGenericImplementation::IndexList< TElem, Policy, ExactSize >::insertBefore | ( | uint32 | index, | |
| const TPtr & | ref | |||
| ) | throw () [inline] |
Insert an element just before the given index.
| index | Zero based index of the element once inserted |
| uint32 Container::PrivateGenericImplementation::IndexList< TElem, Policy, ExactSize >::lastIndexOf | ( | const TPtr & | objectToSearch | ) | [inline] |
Reverse search operator.
| objectToSearch | The object to look for in the array |
| const IndexList& Container::PrivateGenericImplementation::IndexList< TElem, Policy, ExactSize >::operator= | ( | const IndexList< TElem, Policy, ExactSize > & | other | ) | [inline] |
Classic copy operator.
| bool Container::PrivateGenericImplementation::IndexList< TElem, Policy, ExactSize >::operator== | ( | const IndexList< TElem, Policy, ExactSize > & | other | ) | [inline] |
Compare operator.
| TElem& Container::PrivateGenericImplementation::IndexList< TElem, Policy, ExactSize >::operator[] | ( | uint32 | index | ) | [inline] |
Access operator.
| index | The position in the array |
| void Container::PrivateGenericImplementation::IndexList< TElem, Policy, ExactSize >::Remove | ( | uint32 | index | ) | throw () [inline] |
Remove an object from the array.
| index | Index of the object to remove |
