added new sanity checks and compile-time assertions to prevent errors
fixed stair-building issue new test-cases added elevator support fixed/improved some walker modules
This commit is contained in:
@@ -21,14 +21,18 @@ public:
|
||||
;
|
||||
}
|
||||
|
||||
/** add a new element */
|
||||
void add(const Element& element) {
|
||||
/** add a new element WITH overflow check! */
|
||||
void addSafe(const Element& element) {
|
||||
Assert::isTrue(available != (int)data.size(), "buffer overflow");
|
||||
add(element);
|
||||
}
|
||||
|
||||
/** add a new element WIUTHOUT checking for overflows */
|
||||
void add(const Element& element) {
|
||||
data[iWrite] = element;
|
||||
++iWrite;
|
||||
iWrite %= data.size();
|
||||
++available;
|
||||
//if (available > (int)data.size()) {available = data.size();}
|
||||
}
|
||||
|
||||
/** get the next element */
|
||||
@@ -42,6 +46,25 @@ public:
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/** peek into the given element without removing it */
|
||||
const Element& peek(const int idx) const {
|
||||
const Element& tmp = data[(iRead + idx) % data.size()];
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/** peek into the given element without removing it */
|
||||
const Element& operator [] (const int idx) const {
|
||||
return peek(idx);
|
||||
}
|
||||
|
||||
/** does the buffer contain the given element? */
|
||||
bool contains(const Element& e) const {
|
||||
for (int i = 0; i < available; ++i) {
|
||||
if (peek(i) == e) {return true;}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** reset the ringbuffer */
|
||||
void reset() {
|
||||
iWrite = 0;
|
||||
|
||||
Reference in New Issue
Block a user