00001 #ifndef DATAPOINTER_H 00002 #define DATAPOINTER_H 00003 00004 #include <QtCore/QByteArray> 00005 #include <QtCore/QDebug> 00006 #include <QtCore/QString> 00007 class DataPointer { 00008 QString hexByte(unsigned char start) const{ 00009 return QString("%1").arg(start, 2, 16, QChar('0')); 00010 } 00011 public: 00012 QByteArray data; 00013 int offset; 00014 00015 explicit DataPointer(const QByteArray& data_, int offset_ = 0) : 00016 data(data_), 00017 offset(offset_) 00018 { 00019 } 00020 00021 inline DataPointer operator+(int j) const 00022 { 00023 return DataPointer(data, offset + j); 00024 } 00025 00026 DataPointer operator-(int j) const 00027 { 00028 return DataPointer(data, offset - j); 00029 } 00030 00031 int operator-(const DataPointer& other) const 00032 { 00033 return offset - other.offset; 00034 } 00035 00036 DataPointer& operator+=(int j) 00037 { 00038 offset += j; 00039 return *this; 00040 } 00041 00042 inline unsigned char operator[](int j) const 00043 { 00044 return data[offset + j]; 00045 } 00046 00047 const unsigned char* toUnsignedPointer(int j = 0) const 00048 { 00049 return reinterpret_cast<const unsigned char*>(toPointer(j)); 00050 } 00051 00052 const char* toPointer(int j = 0) const 00053 { 00054 return data.data() + offset + j; 00055 } 00056 00057 int bytesLeft() const 00058 { 00059 return data.size() - offset; 00060 } 00061 00062 bool operator<(const DataPointer& other) { 00063 return offset < other.offset; 00064 } 00065 00066 QByteArray toQByteArray() const; 00067 }; 00068 #endif