Blame libdjvu/DjVuNavDir.h

Packit df99a1
//C-  -*- C++ -*-
Packit df99a1
//C- -------------------------------------------------------------------
Packit df99a1
//C- DjVuLibre-3.5
Packit df99a1
//C- Copyright (c) 2002  Leon Bottou and Yann Le Cun.
Packit df99a1
//C- Copyright (c) 2001  AT&T
Packit df99a1
//C-
Packit df99a1
//C- This software is subject to, and may be distributed under, the
Packit df99a1
//C- GNU General Public License, either Version 2 of the license,
Packit df99a1
//C- or (at your option) any later version. The license should have
Packit df99a1
//C- accompanied the software or you may obtain a copy of the license
Packit df99a1
//C- from the Free Software Foundation at http://www.fsf.org .
Packit df99a1
//C-
Packit df99a1
//C- This program is distributed in the hope that it will be useful,
Packit df99a1
//C- but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit df99a1
//C- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit df99a1
//C- GNU General Public License for more details.
Packit df99a1
//C- 
Packit df99a1
//C- DjVuLibre-3.5 is derived from the DjVu(r) Reference Library from
Packit df99a1
//C- Lizardtech Software.  Lizardtech Software has authorized us to
Packit df99a1
//C- replace the original DjVu(r) Reference Library notice by the following
Packit df99a1
//C- text (see doc/lizard2002.djvu and doc/lizardtech2007.djvu):
Packit df99a1
//C-
Packit df99a1
//C-  ------------------------------------------------------------------
Packit df99a1
//C- | DjVu (r) Reference Library (v. 3.5)
Packit df99a1
//C- | Copyright (c) 1999-2001 LizardTech, Inc. All Rights Reserved.
Packit df99a1
//C- | The DjVu Reference Library is protected by U.S. Pat. No.
Packit df99a1
//C- | 6,058,214 and patents pending.
Packit df99a1
//C- |
Packit df99a1
//C- | This software is subject to, and may be distributed under, the
Packit df99a1
//C- | GNU General Public License, either Version 2 of the license,
Packit df99a1
//C- | or (at your option) any later version. The license should have
Packit df99a1
//C- | accompanied the software or you may obtain a copy of the license
Packit df99a1
//C- | from the Free Software Foundation at http://www.fsf.org .
Packit df99a1
//C- |
Packit df99a1
//C- | The computer code originally released by LizardTech under this
Packit df99a1
//C- | license and unmodified by other parties is deemed "the LIZARDTECH
Packit df99a1
//C- | ORIGINAL CODE."  Subject to any third party intellectual property
Packit df99a1
//C- | claims, LizardTech grants recipient a worldwide, royalty-free, 
Packit df99a1
//C- | non-exclusive license to make, use, sell, or otherwise dispose of 
Packit df99a1
//C- | the LIZARDTECH ORIGINAL CODE or of programs derived from the 
Packit df99a1
//C- | LIZARDTECH ORIGINAL CODE in compliance with the terms of the GNU 
Packit df99a1
//C- | General Public License.   This grant only confers the right to 
Packit df99a1
//C- | infringe patent claims underlying the LIZARDTECH ORIGINAL CODE to 
Packit df99a1
//C- | the extent such infringement is reasonably necessary to enable 
Packit df99a1
//C- | recipient to make, have made, practice, sell, or otherwise dispose 
Packit df99a1
//C- | of the LIZARDTECH ORIGINAL CODE (or portions thereof) and not to 
Packit df99a1
//C- | any greater extent that may be necessary to utilize further 
Packit df99a1
//C- | modifications or combinations.
Packit df99a1
//C- |
Packit df99a1
//C- | The LIZARDTECH ORIGINAL CODE is provided "AS IS" WITHOUT WARRANTY
Packit df99a1
//C- | OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
Packit df99a1
//C- | TO ANY WARRANTY OF NON-INFRINGEMENT, OR ANY IMPLIED WARRANTY OF
Packit df99a1
//C- | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
Packit df99a1
//C- +------------------------------------------------------------------
Packit df99a1
Packit df99a1
#ifndef _DJVUNAVDIR_H
Packit df99a1
#define _DJVUNAVDIR_H
Packit df99a1
#ifdef HAVE_CONFIG_H
Packit df99a1
#include "config.h"
Packit df99a1
#endif
Packit df99a1
#if NEED_GNUG_PRAGMAS
Packit df99a1
# pragma interface
Packit df99a1
#endif
Packit df99a1
Packit df99a1
Packit df99a1
#include "GString.h"
Packit df99a1
#include "GThreads.h"
Packit df99a1
#include "GURL.h"
Packit df99a1
Packit df99a1
#ifdef HAVE_NAMESPACES
Packit df99a1
namespace DJVU {
Packit df99a1
# ifdef NOT_DEFINED // Just to fool emacs c++ mode
Packit df99a1
}
Packit df99a1
#endif
Packit df99a1
#endif
Packit df99a1
Packit df99a1
class ByteStream;
Packit df99a1
Packit df99a1
/** @name DjVuNavDir.h
Packit df99a1
    Files #"DjVuNavDir.h"# and #"DjVuNavDir.cpp"# contain implementation of the
Packit df99a1
    multipage DjVu navigation directory. This directory lists all the pages,
Packit df99a1
    that a given document is composed of. The navigation (switching from page
Packit df99a1
    to page in the plugin) is not possible before this directory is decoded.
Packit df99a1
Packit df99a1
    Refer to the \Ref{DjVuNavDir} class description for greater details.
Packit df99a1
Packit df99a1
    @memo DjVu Navigation Directory
Packit df99a1
    @author Andrei Erofeev <eaf@geocities.com>
Packit df99a1
*/
Packit df99a1
Packit df99a1
//@{
Packit df99a1
Packit df99a1
//*****************************************************************************
Packit df99a1
//********************* Note: this class is thread-safe ***********************
Packit df99a1
//*****************************************************************************
Packit df99a1
Packit df99a1
/** DjVu Navigation Directory.
Packit df99a1
Packit df99a1
    This class implements the {\em navigation directory} of a multipage
Packit df99a1
    DjVu document - basically a list of pages that this document is composed
Packit df99a1
    of. We would like to emphasize, that this is the list of namely
Packit df99a1
    {\bf pages}, not {\bf files}. Any page may include any
Packit df99a1
    number of additional files. When you've got an all-in-one-file multipage
Packit df99a1
    DjVu document (DjVm archive) you may get the files list from \Ref{DjVmDir0}
Packit df99a1
    class.
Packit df99a1
Packit df99a1
    The \Ref{DjVuNavDir} class can decode and encode the navigation directory
Packit df99a1
    from {\bf NDIR} IFF chunk. It's normally created by the library during
Packit df99a1
    decoding procedure and can be accessed like any other component of
Packit df99a1
    the \Ref{DjVuImage} being decoded.
Packit df99a1
    
Packit df99a1
    In a typical multipage DjVu document the navigation directory is stored
Packit df99a1
    in a separate IFF file containing only one chunk: {\bf NDIR} chunk.
Packit df99a1
    This file should be included (by means of the {\bf INCL} chunk) into
Packit df99a1
    every page of the document to enable the navigation. */
Packit df99a1
class DjVuNavDir : public GPEnabled
Packit df99a1
{
Packit df99a1
private:
Packit df99a1
   GCriticalSection		lock;
Packit df99a1
   GURL				baseURL;
Packit df99a1
   GArray<GUTF8String>		page2name;
Packit df99a1
   GMap<GUTF8String, int>		name2page;
Packit df99a1
   GMap<GURL, int>		url2page;
Packit df99a1
protected:
Packit df99a1
   DjVuNavDir(const GURL &dir_url);
Packit df99a1
   DjVuNavDir(ByteStream & str, const GURL &dir_url);
Packit df99a1
Packit df99a1
public:
Packit df99a1
   int		get_memory_usage(void) const { return 1024; };
Packit df99a1
Packit df99a1
      /** Creates a #DjVuNavDir# object. #dir_url# is the URL of the file
Packit df99a1
	  containing the directory source data. It will be used later
Packit df99a1
	  in translation by functions like \Ref{url_to_page}() and
Packit df99a1
	  \Ref{page_to_url}() */
Packit df99a1
   static GP<DjVuNavDir> create(const GURL &dir_url)
Packit df99a1
   {return new DjVuNavDir(dir_url);}
Packit df99a1
Packit df99a1
      /** Creates #DjVuNavDir# object by decoding its contents from
Packit df99a1
	  the stream. #dir_url# is the URL of the file containing the
Packit df99a1
	  directory source data. */
Packit df99a1
   static GP<DjVuNavDir> create(ByteStream & str, const GURL &dir_url)
Packit df99a1
   { return new DjVuNavDir(str,dir_url); }
Packit df99a1
Packit df99a1
   virtual ~DjVuNavDir(void) {};
Packit df99a1
Packit df99a1
      /// Decodes the directory contents from the given \Ref{ByteStream}
Packit df99a1
   void		decode(ByteStream & str);
Packit df99a1
Packit df99a1
      /// Encodes the directory contents into the given \Ref{ByteStream}
Packit df99a1
   void		encode(ByteStream & str);
Packit df99a1
Packit df99a1
      /** Inserts a new page at position #where# pointing to a file
Packit df99a1
	  with name #name#.
Packit df99a1
Packit df99a1
	  @param where The position where the page should be inserted.
Packit df99a1
	  	 #-1# means to append.
Packit df99a1
	  @param name The name of the file corresponding to this page.
Packit df99a1
	  	 The name may not contain slashes. The file may include
Packit df99a1
		 other files. */
Packit df99a1
   void		insert_page(int where, const char * name);
Packit df99a1
Packit df99a1
      /// Deletes page with number #page_num# from the directory.
Packit df99a1
   void		delete_page(int page_num);
Packit df99a1
Packit df99a1
      /// Returns the number of pages in the directory.
Packit df99a1
   int		get_pages_num(void) const;
Packit df99a1
      /** Converts the #url# to page number. Returns #-1# if the #url#
Packit df99a1
	  does not correspond to anything in the directory. */
Packit df99a1
   int		url_to_page(const GURL & url) const;
Packit df99a1
      /** Converts file name #name# to page number. Returns #-1# if file
Packit df99a1
	  with given name cannot be found. */
Packit df99a1
   int		name_to_page(const char * name) const;
Packit df99a1
      /** Converts given #page# to URL. Throws an exception if page number
Packit df99a1
	  is invalid. */
Packit df99a1
   GURL		page_to_url(int page) const;
Packit df99a1
      /** Converts given #page# to URL. Throws an exception if page number
Packit df99a1
	  is invalid. */
Packit df99a1
   GUTF8String	page_to_name(int page) const;
Packit df99a1
};
Packit df99a1
Packit df99a1
//@}
Packit df99a1
Packit df99a1
Packit df99a1
#ifdef HAVE_NAMESPACES
Packit df99a1
}
Packit df99a1
# ifndef NOT_USING_DJVU_NAMESPACE
Packit df99a1
using namespace DJVU;
Packit df99a1
# endif
Packit df99a1
#endif
Packit df99a1
#endif