2014-08-29 07:52:33 -07:00
|
|
|
/**
|
|
|
|
* @file fl_stack.h
|
|
|
|
* @brief Fixed-length stack
|
|
|
|
*
|
|
|
|
* @date Jul 9, 2014
|
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2014
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef FL_STACK_H_
|
|
|
|
#define FL_STACK_H_
|
|
|
|
|
2014-12-27 13:03:38 -08:00
|
|
|
#include "error_handling.h"
|
|
|
|
|
2014-08-29 07:52:33 -07:00
|
|
|
template<typename T, int MAXSIZE>
|
|
|
|
class FLStack {
|
|
|
|
public:
|
|
|
|
FLStack();
|
|
|
|
void push(T value);
|
2014-10-03 12:05:03 -07:00
|
|
|
void reset();
|
2014-08-29 07:52:33 -07:00
|
|
|
T pop();
|
2014-10-03 15:03:01 -07:00
|
|
|
T get(int index);
|
2014-08-29 07:52:33 -07:00
|
|
|
int size();
|
|
|
|
bool isEmpty();
|
|
|
|
private:
|
|
|
|
int index;
|
|
|
|
T values[MAXSIZE];
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T, int MAXSIZE>
|
|
|
|
FLStack<T, MAXSIZE>::FLStack() {
|
2014-10-03 12:05:03 -07:00
|
|
|
reset();
|
2014-08-29 07:52:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T, int MAXSIZE>
|
|
|
|
bool FLStack<T, MAXSIZE>::isEmpty() {
|
|
|
|
return index == 0;
|
|
|
|
}
|
|
|
|
|
2014-10-03 12:05:03 -07:00
|
|
|
template<typename T, int MAXSIZE>
|
|
|
|
void FLStack<T, MAXSIZE>::reset() {
|
|
|
|
index = 0;
|
|
|
|
}
|
|
|
|
|
2014-08-29 07:52:33 -07:00
|
|
|
template<typename T, int MAXSIZE>
|
|
|
|
void FLStack<T, MAXSIZE>::push(T value) {
|
|
|
|
values[index++] = value;
|
|
|
|
}
|
|
|
|
|
2014-10-03 12:05:03 -07:00
|
|
|
template<typename T, int MAXSIZE>
|
|
|
|
T FLStack<T, MAXSIZE>::pop() {
|
2014-10-07 08:04:35 -07:00
|
|
|
if (index == 0) {
|
2014-10-05 07:03:00 -07:00
|
|
|
firmwareError("FLStack is empty");
|
|
|
|
}
|
2014-10-07 08:04:35 -07:00
|
|
|
return values[--index];
|
2014-10-03 12:05:03 -07:00
|
|
|
}
|
|
|
|
|
2014-10-03 15:03:01 -07:00
|
|
|
template<typename T, int MAXSIZE>
|
|
|
|
T FLStack<T, MAXSIZE>::get(int index) {
|
|
|
|
return values[index];
|
|
|
|
}
|
2014-10-03 12:05:03 -07:00
|
|
|
|
2014-08-29 07:52:33 -07:00
|
|
|
template<typename T, int MAXSIZE>
|
|
|
|
int FLStack<T, MAXSIZE>::size() {
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2015-01-01 15:04:13 -08:00
|
|
|
template <class Type, int Dimention>
|
|
|
|
class ArrayList {
|
|
|
|
public:
|
|
|
|
int size;
|
|
|
|
Type elements[Dimention];
|
|
|
|
void reset(void);
|
|
|
|
Type *add(void);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class Type, int Dimention>
|
|
|
|
void ArrayList< Type, Dimention>::reset(void) {
|
|
|
|
size = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Type, int Dimention>
|
|
|
|
Type * ArrayList< Type, Dimention>::add(void) {
|
|
|
|
efiAssert(size < Dimention, "add() too many elements", (Type *)NULL);
|
|
|
|
return &elements[size++];
|
|
|
|
}
|
|
|
|
|
2014-08-29 07:52:33 -07:00
|
|
|
#endif /* FL_STACK_H_ */
|