source: trunk/libdjvu/UnicodeByteStream.h @ 15

Last change on this file since 15 was 15, checked in by Eugene Romanenko, 15 years ago

needed libs update

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