2 * This file is part of ShapeFusion (Copyright 2000 Tito Dal Canton)
4 * ShapeFusion is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * ShapeFusion is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with ShapeFusion; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "LittleEndianBuffer.h"
21 LittleEndianBuffer::LittleEndianBuffer(unsigned int _size):
22 GenericEndianBuffer(_size)
27 LittleEndianBuffer::LittleEndianBuffer(unsigned char *_data, unsigned int _size):
28 GenericEndianBuffer(_data, _size)
33 LittleEndianBuffer::~LittleEndianBuffer(void)
38 short LittleEndianBuffer::ReadShort(void)
40 if ((unsigned int)(mPosition - mData + 1) < mSize) {
41 unsigned char lo = *mPosition++,
44 return (short)((hi << 8) | lo);
46 std::cerr << "LittleEndianBuffer: attempted read beyond buffer limits\n";
51 unsigned short LittleEndianBuffer::ReadUShort(void)
53 if ((unsigned int)(mPosition - mData + 1) < mSize) {
54 unsigned char lo = *mPosition++,
57 return (unsigned short)((hi << 8) | lo);
59 std::cerr << "LittleEndianBuffer: attempted read beyond buffer limits\n";
64 long LittleEndianBuffer::ReadLong(void)
66 if ((unsigned int)(mPosition - mData + 3) < mSize) {
67 unsigned char a = *mPosition++,
72 return (long)((d << 24) | (c << 16) | (b << 8) | a);
74 std::cerr << "LittleEndianBuffer: attempted read beyond buffer limits\n";
79 unsigned long LittleEndianBuffer::ReadULong(void)
81 if ((unsigned int)(mPosition - mData + 3) < mSize) {
82 unsigned char a = *mPosition++,
87 return (unsigned long)((d << 24) | (c << 16) | (b << 8) | a);
89 std::cerr << "LittleEndianBuffer: attempted read beyond buffer limits\n";
94 void LittleEndianBuffer::WriteShort(short v)
96 if ((unsigned int)(mPosition - mData + 1) < mSize) {
97 *mPosition++ = v & 0xff;
98 *mPosition++ = (v >> 8) & 0xff;
100 std::cerr << "LittleEndianBuffer: attempted write beyond buffer limits\n";
104 void LittleEndianBuffer::WriteUShort(unsigned short v)
106 if ((unsigned int)(mPosition - mData + 1) < mSize) {
107 *mPosition++ = v & 0xff;
108 *mPosition++ = (v >> 8) & 0xff;
110 std::cerr << "LittleEndianBuffer: attempted write beyond buffer limits\n";
114 void LittleEndianBuffer::WriteLong(long v)
116 if ((unsigned int)(mPosition - mData + 3) < mSize) {
117 *mPosition++ = v & 0xff;
118 *mPosition++ = (v >> 8) & 0xff;
119 *mPosition++ = (v >> 16) & 0xff;
120 *mPosition++ = (v >> 24) & 0xff;
122 std::cerr << "LittleEndianBuffer: attempted write beyond buffer limits\n";
126 void LittleEndianBuffer::WriteULong(unsigned long v)
128 if ((unsigned int)(mPosition - mData + 3) < mSize) {
129 *mPosition++ = v & 0xff;
130 *mPosition++ = (v >> 8) & 0xff;
131 *mPosition++ = (v >> 16) & 0xff;
132 *mPosition++ = (v >> 24) & 0xff;
134 std::cerr << "LittleEndianBuffer: attempted write beyond buffer limits\n";