History

Some type modifications in DataViewPrototype

Atlante45 committed 12 years ago

Commit 4b2e4b71 parent 7fe88a42 files · +42 −34Browse files

Showing the changes to libraries/script-engine/src/DataViewPrototype.cpp (1 of 2 files). Show all

Unified · Split

libraries/script-engine/src/DataViewPrototype.cpp+33−25
@@ -38,23 +38,31 @@ bool DataViewPrototype::realOffset(quint32& offset, size_t size) const { · 37 unmodified lines
3838
3939 ///////////////// GETTERS ////////////////////////////
4040
41−qint8 DataViewPrototype::getInt8(quint32 byteOffset) {
41+qint32 DataViewPrototype::getInt8(quint32 byteOffset) {
4242 if (realOffset(byteOffset, sizeof(qint8))) {
43− qDebug() << "Value: " << (qint8)thisArrayBuffer()->at(byteOffset);
44−
45− return (qint8)thisArrayBuffer()->at(byteOffset);
43+ QDataStream stream(*thisArrayBuffer());
44+ stream.skipRawData(byteOffset);
45+
46+ qint8 result;
47+ stream >> result;
48+ return result;
4649 }
47− qDebug() << "42 powaaaa!!!";
4850 return 42;
4951 }
5052
51−quint8 DataViewPrototype::getUint8(quint32 byteOffset) {
52− if (realOffset(byteOffset, sizeof(quint8))) { return thisArrayBuffer()->at(byteOffset);
53+quint32 DataViewPrototype::getUint8(quint32 byteOffset) {
54+ if (realOffset(byteOffset, sizeof(quint8))) {
55+ QDataStream stream(*thisArrayBuffer());
56+ stream.skipRawData(byteOffset);
57+
58+ quint8 result;
59+ stream >> result;
60+ return result;
5361 }
5462 return 42;
5563 }
5664
57−qint16 DataViewPrototype::getInt16(quint32 byteOffset, bool littleEndian) {
65+qint32 DataViewPrototype::getInt16(quint32 byteOffset, bool littleEndian) {
5866 if (realOffset(byteOffset, sizeof(qint16))) {
5967 QDataStream stream(*thisArrayBuffer());
6068 stream.setByteOrder((littleEndian) ? QDataStream::LittleEndian : QDataStream::BigEndian);
@@ -67,13 +75,13 @@ qint16 DataViewPrototype::getInt16(quint32 byteOffset, bool littleEndian) { · 6 unmodified lines
6775 return 42;
6876 }
6977
70−quint16 DataViewPrototype::getUint16(quint32 byteOffset, bool littleEndian) {
78+quint32 DataViewPrototype::getUint16(quint32 byteOffset, bool littleEndian) {
7179 if (realOffset(byteOffset, sizeof(quint16))) {
7280 QDataStream stream(*thisArrayBuffer());
7381 stream.setByteOrder((littleEndian) ? QDataStream::LittleEndian : QDataStream::BigEndian);
7482 stream.skipRawData(byteOffset);
7583
76− qint16 result;
84+ quint16 result;
7785 stream >> result;
7886 return result;
7987 }
@@ -86,7 +94,7 @@ qint32 DataViewPrototype::getInt32(quint32 byteOffset, bool littleEndian) { · 6 unmodified lines
8694 stream.setByteOrder((littleEndian) ? QDataStream::LittleEndian : QDataStream::BigEndian);
8795 stream.skipRawData(byteOffset);
8896
89− qint16 result;
97+ qint32 result;
9098 stream >> result;
9199 return result;
92100 }
@@ -99,7 +107,7 @@ quint32 DataViewPrototype::getUint32(quint32 byteOffset, bool littleEndian) { · 6 unmodified lines
99107 stream.setByteOrder((littleEndian) ? QDataStream::LittleEndian : QDataStream::BigEndian);
100108 stream.skipRawData(byteOffset);
101109
102− qint16 result;
110+ quint32 result;
103111 stream >> result;
104112 return result;
105113 }
@@ -112,7 +120,7 @@ float DataViewPrototype::getFloat32(quint32 byteOffset, bool littleEndian) { · 6 unmodified lines
112120 stream.setByteOrder((littleEndian) ? QDataStream::LittleEndian : QDataStream::BigEndian);
113121 stream.skipRawData(byteOffset);
114122
115− qint16 result;
123+ float result;
116124 stream >> result;
117125 return result;
118126 }
@@ -125,7 +133,7 @@ double DataViewPrototype::getFloat64(quint32 byteOffset, bool littleEndian) { · 6 unmodified lines
125133 stream.setByteOrder((littleEndian) ? QDataStream::LittleEndian : QDataStream::BigEndian);
126134 stream.skipRawData(byteOffset);
127135
128− qint16 result;
136+ double result;
129137 stream >> result;
130138 return result;
131139 }
@@ -134,48 +142,48 @@ double DataViewPrototype::getFloat64(quint32 byteOffset, bool littleEndian) { · 2 unmodified lines
134142
135143 ///////////////// SETTERS ////////////////////////////
136144
137−void DataViewPrototype::setInt8(quint32 byteOffset, qint8 value) {
145+void DataViewPrototype::setInt8(quint32 byteOffset, qint32 value) {
138146 if (realOffset(byteOffset, sizeof(qint8))) {
139147 QDataStream stream(thisArrayBuffer(), QIODevice::ReadWrite);
140148 stream.skipRawData(byteOffset);
141149
142− stream << value;
150+ stream << (qint8)value;
143151 }
144152 }
145153
146−void DataViewPrototype::setUint8(quint32 byteOffset, quint8 value) {
154+void DataViewPrototype::setUint8(quint32 byteOffset, quint32 value) {
147155 if (realOffset(byteOffset, sizeof(quint8))) {
148156 QDataStream stream(thisArrayBuffer(), QIODevice::ReadWrite);
149157 stream.skipRawData(byteOffset);
150158
151− stream << value;
159+ stream << (quint8)value;
152160 }
153161 }
154162
155−void DataViewPrototype::setInt16(quint32 byteOffset, qint16 value, bool littleEndian) {
163+void DataViewPrototype::setInt16(quint32 byteOffset, qint32 value, bool littleEndian) {
156164 if (realOffset(byteOffset, sizeof(qint16))) {
157165 QDataStream stream(thisArrayBuffer(), QIODevice::ReadWrite);
158166 stream.skipRawData(byteOffset);
159167
160− stream << value;
168+ stream << (qint16)value;
161169 }
162170 }
163171
164−void DataViewPrototype::setUint16(quint32 byteOffset, quint16 value, bool littleEndian) {
172+void DataViewPrototype::setUint16(quint32 byteOffset, quint32 value, bool littleEndian) {
165173 if (realOffset(byteOffset, sizeof(quint16))) {
166174 QDataStream stream(thisArrayBuffer(), QIODevice::ReadWrite);
167175 stream.skipRawData(byteOffset);
168176
169− stream << value;
177+ stream << (quint16)value;
170178 }
171179 }
172180
173−void DataViewPrototype::setInt32(quint32 byteOffset, quint32 value, bool littleEndian) {
181+void DataViewPrototype::setInt32(quint32 byteOffset, qint32 value, bool littleEndian) {
174182 if (realOffset(byteOffset, sizeof(qint32))) {
175183 QDataStream stream(thisArrayBuffer(), QIODevice::ReadWrite);
176184 stream.skipRawData(byteOffset);
177185
178− stream << value;
186+ stream << (qint32)value;
179187 }
180188 }
181189
@@ -184,7 +192,7 @@ void DataViewPrototype::setUint32(quint32 byteOffset, quint32 value, bool little · 2 unmodified lines
184192 QDataStream stream(thisArrayBuffer(), QIODevice::ReadWrite);
185193 stream.skipRawData(byteOffset);
186194
187− stream << value;
195+ stream << (quint32)value;
188196 }
189197 }
190198