#include <FIFO.hpp>
The stack takes care of deleting the pushed pointer when destructed or reallocated (size zeros and grow again) If you plan to use copy constructor or operator =, the objects must provide a "clone" method.
Stack::WithClone::FIFO<MyClass> stack; // Push some data onto this stack stack.Push(new MyClass(...)); stack.Push(new MyDerivedClass(...)); // Pop them MyClass * t = stack.Pop(); // Don't delete the popped pointer MyClass * t2 = stack.Pop(); // t3 will be NULL, but t and t2 still points to valid memory MyClass * t3 = stack.Pop(); // This will invalidate t and t2 ( because stack.size is zero ) stack.Push(new MyChildClass(3)); t2->SomeMethod(); //<== This will crash the program as t2 is now deleted // This will use virtual MyClass::clone method Stack::WithClone::FIFO<MyClass> stack2 = stack; // On leaving scope, the array will be destructed, so will MyChildClass instance.
Public Member Functions | |
FIFO (const FIFO &other) | |
Copy constructor. | |
FIFO () | |
Default Constructor. | |
bool | Forget (T *avoidDeleting=NULL) |
Tell the stack it is no more required to delete the given pop'd pointer. | |
size_t | getSize () const |
Access size member. | |
const FIFO & | operator= (const FIFO< T > &fifo) |
Classic copy operator. | |
T * | Pop () |
Pop an element from the list. | |
void | Push (T *ref) |
Push an element to the list. | |
void | Reset () |
Reset the FIFO. | |
~FIFO () | |
Destructor. |
Stack::WithClone::FIFO< T >::FIFO | ( | ) | [inline] |
Default Constructor.
Stack::WithClone::FIFO< T >::FIFO | ( | const FIFO< T > & | other | ) | [inline] |
Copy constructor.
Stack::WithClone::FIFO< T >::~FIFO | ( | ) | [inline] |
Destructor.
bool Stack::WithClone::FIFO< T >::Forget | ( | T * | avoidDeleting = NULL |
) | [inline] |
Tell the stack it is no more required to delete the given pop'd pointer.
false if the pointer hasn't been pop'd yet, or not found
size_t Stack::WithClone::FIFO< T >::getSize | ( | ) | const [inline] |
Access size member.
const FIFO& Stack::WithClone::FIFO< T >::operator= | ( | const FIFO< T > & | fifo | ) | [inline] |
Classic copy operator.
T* Stack::WithClone::FIFO< T >::Pop | ( | ) | [inline] |
Pop an element from the list.
void Stack::WithClone::FIFO< T >::Push | ( | T * | ref | ) | [inline] |
Push an element to the list.
void Stack::WithClone::FIFO< T >::Reset | ( | ) | [inline] |
Reset the FIFO.