2 * This library is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2.1 of the License, or (at your option) any later version.
7 * This library is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with this library; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 * binstr.cpp - Binary I/O on standard C strings in memory
17 * Copyright (C) 2003 Simon Peter <dn.tlp@gmx.net>
22 /***** binsbase *****/
24 binsbase::binsbase(void *str, unsigned long len)
25 : data((Byte *)str), spos((Byte *)str), length(len)
33 void binsbase::seek(long p, Offset offs)
36 case Set: spos = data + p; break;
37 case Add: spos += p; break;
38 case End: spos = data + length - 1 + p; break;
41 // Seek before start of data
48 // Seek after end of data
49 if(spos - data >= length) {
51 spos = data + length - 1;
57 return (long)(spos - data);
60 /***** binisstream *****/
62 binisstream::binisstream(void *str, unsigned long len)
67 binisstream::~binisstream()
71 binisstream::Byte binisstream::getByte()
75 if(spos - data >= length)
85 /***** binosstream *****/
87 binosstream::binosstream(void *str, unsigned long len)
92 binosstream::~binosstream()
96 void binosstream::putByte(Byte b)
101 if(spos - data >= length)
102 spos = data + length - 1;
105 /***** binsstream *****/
107 binsstream::binsstream(void *str, unsigned long len)
108 : binsbase(str, len), binisstream(str, len), binosstream(str, len)
112 binsstream::~binsstream()