Blender V2.61 - r43446

Stream.cpp

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