unsigned char array

Dependents:   MGC3130 SmartLabXBeeCore

Files at this revision

API Documentation at this revision

Comitter:
yangcq88517
Date:
Thu Nov 12 02:41:54 2015 +0000
Parent:
1:77c1ea04eb5a
Commit message:
bug fix

Changed in this revision

BufferedArray.cpp Show annotated file Show diff for this revision Revisions of this file
BufferedArray.h Show annotated file Show diff for this revision Revisions of this file
--- a/BufferedArray.cpp	Thu Nov 12 02:06:49 2015 +0000
+++ b/BufferedArray.cpp	Thu Nov 12 02:41:54 2015 +0000
@@ -1,6 +1,6 @@
 #include "BufferedArray.h"
 
-BufferedArray::BufferedArray(int initialLength, int expandSize)
+BufferedArray::BufferedArray(unsigned int initialLength, unsigned int expandSize)
 {
     this->expandSize = expandSize;
     max = initialLength;
@@ -31,12 +31,12 @@
     return data;
 }
 
-unsigned char * BufferedArray::gets(int position)
+unsigned char * BufferedArray::gets(unsigned long position)
 {
     return data + position;
 }
 
-unsigned char BufferedArray::get(int position)
+unsigned char BufferedArray::get(unsigned long position)
 {
     return *(data + position);
 }
@@ -46,14 +46,14 @@
     return index;
 }
 
-void BufferedArray::setPosition(int position)
+void BufferedArray::setPosition(unsigned long position)
 {
     if (this->index > max)
         this->index = max;
     else this->index = position;
 }
 
-void BufferedArray::allocate(int length)
+void BufferedArray::allocate(unsigned long length)
 {
     if (length <= 0)
         return;
@@ -72,7 +72,7 @@
     index = 0;
 }
 
-void BufferedArray::expandSpace(int length)
+void BufferedArray::expandSpace(unsigned long length)
 {
     max += expandSize * (1 + length / expandSize);
     unsigned char * temp = new unsigned char[max];
@@ -81,11 +81,8 @@
     data = temp;
 }
 
-void BufferedArray::set(int position, unsigned char value)
+void BufferedArray::set(unsigned long position, unsigned char value)
 {
-    if (position < 0)
-        return;
-
     if (position >= max)
         expandSpace(position - max + 1);
 
@@ -98,7 +95,7 @@
     index++;
 }
 
-void BufferedArray::sets(const unsigned char * value, int offset, int length)
+void BufferedArray::sets(const unsigned char * value, unsigned long offset, unsigned long length)
 {
     if (length <= 0)
         return;
@@ -107,11 +104,8 @@
     index += length;
 }
 
-void BufferedArray::sets(int position, const unsigned char * value, int offset, int length)
+void BufferedArray::sets(unsigned long position, const unsigned char * value, unsigned long offset, unsigned long length)
 {
-    if (position < 0)
-        return;
-
     if (length <= 0)
         return;
 
--- a/BufferedArray.h	Thu Nov 12 02:06:49 2015 +0000
+++ b/BufferedArray.h	Thu Nov 12 02:41:54 2015 +0000
@@ -10,21 +10,21 @@
 {
 protected :
     /// initial size and automatically increase length.
-    int expandSize;
+    unsigned int expandSize;
 
     /// Raw data
     unsigned char * data;
 
     /// Current index of the data, could also used as data lendth.
-    int index;
+    unsigned long index;
 
     /// Max data size that the raw data can hold.
-    int max;
+    unsigned long max;
     
-    void expandSpace(int length);
+    void expandSpace(unsigned long length);
 
 public:
-    BufferedArray(int initialLength, int expandSize);
+    BufferedArray(unsigned int initialLength, unsigned int expandSize);
 
     BufferedArray(BufferedArray * bufferedArray);
     
@@ -41,7 +41,7 @@
     *
     * @returns unsigned char array.
     */
-    unsigned char * gets(int position);
+    unsigned char * gets(unsigned long position);
            
     /** Get 1 byte data from a specific location.
     *
@@ -49,7 +49,7 @@
     *
     * @returns unsigned char.
     */
-    unsigned char get(int position);
+    unsigned char get(unsigned long position);
 
     /** Get the current index.
     * @returns unsigned char array.
@@ -59,12 +59,12 @@
     /** Set the index within the max length of raw data.
     * @param position where to begin read and write
     */
-    void setPosition(int position);
+    void setPosition(unsigned long position);
 
     /** Reset the raw data.
     * @param length current max size for the raw data
     */
-    void allocate(int length);
+    void allocate(unsigned long length);
 
     /** Reset the position and does not affect the content of the data.
     * @param length current max size for the raw data
@@ -81,13 +81,13 @@
     * @param offset start point of the data
     * @param length length to write
     */
-    void sets(const unsigned char * value, int offset, int length);
+    void sets(const unsigned char * value, unsigned long offset, unsigned long length);
 
     /** Write 8-bit data into specific posiston and deos not affect the current position.
     * @param position where to write
     * @param value sigle byte
     */
-    void set(int position, unsigned char value);
+    void set(unsigned long position, unsigned char value);
 
     /** Write array of data into specific posiston and deos not affect the current position.
     * @param position where to write
@@ -95,7 +95,7 @@
     * @param offset start point of the data
     * @param length length to write
     */
-    void sets(int position, const unsigned char * value, int offset, int length);
-};
+    void sets(unsigned long position, const unsigned char * value, unsigned long offset, unsigned long length);
+}; 
 
 #endif