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

kviewshell

DjVuNavDir.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: DjVuNavDir.cpp,v 1.8 2003/11/07 22:08:21 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 "DjVuNavDir.h"
00065 #include "debug.h"
00066 #include "GException.h"
00067 #include "GOS.h"
00068 #include "ByteStream.h"
00069 #include "GURL.h"
00070 #include <ctype.h>
00071 
00072 
00073 
00074 #ifdef HAVE_NAMESPACES
00075 namespace DJVU {
00076 # ifdef NOT_DEFINED // Just to fool emacs c++ mode
00077 }
00078 #endif
00079 #endif
00080 
00081 
00082 
00083 DjVuNavDir::DjVuNavDir(const GURL &dirURL)
00084 {
00085    if (!dirURL) G_THROW( ERR_MSG("DjVuNavDir.zero_dir") );
00086    baseURL=dirURL.base();
00087 }
00088 
00089 DjVuNavDir::DjVuNavDir(ByteStream & str, const GURL &dirURL)
00090 {
00091    if (!dirURL) G_THROW( ERR_MSG("DjVuNavDir.zero_dir") );
00092    
00093    baseURL=GURL(dirURL).base();
00094    
00095    decode(str);
00096 }
00097 
00098 void
00099 DjVuNavDir::decode(ByteStream & str)
00100 {
00101    GCriticalSectionLock lk(&lock);
00102    
00103    GList<GUTF8String> tmp_page2name;
00104    int eof=0;
00105    while(!eof)
00106    {
00107       char buffer[1024];
00108       char * ptr;
00109       for(ptr=buffer;ptr-buffer<1024;ptr++)
00110      if ((eof=!str.read(ptr, 1)) || *ptr=='\n') break;
00111       if (ptr-buffer==1024) G_THROW( ERR_MSG("DjVuNavDir.long_line") );
00112       *ptr=0;
00113       if (!strlen(buffer)) continue;
00114 
00115       if (!tmp_page2name.contains(buffer))
00116      tmp_page2name.append(buffer);
00117    };
00118 
00119    // Now copying lists to arrays for faster access later
00120    int pages=tmp_page2name.size();
00121    page2name.resize(pages-1);
00122 
00123    int cnt;
00124    GPosition pos;
00125    for(pos=tmp_page2name, cnt=0;pos;++pos, cnt++)
00126       page2name[cnt]=tmp_page2name[pos];
00127    
00128    // Now creating reverse mapping (strings => numbers)
00129    for(cnt=0;cnt<pages;cnt++)
00130    {
00131       name2page[page2name[cnt]]=cnt;
00132       url2page[GURL::UTF8(page2name[cnt],baseURL)]=cnt;
00133    }
00134 }
00135 
00136 #ifndef NEED_DECODER_ONLY
00137 void
00138 DjVuNavDir::encode(ByteStream & str)
00139 {
00140    GCriticalSectionLock lk(&lock);
00141 
00142    for(int i=0;i<page2name.size();i++)
00143    {
00144       GUTF8String & name=page2name[i];
00145       str.writall((const char*)name, name.length());
00146       str.writall("\n", 1);
00147    };
00148 }
00149 #endif //NEED_DECODER_ONLY
00150 
00151 int
00152 DjVuNavDir::get_pages_num(void) const
00153 {
00154    GCriticalSectionLock lk((GCriticalSection *)&lock);
00155    
00156    return page2name.size();
00157 }
00158 
00159 int
00160 DjVuNavDir::name_to_page(const char * name) const
00161 {
00162    GCriticalSectionLock lk((GCriticalSection *)&lock);
00163 
00164    if (!name2page.contains(name)) return -1;
00165    return name2page[name];
00166 }
00167 
00168 int
00169 DjVuNavDir::url_to_page(const GURL & url) const
00170 {
00171    GCriticalSectionLock lk((GCriticalSection *)&lock);
00172 
00173    if (!url2page.contains(url)) return -1;
00174    return url2page[url];
00175 }
00176 
00177 GUTF8String
00178 DjVuNavDir::page_to_name(int page) const
00179 {
00180    GCriticalSectionLock lk((GCriticalSection *)&lock);
00181    
00182    if (page<0) 
00183       G_THROW( ERR_MSG("DjVuNavDir.neg_page") );
00184    if (page>=page2name.size())
00185       G_THROW( ERR_MSG("DjVuNavDir.large_page") );
00186    return page2name[page];
00187 }
00188 
00189 GURL
00190 DjVuNavDir::page_to_url(int page) const
00191 {
00192    GCriticalSectionLock lk((GCriticalSection *)&lock);
00193    
00194    return GURL::UTF8(page_to_name(page),baseURL);
00195 }
00196 
00197 void
00198 DjVuNavDir::insert_page(int where, const char * name)
00199 {
00200    GCriticalSectionLock lk((GCriticalSection *)&lock);
00201 
00202    int pages=page2name.size();
00203    if (where<0) where=pages;
00204    
00205    page2name.resize(pages);
00206    for(int i=pages;i>where;i--)
00207       page2name[i]=page2name[i-1];
00208    page2name[where]=name;
00209    name2page[name]=where;
00210    url2page[GURL::UTF8(name,baseURL)]=where;
00211 }
00212 
00213 #ifndef NEED_DECODER_ONLY
00214 void
00215 DjVuNavDir::delete_page(int page_num)
00216 {
00217    GCriticalSectionLock lk((GCriticalSection *)&lock);
00218 
00219    int pages=page2name.size();
00220    
00221    if (page_num<0 || page_num>=pages)
00222       G_THROW( ERR_MSG("DjVuNavDir.bad_page") );
00223 
00224    for(int i=page_num;i<pages-1;i++)
00225       page2name[i]=page2name[i+1];
00226    page2name.resize(--pages-1);
00227 }
00228 #endif
00229 
00230 
00231 
00232 #ifdef HAVE_NAMESPACES
00233 }
00234 # ifndef NOT_USING_DJVU_NAMESPACE
00235 using namespace DJVU;
00236 # endif
00237 #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