source: trunk/libdjvu/DjVmDir0.h @ 280

Last change on this file since 280 was 280, checked in by rbri, 11 years ago

DJVU plugin: djvulibre updated to version 3.5.22

File size: 7.2 KB
Line 
1//C-  -*- C++ -*-
2//C- -------------------------------------------------------------------
3//C- DjVuLibre-3.5
4//C- Copyright (c) 2002  Leon Bottou and Yann Le Cun.
5//C- Copyright (c) 2001  AT&T
6//C-
7//C- This software is subject to, and may be distributed under, the
8//C- GNU General Public License, either Version 2 of the license,
9//C- or (at your option) any later version. The license should have
10//C- accompanied the software or you may obtain a copy of the license
11//C- from the Free Software Foundation at http://www.fsf.org .
12//C-
13//C- This program is distributed in the hope that it will be useful,
14//C- but WITHOUT ANY WARRANTY; without even the implied warranty of
15//C- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16//C- GNU General Public License for more details.
17//C-
18//C- DjVuLibre-3.5 is derived from the DjVu(r) Reference Library from
19//C- Lizardtech Software.  Lizardtech Software has authorized us to
20//C- replace the original DjVu(r) Reference Library notice by the following
21//C- text (see doc/lizard2002.djvu and doc/lizardtech2007.djvu):
22//C-
23//C-  ------------------------------------------------------------------
24//C- | DjVu (r) Reference Library (v. 3.5)
25//C- | Copyright (c) 1999-2001 LizardTech, Inc. All Rights Reserved.
26//C- | The DjVu Reference Library is protected by U.S. Pat. No.
27//C- | 6,058,214 and patents pending.
28//C- |
29//C- | This software is subject to, and may be distributed under, the
30//C- | GNU General Public License, either Version 2 of the license,
31//C- | or (at your option) any later version. The license should have
32//C- | accompanied the software or you may obtain a copy of the license
33//C- | from the Free Software Foundation at http://www.fsf.org .
34//C- |
35//C- | The computer code originally released by LizardTech under this
36//C- | license and unmodified by other parties is deemed "the LIZARDTECH
37//C- | ORIGINAL CODE."  Subject to any third party intellectual property
38//C- | claims, LizardTech grants recipient a worldwide, royalty-free,
39//C- | non-exclusive license to make, use, sell, or otherwise dispose of
40//C- | the LIZARDTECH ORIGINAL CODE or of programs derived from the
41//C- | LIZARDTECH ORIGINAL CODE in compliance with the terms of the GNU
42//C- | General Public License.   This grant only confers the right to
43//C- | infringe patent claims underlying the LIZARDTECH ORIGINAL CODE to
44//C- | the extent such infringement is reasonably necessary to enable
45//C- | recipient to make, have made, practice, sell, or otherwise dispose
46//C- | of the LIZARDTECH ORIGINAL CODE (or portions thereof) and not to
47//C- | any greater extent that may be necessary to utilize further
48//C- | modifications or combinations.
49//C- |
50//C- | The LIZARDTECH ORIGINAL CODE is provided "AS IS" WITHOUT WARRANTY
51//C- | OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
52//C- | TO ANY WARRANTY OF NON-INFRINGEMENT, OR ANY IMPLIED WARRANTY OF
53//C- | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
54//C- +------------------------------------------------------------------
55//
56// $Id: DjVmDir0.h,v 1.9 2007/03/25 20:48:29 leonb Exp $
57// $Name: release_3_5_22 $
58
59#ifndef _DJVMDIR0_H
60#define _DJVMDIR0_H
61#ifdef HAVE_CONFIG_H
62#include "config.h"
63#endif
64#if NEED_GNUG_PRAGMAS
65# pragma interface
66#endif
67
68
69#include "GString.h"
70
71#ifdef HAVE_NAMESPACES
72namespace DJVU {
73# ifdef NOT_DEFINED // Just to fool emacs c++ mode
74}
75#endif
76#endif
77
78class ByteStream;
79
80/** @name DjVmDir0.h
81
82    Files #"DjVmDir0.h"# and #"DjVmDir0.cpp"# contain implementation of
83    \Ref{DjVmDir0} class responsible for reading and writing the directory
84    of a multipage all-in-one-file DjVu document (usually referred to as
85    {\bf DjVm} document.
86
87    This is {\bf not} a navigation directory, which lists all the pages
88    in a multipage document. The navigation directory is supported by class
89    \Ref{DjVuNavDir}. This is the directory of a DjVm archive.
90   
91
92    @memo Directory of DjVu all-in-one-file DjVu documents.
93    @author Andrei Erofeev <eaf@geocities.com>
94    @version #$Id: DjVmDir0.h,v 1.9 2007/03/25 20:48:29 leonb Exp $# */
95
96//@{
97
98/** Directory of all-in-one-file DjVu documents (also known as DjVm documents).
99    This class can read and write the directory (table of contents, in other
100    words) of a DjVm document. This table of contents lists all {\bf files}
101    included into the document, not {\bf pages} like \Ref{DjVuNavDir} does.
102    It is normally stored in the document inside {\bf DIR0} chunk where
103    {\bf "0"} refers to the version number.
104
105    An object of this class can be created either as a result of the decoding
106    of an existing DjVm file, or manually by calling the default constructor
107    and adding later directory entries by means of \Ref{add_file}() function.
108
109    You normally will not want to create or decode this directory manually.
110    \Ref{DjVmFile} class will do it for you. */
111class DjVmDir0 : public GPEnabled
112{
113public:
114      /** Describes a file record inside a DjVm document (archive) */
115   class FileRec;
116private:
117   GMap<GUTF8String, GP<FileRec> >      name2file;
118   GPArray<FileRec>             num2file;
119protected:
120      /// Default constructor
121   DjVmDir0(void) {};
122public:
123      /// Copy constructor
124   DjVmDir0(const DjVmDir0 & d);
125
126   static GP<DjVmDir0> create(void) {return new DjVmDir0;}
127
128   virtual ~DjVmDir0(void) {};
129
130      /// Returns the number of files in the DjVm archive
131   int          get_files_num(void) const;
132   
133      /// Returns the file record with name #name#
134   GP<FileRec>  get_file(const GUTF8String &name);
135
136      /// Returns the file record number #file_num#
137   GP<FileRec>  get_file(int file_num);
138
139      /** Creates a new file record with name #name# at offset
140          #offset# and size #size#, which is in IFF format if
141          #iff_file# is #TRUE#. */
142   void         add_file(const GUTF8String &name, bool iff_file,
143                         int offset=-1, int size=-1);
144
145      /// Returns the size of the directory if it were encoded in #DIR0# chunk
146   int          get_size(void) const;
147
148      /** Encodes the directory in #DIR0# chunk into the specified
149          \Ref{ByteStream} */
150   void         encode(ByteStream & bs);
151
152      /** Decodes the directory from #DIR0# chunk from the specified
153          \Ref{ByteStream} */
154   void         decode(ByteStream & bs);
155
156};
157
158      /** Describes a file record inside a DjVm document (archive) */
159class DjVmDir0::FileRec : public GPEnabled
160{
161public:
162  /// Name of the file.
163  GUTF8String           name;
164  /// 1 if the file is in IFF format.
165  bool          iff_file;
166  /// Offset of the file in the archive.
167  int           offset;
168  /// Size of the file
169  int           size;
170
171  friend int    operator==(const FileRec & f1, const FileRec & f2);
172
173  /// Constructs the #FileRec# object
174  FileRec(const GUTF8String &name, bool iff_file,
175              int offset=-1, int size=-1);
176  /// Default constructor
177  FileRec(void);
178  virtual ~FileRec(void);
179};
180
181inline
182DjVmDir0::FileRec::FileRec(
183  const GUTF8String &name_in, bool iff_file_in, int offset_in, int size_in)
184: name(name_in), iff_file(iff_file_in), offset(offset_in), size(size_in)
185{
186}
187
188inline
189DjVmDir0::FileRec::FileRec(void) : iff_file(0), offset(-1), size(-1)
190{
191}
192
193inline
194DjVmDir0::FileRec::~FileRec(void)
195{
196}
197
198inline int
199DjVmDir0::get_files_num(void) const
200{
201   return num2file.size();
202}
203
204inline
205DjVmDir0::DjVmDir0(const DjVmDir0 & d) :
206      name2file(d.name2file), num2file(d.num2file)
207{
208}
209
210//@}
211
212
213#ifdef HAVE_NAMESPACES
214}
215# ifndef NOT_USING_DJVU_NAMESPACE
216using namespace DJVU;
217# endif
218#endif
219#endif
Note: See TracBrowser for help on using the repository browser.