XBee and XBee-PRO ZigBee RF modules provide cost-effective wireless connectivity to electronic devices. They are interoperable with other ZigBee PRO feature set devices, including devices from other vendors.
Diff: Core/BufferedArray.cpp
- Revision:
- 6:5f31ddc17239
- Parent:
- 5:945b89c71902
--- a/Core/BufferedArray.cpp Thu Nov 05 23:03:42 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,133 +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) -{ - if (bufferedArray != NULL) { - this->data = bufferedArray->data; - this->index = bufferedArray->index; - this->max = bufferedArray->max; - } -} - -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) { - if (data != NULL) - 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