source: trunk/libdjvu/UnicodeByteStream.h @ 269

Last change on this file since 269 was 206, checked in by Eugene Romanenko, 14 years ago

DJVU plugin: djvulibre updated to version 3.5.19

File size: 7.4 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: UnicodeByteStream.h,v 1.10 2007/03/25 20:48:34 leonb Exp $
57// $Name: release_3_5_19 $
58
59#ifndef _UNICODEBYTESTREAM_H_
60#define _UNICODEBYTESTREAM_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/** @name UnicodeByteStream.h
70
71    Files #"UnicodeByteStream.h"# and #"UnicodeByteStream.cpp"# implement a parser for
72    files structured W3C Extensible Markup Language (XML) 1.0 (Second Edition).
73   
74    Class \Ref{UnicodeByteStream} provides a way to read or write XML files.
75    files.  Member functions provide an easy mean to position the underlying
76    \Ref{ByteStream}.
77
78    {\bf References} --- W3C Extensible Markup Language (XML) 1.0
79    (Second Edition)
80    \URL{http://www.w3.org/TR/2000/REC-xml-20001006.html}
81
82    @memo
83    XML file parser.
84    @author
85    Bill C Riemers <docbill@sourceforge.net>
86    @version
87    #$Id: UnicodeByteStream.h,v 1.10 2007/03/25 20:48:34 leonb Exp $# */
88//@{
89
90#include "DjVuGlobal.h"
91#include "GString.h"
92#include "ByteStream.h"
93
94
95#ifdef HAVE_NAMESPACES
96namespace DJVU {
97# ifdef NOT_DEFINED // Just to fool emacs c++ mode
98}
99#endif
100#endif
101
102
103
104/** ByteStream interface for an Unicode file.
105
106    Class #UnicodeByteStream# augments the #ByteStream# interface with
107    functions for navigating Unicode documents.  It works in relation
108    with a ByteStream specified at construction time.
109
110    {\bf Reading an Unicode file} --- You can read an Unicode file by
111    constructing an #UnicodeByteStream# object attached to the ByteStream
112    containing the Unicode file.
113   
114    {\bf Writing an Unicode file} --- You can write an Unicode file by
115    constructing an #UnicodeByteStream# object attached to the seekable
116    ByteStream object that will contain the XML file.
117
118    Writing an XML file requires a seekable ByteStream (see
119    \Ref{ByteStream::is_seekable}).  This is not much of a problem because you
120    can always create the XML file into a \Ref{MemoryByteStream} and then use
121    \Ref{ByteStream::copy} to transfer the XML file into a non seekable
122    ByteStream.  */
123
124class UnicodeByteStream : public ByteStream
125{
126protected:
127  UnicodeByteStream(const UnicodeByteStream &bs);
128  UnicodeByteStream(GP<ByteStream> bs,
129    const GStringRep::EncodeType encodetype=GStringRep::XUTF8);
130public:
131  /** Constructs an UnicodeByteStream object attached to ByteStream #bs#.
132      Any ByteStream can be used when reading an XML file.  Writing
133      an XML file however requires a seekable ByteStream. */
134  static GP<UnicodeByteStream> create(GP<ByteStream> bs,
135    const GStringRep::EncodeType encodetype=GStringRep::XUTF8)
136  { return new UnicodeByteStream(bs,encodetype); }
137
138  // --- BYTESTREAM INTERFACE
139  ~UnicodeByteStream();
140  /// Sets the encoding type and seek's to position 0.
141  void set_encodetype(const GStringRep::EncodeType et=GStringRep::XUTF8);
142  void set_encoding(const GUTF8String &encoding);
143  /// Simmular to fgets(), except read aheads effect the tell() position.
144  virtual GUTF8String gets(size_t const t=0,unsigned long const stopat='\n',bool const inclusive=true); 
145  /// Resets the gets buffering as well as physically seeking.
146  virtual int seek(long offset, int whence = SEEK_SET, bool nothrow=false);
147  /** Physically reads the specified bytes, and truncate the read ahead buffer.
148    */
149  virtual size_t read(void *buffer, size_t size);
150  /// Not correctly implimented...
151  virtual size_t write(const void *buffer, size_t size);
152  /// tell will tell you the read position, including read ahead for gets()...
153  virtual long tell(void) const;
154  /// Does a flush, and clears the read ahead buffer.
155  virtual void flush(void);
156
157  /// Find out how many lines have been read with gets.
158  int get_lines_read(void) const { return linesread; }
159protected:
160  /// The real byte stream.
161  GP<ByteStream> bs;
162  GUTF8String buffer;
163  int bufferpos;
164  int linesread;
165  long startpos;
166private:
167  // Cancel C++ default stuff
168  UnicodeByteStream & operator=(UnicodeByteStream &);
169};
170
171
172class XMLByteStream : public UnicodeByteStream
173{
174protected:
175  XMLByteStream(GP<ByteStream> &bs);
176  XMLByteStream(UnicodeByteStream &bs);
177  void init(void);
178public:
179  static GP<XMLByteStream> create(GP<ByteStream> bs);
180  static GP<XMLByteStream> create(UnicodeByteStream &bs);
181  // --- BYTESTREAM INTERFACE
182  ~XMLByteStream();
183};
184
185inline GP<XMLByteStream>
186XMLByteStream::create(UnicodeByteStream &bs)
187{
188  return new XMLByteStream(bs);
189}
190
191//@}
192
193
194#ifdef HAVE_NAMESPACES
195}
196# ifndef NOT_USING_DJVU_NAMESPACE
197using namespace DJVU;
198# endif
199#endif
200#endif
201
Note: See TracBrowser for help on using the repository browser.