kviewshell
IFFByteStream.h
Go to the documentation of this file.00001 //C- -*- C++ -*- 00002 //C- ------------------------------------------------------------------- 00003 //C- DjVuLibre-3.5 00004 //C- Copyright (c) 2002 Leon Bottou and Yann Le Cun. 00005 //C- Copyright (c) 2001 AT&T 00006 //C- 00007 //C- This software is subject to, and may be distributed under, the 00008 //C- GNU General Public License, Version 2. The license should have 00009 //C- accompanied the software or you may obtain a copy of the license 00010 //C- from the Free Software Foundation at http://www.fsf.org . 00011 //C- 00012 //C- This program is distributed in the hope that it will be useful, 00013 //C- but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 //C- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 //C- GNU General Public License for more details. 00016 //C- 00017 //C- DjVuLibre-3.5 is derived from the DjVu(r) Reference Library 00018 //C- distributed by Lizardtech Software. On July 19th 2002, Lizardtech 00019 //C- Software authorized us to replace the original DjVu(r) Reference 00020 //C- Library notice by the following text (see doc/lizard2002.djvu): 00021 //C- 00022 //C- ------------------------------------------------------------------ 00023 //C- | DjVu (r) Reference Library (v. 3.5) 00024 //C- | Copyright (c) 1999-2001 LizardTech, Inc. All Rights Reserved. 00025 //C- | The DjVu Reference Library is protected by U.S. Pat. No. 00026 //C- | 6,058,214 and patents pending. 00027 //C- | 00028 //C- | This software is subject to, and may be distributed under, the 00029 //C- | GNU General Public License, Version 2. The license should have 00030 //C- | accompanied the software or you may obtain a copy of the license 00031 //C- | from the Free Software Foundation at http://www.fsf.org . 00032 //C- | 00033 //C- | The computer code originally released by LizardTech under this 00034 //C- | license and unmodified by other parties is deemed "the LIZARDTECH 00035 //C- | ORIGINAL CODE." Subject to any third party intellectual property 00036 //C- | claims, LizardTech grants recipient a worldwide, royalty-free, 00037 //C- | non-exclusive license to make, use, sell, or otherwise dispose of 00038 //C- | the LIZARDTECH ORIGINAL CODE or of programs derived from the 00039 //C- | LIZARDTECH ORIGINAL CODE in compliance with the terms of the GNU 00040 //C- | General Public License. This grant only confers the right to 00041 //C- | infringe patent claims underlying the LIZARDTECH ORIGINAL CODE to 00042 //C- | the extent such infringement is reasonably necessary to enable 00043 //C- | recipient to make, have made, practice, sell, or otherwise dispose 00044 //C- | of the LIZARDTECH ORIGINAL CODE (or portions thereof) and not to 00045 //C- | any greater extent that may be necessary to utilize further 00046 //C- | modifications or combinations. 00047 //C- | 00048 //C- | The LIZARDTECH ORIGINAL CODE is provided "AS IS" WITHOUT WARRANTY 00049 //C- | OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 00050 //C- | TO ANY WARRANTY OF NON-INFRINGEMENT, OR ANY IMPLIED WARRANTY OF 00051 //C- | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. 00052 //C- +------------------------------------------------------------------ 00053 // 00054 // $Id: IFFByteStream.h,v 1.10 2003/11/07 22:08:21 leonb Exp $ 00055 // $Name: release_3_5_15 $ 00056 00057 #ifndef _IFFBYTESTREAM_H_ 00058 #define _IFFBYTESTREAM_H_ 00059 #ifdef HAVE_CONFIG_H 00060 #include "config.h" 00061 #endif 00062 #if NEED_GNUG_PRAGMAS 00063 # pragma interface 00064 #endif 00065 00066 00126 00127 00128 #include "DjVuGlobal.h" 00129 #include <stdlib.h> 00130 #include <stdio.h> 00131 #include <string.h> 00132 #include "GException.h" 00133 #include "GString.h" 00134 #include "ByteStream.h" 00135 00136 00137 #ifdef HAVE_NAMESPACES 00138 namespace DJVU { 00139 # ifdef NOT_DEFINED // Just to fool emacs c++ mode 00140 } 00141 #endif 00142 #endif 00143 00181 class IFFByteStream : protected ByteStream::Wrapper 00182 { 00183 protected: 00184 IFFByteStream(const GP<ByteStream> &bs, const int pos); 00185 public: 00189 static GP<IFFByteStream> create(const GP<ByteStream> &bs); 00190 // --- BYTESTREAM INTERFACE 00191 ~IFFByteStream(); 00192 virtual size_t read(void *buffer, size_t size); 00193 virtual size_t write(const void *buffer, size_t size); 00194 virtual long tell(void) const; 00195 // -- NAVIGATING CHUNKS 00207 int get_chunk(GUTF8String &chkid, int *rawoffsetptr=0, int *rawsizeptr=0); 00216 void put_chunk(const char *chkid, int insertmagic=0); 00221 void close_chunk(); 00224 void seek_close_chunk(); 00226 int ready(); 00228 int composite(); 00236 void short_id(GUTF8String &chkid); 00247 void full_id(GUTF8String &chkid); 00254 static int check_id(const char *id); 00255 GP<ByteStream> get_bytestream(void) {return this;} 00264 size_t copy(ByteStream &bsfrom, size_t size=0) 00265 { return get_bytestream()->copy(bsfrom,size); } 00270 virtual void flush(void) 00271 { ByteStream::Wrapper::flush(); } 00276 bool compare(IFFByteStream &iff); 00279 bool has_magic; 00280 private: 00281 // private datatype 00282 struct IFFContext 00283 { 00284 IFFContext *next; 00285 long offStart; 00286 long offEnd; 00287 char idOne[4]; 00288 char idTwo[4]; 00289 char bComposite; 00290 }; 00291 // Implementation 00292 IFFContext *ctx; 00293 long offset; 00294 long seekto; 00295 int dir; 00296 // Cancel C++ default stuff 00297 IFFByteStream(const IFFByteStream &); 00298 IFFByteStream & operator=(const IFFByteStream &); 00299 static GP<IFFByteStream> create(ByteStream *bs); 00300 }; 00301 00303 00304 00305 00306 #ifdef HAVE_NAMESPACES 00307 } 00308 # ifndef NOT_USING_DJVU_NAMESPACE 00309 using namespace DJVU; 00310 # endif 00311 #endif 00312 #endif