|
Blender
V2.59
|
00001 /* 00002 * $Id: Stream.cpp 36541 2011-05-07 20:53:49Z jesterking $ 00003 * 00004 * ***** BEGIN GPL LICENSE BLOCK ***** 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software Foundation, 00018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 * 00020 * Contributors: Amorilia (amorilia@users.sourceforge.net) 00021 * 00022 * ***** END GPL LICENSE BLOCK ***** 00023 */ 00024 00030 #include <Stream.h> 00031 00032 #include <stdio.h> // printf 00033 #include <string.h> // memcpy 00034 00035 unsigned int Stream::seek(unsigned int p) 00036 { 00037 if (p > size) { 00038 printf("DDS: trying to seek beyond end of stream (corrupt file?)"); 00039 } 00040 else { 00041 pos = p; 00042 } 00043 00044 return pos; 00045 } 00046 00047 unsigned int mem_read(Stream & mem, unsigned long long & i) 00048 { 00049 if (mem.pos + 8 > mem.size) { 00050 printf("DDS: trying to read beyond end of stream (corrupt file?)"); 00051 return(0); 00052 }; 00053 memcpy(&i, mem.mem + mem.pos, 8); // @@ todo: make sure little endian 00054 mem.pos += 8; 00055 return(8); 00056 } 00057 00058 unsigned int mem_read(Stream & mem, unsigned int & i) 00059 { 00060 if (mem.pos + 4 > mem.size) { 00061 printf("DDS: trying to read beyond end of stream (corrupt file?)"); 00062 return(0); 00063 }; 00064 memcpy(&i, mem.mem + mem.pos, 4); // @@ todo: make sure little endian 00065 mem.pos += 4; 00066 return(4); 00067 } 00068 00069 unsigned int mem_read(Stream & mem, unsigned short & i) 00070 { 00071 if (mem.pos + 2 > mem.size) { 00072 printf("DDS: trying to read beyond end of stream (corrupt file?)"); 00073 return(0); 00074 }; 00075 memcpy(&i, mem.mem + mem.pos, 2); // @@ todo: make sure little endian 00076 mem.pos += 2; 00077 return(2); 00078 } 00079 00080 unsigned int mem_read(Stream & mem, unsigned char & i) 00081 { 00082 if (mem.pos + 1 > mem.size) { 00083 printf("DDS: trying to read beyond end of stream (corrupt file?)"); 00084 return(0); 00085 }; 00086 i = (mem.mem + mem.pos)[0]; 00087 mem.pos += 1; 00088 return(1); 00089 } 00090 00091 unsigned int mem_read(Stream & mem, unsigned char *i, unsigned int cnt) 00092 { 00093 if (mem.pos + cnt > mem.size) { 00094 printf("DDS: trying to read beyond end of stream (corrupt file?)"); 00095 return(0); 00096 }; 00097 memcpy(i, mem.mem + mem.pos, cnt); 00098 mem.pos += cnt; 00099 return(cnt); 00100 } 00101