source: trunk/libdjvu/DjVmDir0.h @ 76

Last change on this file since 76 was 17, checked in by Eugene Romanenko, 16 years ago

update makefiles, remove absolute paths, update djvulibre to version 3.5.17

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