The MGC3130 is the world’s first electrical-field (E-field) based three-dimensional (3D) tracking and gesture controller
Dependents: NucleoMGC3130 i2c_master
Diff: GestILibrarMessage/BufferedArray.cpp
- Revision:
- 8:de7934ec7ea2
- Parent:
- 7:eacd776fce29
--- a/GestILibrarMessage/BufferedArray.cpp Thu Oct 15 16:10:55 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,129 +0,0 @@ -#include "BufferedArray.h" - -BufferedArray::BufferedArray() -{ - max = EXPANDSIZE; - data = new char[EXPANDSIZE]; - index = 0; -} - -BufferedArray::BufferedArray(int size) -{ - max = size; - data = new char[size]; - index = 0; -} - -BufferedArray::BufferedArray(BufferedArray * bufferedArray) -{ - this->data = bufferedArray->data; - this->index = bufferedArray->index; -} - -BufferedArray::~BufferedArray() -{ - if (data == NULL) - return; - - delete[] data; -} - -char * BufferedArray::gets() -{ - return data; -} - -char * BufferedArray::gets(int position) -{ - return data + position; -} - -char BufferedArray::get(int position) -{ - return *(data + position); -} - -int BufferedArray::getPosition() -{ - return index; -} - -void BufferedArray::setPosition(int position) -{ - if (this->index > max) - this->index = max; - else this->index = position; -} - -void BufferedArray::allocate(int length) -{ - if (length <= 0) - return; - - if (length > max) { - delete[] data; - data = new char[length]; - } - - rewind(); -} - -void BufferedArray::rewind() -{ - index = 0; -} - -void BufferedArray::expandSpace(int length) -{ - max += EXPANDSIZE * (1 + length / EXPANDSIZE); - char * temp = new char[max]; - memcpy(temp, data, index); - delete[] data; - data = temp; -} - -void BufferedArray::set(int position, char value) -{ - if (position < 0) - return; - - if (position >= max) - expandSpace(1); - - data[position] = value; -} - -void BufferedArray::set(char value) -{ - set(index, value); - index++; -} - -void BufferedArray::sets(const char * value, int offset, int length) -{ - if (length <= 0) - return; - - if (offset < 0) - return; - - sets(index, value, offset, length); - index += length; -} - -void BufferedArray::sets(int position, const char * value, int offset, int length) -{ - if (position < 0) - return; - - if (length <= 0) - return; - - if (offset < 0) - return; - - if (position + length - offset > max) - expandSpace(position + length - offset - max); - - memcpy(data + position, value + offset, length); -} \ No newline at end of file