auto-sync

This commit is contained in:
rusEfi 2015-04-07 19:11:23 -05:00
parent c2d2a6ef0c
commit 53f3dd7238
4 changed files with 42 additions and 23 deletions

View File

@ -20,10 +20,10 @@ public:
void reset(); void reset();
T pop(); T pop();
T get(int index); T get(int index);
int size(); bool_t remove(T value);
bool isEmpty(); int size();bool isEmpty();
private: private:
int index; int currentSize;
T values[MAXSIZE]; T values[MAXSIZE];
}; };
@ -34,32 +34,47 @@ FLStack<T, MAXSIZE>::FLStack() {
template<typename T, int MAXSIZE> template<typename T, int MAXSIZE>
bool FLStack<T, MAXSIZE>::isEmpty() { bool FLStack<T, MAXSIZE>::isEmpty() {
return index == 0; return currentSize == 0;
} }
template<typename T, int MAXSIZE> template<typename T, int MAXSIZE>
void FLStack<T, MAXSIZE>::reset() { void FLStack<T, MAXSIZE>::reset() {
index = 0; currentSize = 0;
}
template<typename T, int MAXSIZE>
bool_t FLStack<T, MAXSIZE>::remove(T value) {
for (int i = 0; i < currentSize; i++) {
if (values[i] == value) {
values[0] = values[currentSize - 1];
currentSize--;
return true;
}
}
return false;
} }
template<typename T, int MAXSIZE> template<typename T, int MAXSIZE>
void FLStack<T, MAXSIZE>::push(T value) { void FLStack<T, MAXSIZE>::push(T value) {
if(index >= MAXSIZE) { if (currentSize >= MAXSIZE) {
firmwareError("FLstack overflow"); firmwareError("FLstack overflow");
return; return;
//warning() //warning()
} }
values[index++] = value; values[currentSize++] = value;
} }
template<typename T, int MAXSIZE> template<typename T, int MAXSIZE>
T FLStack<T, MAXSIZE>::pop() { T FLStack<T, MAXSIZE>::pop() {
if (index == 0) { if (currentSize == 0) {
firmwareError("FLStack is empty"); firmwareError("FLStack is empty");
} }
return values[--index]; return values[--currentSize];
} }
/**
* @return element at the specified index
*/
template<typename T, int MAXSIZE> template<typename T, int MAXSIZE>
T FLStack<T, MAXSIZE>::get(int index) { T FLStack<T, MAXSIZE>::get(int index) {
efiAssert(index >= 0 && index < MAXSIZE, "FLget", values[0]); efiAssert(index >= 0 && index < MAXSIZE, "FLget", values[0]);
@ -68,7 +83,7 @@ T FLStack<T, MAXSIZE>::get(int index) {
template<typename T, int MAXSIZE> template<typename T, int MAXSIZE>
int FLStack<T, MAXSIZE>::size() { int FLStack<T, MAXSIZE>::size() {
return index; return currentSize;
} }
template<class Type, int Dimention> template<class Type, int Dimention>

View File

@ -150,7 +150,7 @@ int main(void) {
testTriggerDecoder(); testTriggerDecoder();
// resizeMap(); // resizeMap();
printf("Success 20150213\r\n"); printf("Success 20150407\r\n");
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -9,10 +9,5 @@
#include "test_event_registry.h" #include "test_event_registry.h"
#include "main.h" #include "main.h"
static ActuatorEventList eventList;
static ActuatorEventList result;
extern int outputSignalCount;
void testEventRegistry(void) { void testEventRegistry(void) {
} }

View File

@ -362,6 +362,15 @@ void testFLStack(void) {
assertEquals(123, v); assertEquals(123, v);
assertEquals(0, stack.size()); assertEquals(0, stack.size());
stack.push(123);
stack.push(234);
stack.push(345);
stack.push(456);
assertEquals(4, stack.size());
stack.remove(123);
assertEquals(456, stack.get(0));
assertEquals(3, stack.size());
} }
static char buff[32]; static char buff[32];