3ea780cdf9
some heuristic: when you booted from a CD, CDs are preferred; else, volumes with names like "Haiku" or "System" are preferred - if someone has better ideas, please shout. Note, this heuristic will only come into play if the boot loader was loaded from an image (ie. floppy/CD/network), and you didn't choose any boot device. Added evil methods to the Stack class that come in handy (you can now directly access the array) for this. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14410 a95241bf-73f2-0310-859d-f6bbb57e9c96
79 lines
1.1 KiB
C++
79 lines
1.1 KiB
C++
/* Stack - a template stack class (plus some handy methods)
|
|
*
|
|
* Copyright 2001-2005, Axel Dörfler, axeld@pinc-software.de.
|
|
* This file may be used under the terms of the MIT License.
|
|
*/
|
|
#ifndef KERNEL_UTIL_STACK_H
|
|
#define KERNEL_UTIL_STACK_H
|
|
|
|
|
|
#include <SupportDefs.h>
|
|
|
|
|
|
template<class T> class Stack {
|
|
public:
|
|
Stack()
|
|
:
|
|
fArray(NULL),
|
|
fUsed(0),
|
|
fMax(0)
|
|
{
|
|
}
|
|
|
|
~Stack()
|
|
{
|
|
free(fArray);
|
|
}
|
|
|
|
bool IsEmpty() const
|
|
{
|
|
return fUsed == 0;
|
|
}
|
|
|
|
void MakeEmpty()
|
|
{
|
|
// could also free the memory
|
|
fUsed = 0;
|
|
}
|
|
|
|
status_t Push(T value)
|
|
{
|
|
if (fUsed >= fMax) {
|
|
fMax += 16;
|
|
T *newArray = (T *)realloc(fArray, fMax * sizeof(T));
|
|
if (newArray == NULL)
|
|
return B_NO_MEMORY;
|
|
|
|
fArray = newArray;
|
|
}
|
|
fArray[fUsed++] = value;
|
|
return B_OK;
|
|
}
|
|
|
|
bool Pop(T *value)
|
|
{
|
|
if (fUsed == 0)
|
|
return false;
|
|
|
|
*value = fArray[--fUsed];
|
|
return true;
|
|
}
|
|
|
|
T *Array()
|
|
{
|
|
return fArray;
|
|
}
|
|
|
|
int32 CountItems() const
|
|
{
|
|
return fUsed;
|
|
}
|
|
|
|
private:
|
|
T *fArray;
|
|
int32 fUsed;
|
|
int32 fMax;
|
|
};
|
|
|
|
#endif /* KERNEL_UTIL_STACK_H */
|