• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kviewshell

DjVmDir0.cpp

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: DjVmDir0.cpp,v 1.8 2003/11/07 22:08:20 leonb Exp $
00055 // $Name: release_3_5_15 $
00056 
00057 #ifdef HAVE_CONFIG_H
00058 # include "config.h"
00059 #endif
00060 #if NEED_GNUG_PRAGMAS
00061 # pragma implementation
00062 #endif
00063 
00064 #include "DjVmDir0.h"
00065 #include "ByteStream.h"
00066 #include "debug.h"
00067 
00068 
00069 #ifdef HAVE_NAMESPACES
00070 namespace DJVU {
00071 # ifdef NOT_DEFINED // Just to fool emacs c++ mode
00072 }
00073 #endif
00074 #endif
00075 
00076 int
00077 DjVmDir0::get_size(void) const
00078       // WARNING! make sure, that get_size(), encode() and decode() are in sync
00079 {
00080    int size=0;
00081 
00082    size+=2; // number of files
00083    for(int i=0;i<num2file.size();i++)
00084    {
00085       FileRec & file=*num2file[i];
00086       size+=file.name.length()+1;   // file name
00087       size+=1;              // is IFF file
00088       size+=4;              // file offset
00089       size+=4;              // file size
00090    };
00091 
00092    return size;
00093 }
00094 
00095 #ifndef NEED_DECODER_ONLY
00096 void
00097 DjVmDir0::encode(ByteStream & bs)
00098       // WARNING! make sure, that get_size(), encode() and decode() are in sync
00099 {
00100    bs.write16(num2file.size());
00101    for(int i=0;i<num2file.size();i++)
00102    {
00103       FileRec & file=*num2file[i];
00104       bs.writestring(file.name);
00105       bs.write8(0);
00106       bs.write8(file.iff_file);
00107       bs.write32(file.offset);
00108       bs.write32(file.size);
00109    }
00110 }
00111 #endif
00112 
00113 void
00114 DjVmDir0::decode(ByteStream & bs)
00115       // WARNING! make sure, that get_size(), encode() and decode() are in sync
00116 {
00117    name2file.empty();
00118    num2file.empty();
00119 
00120    for(int i=bs.read16();i>0;i--)
00121    {
00122       GUTF8String name;
00123       char ch;
00124       while(bs.read(&ch, 1) && ch) name+=ch;
00125       bool iff_file=bs.read8()?true:false;
00126       int offset=bs.read32();
00127       int size=bs.read32();
00128       add_file(name, iff_file, offset, size);
00129    };
00130 }
00131 
00132 GP<DjVmDir0::FileRec>
00133 DjVmDir0::get_file(const GUTF8String &name)
00134 {
00135    if (name2file.contains(name))
00136      return name2file[name];
00137    return 0;
00138 }
00139 
00140 GP<DjVmDir0::FileRec>
00141 DjVmDir0::get_file(int file_num)
00142 {
00143    if (file_num<num2file.size()) return num2file[file_num];
00144    return 0;
00145 }
00146 
00147 void
00148 DjVmDir0::add_file(
00149   const GUTF8String &name, bool iff_file, int offset, int size)
00150 {
00151    DEBUG_MSG("DjVmDir0::add_file(): name='" << name << "', iff=" << iff_file <<
00152          ", offset=" << offset << "\n");
00153    
00154    if (name.search('/') >= 0)
00155      G_THROW( ERR_MSG("DjVmDir0.no_slash") );
00156    
00157    GP<FileRec> file=new FileRec(name, iff_file, offset, size);
00158    name2file[name]=file;
00159    num2file.resize(num2file.size());
00160    num2file[num2file.size()-1]=file;
00161 }
00162 
00163 
00164 #ifdef HAVE_NAMESPACES
00165 }
00166 # ifndef NOT_USING_DJVU_NAMESPACE
00167 using namespace DJVU;
00168 # endif
00169 #endif

kviewshell

Skip menu "kviewshell"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • kviewshell
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal