source: trunk/libdjvu/XMLTags.h @ 81

Last change on this file since 81 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.5 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: XMLTags.h,v 1.9 2003/11/07 22:08:22 leonb Exp $
55// $Name:  $
56
57#ifndef _LT_XMLTAGS__
58#define _LT_XMLTAGS__
59#ifdef HAVE_CONFIG_H
60#include "config.h"
61#endif
62#if NEED_GNUG_PRAGMAS
63# pragma interface
64#endif
65
66// From: Leon Bottou, 1/31/2002
67// This is purely Lizardtech stuff.
68
69#include "GContainer.h"
70#include "GString.h"
71
72#ifdef HAVE_NAMESPACES
73namespace DJVU {
74# ifdef NOT_DEFINED // Just to fool emacs c++ mode
75}
76#endif
77#endif
78
79class lt_XMLContents;
80class DjVuFile;
81class DjVuDocument;
82class ByteStream;
83class XMLByteStream;
84class GURL;
85
86class lt_XMLTags : public GPEnabled
87{
88protected:
89  lt_XMLTags();
90  lt_XMLTags(const char n[]);
91
92public:
93  /// Empty creator.
94  static GP<lt_XMLTags> create(void) { return new lt_XMLTags; }
95  /// Default the specified tag.
96  static GP<lt_XMLTags> create(const char n[]) { return new lt_XMLTags(n); }
97  /// Initialize from the specified URL.
98  void init(const GURL & url);
99  /// Create from the specified URL.
100  static GP<lt_XMLTags> create(const GURL &url);
101  /// Initialize from the specified bytestream.
102  void init(const GP<ByteStream> &bs);
103  /// Create from the specified bytestream.
104  static GP<lt_XMLTags> create(const GP<ByteStream> &bs);
105  /// Initialize from an XMLByteStream.
106  void init(XMLByteStream &xmlbs);
107  /// Create from an XML bytestream.
108  static GP<lt_XMLTags> create(XMLByteStream &xmlbs);
109  /// Non-virtual destructor.
110  ~lt_XMLTags();
111
112  inline int get_Line(void) const;
113  inline const GUTF8String& get_raw(void) const;
114  inline const GUTF8String& get_name(void) const;
115  inline const GList<lt_XMLContents>& get_content(void) const;
116  inline const GMap<GUTF8String,GUTF8String>& get_args(void) const;
117  inline const GMap<GUTF8String,GPList<lt_XMLTags> >& get_allTags(void) const;
118
119  GPList<lt_XMLTags> get_Tags(char const tagname[]) const;
120  inline void set_Line(const int xstartline) { startline=xstartline; }
121
122  inline void addtag(GP<lt_XMLTags> x);
123  inline void addraw(GUTF8String raw);
124  inline GPosition contains(GUTF8String name) const;
125  inline const GPList<lt_XMLTags> & operator [] (const GUTF8String name) const;
126  inline const GPList<lt_XMLTags> & operator [] (const GPosition &pos) const;
127  static void ParseValues(char const *t, GMap<GUTF8String,GUTF8String> &args,bool downcase=true);
128  static void get_Maps(char const tagname[],char const argn[],
129    GPList<lt_XMLTags> list, GMap<GUTF8String, GP<lt_XMLTags> > &map);
130  void write(ByteStream &bs,bool const top=true) const;
131
132protected:
133  GUTF8String name;
134  GMap<GUTF8String,GUTF8String> args;
135  GList<lt_XMLContents> content;
136  GUTF8String raw;
137  GMap<GUTF8String,GPList<lt_XMLTags> > allTags;
138  int startline;
139};
140
141class lt_XMLContents
142{
143public:
144  lt_XMLContents(void);
145  lt_XMLContents(GP<lt_XMLTags> tag);
146  GP<lt_XMLTags> tag;
147  GUTF8String raw;
148  void write(ByteStream &bs) const;
149};
150
151inline GP<lt_XMLTags>
152lt_XMLTags::create(const GURL &url)
153{
154  const GP<lt_XMLTags> retval(new lt_XMLTags);
155  retval->init(url);
156  return retval;
157}
158
159inline GP<lt_XMLTags>
160lt_XMLTags::create(const GP<ByteStream> &bs)
161{
162  const GP<lt_XMLTags> retval(new lt_XMLTags);
163  retval->init(bs);
164  return retval;
165}
166
167inline GP<lt_XMLTags>
168lt_XMLTags::create(XMLByteStream &xmlbs)
169{
170  const GP<lt_XMLTags> retval(new lt_XMLTags);
171  retval->init(xmlbs);
172  return retval;
173}
174
175/// Non-virtual destructor.
176inline void
177lt_XMLTags::addtag (GP<lt_XMLTags> x)
178{
179  content.append(lt_XMLContents(x));
180  allTags[x->name].append(x);
181}
182
183inline void
184lt_XMLTags::addraw (GUTF8String r)
185{
186  GPosition pos=content;
187  if(pos)
188  {
189    content[pos].raw+=r;
190  }else
191  {
192    raw+=r;
193  }
194}
195
196inline int
197lt_XMLTags::get_Line(void) const
198{ return startline; }
199
200inline const GUTF8String &
201lt_XMLTags::get_name(void) const { return name; }
202
203inline const GUTF8String &
204lt_XMLTags::get_raw(void) const { return raw; }
205
206inline const GList<lt_XMLContents> &
207lt_XMLTags::get_content(void) const { return content; }
208
209inline const GMap<GUTF8String,GUTF8String> &
210lt_XMLTags::get_args(void) const { return args; }
211
212inline const GMap<GUTF8String,GPList<lt_XMLTags> > &
213lt_XMLTags::get_allTags(void) const { return allTags; }
214
215inline GPosition
216lt_XMLTags::contains(GUTF8String name) const
217{
218  return allTags.contains(name);
219}
220
221inline const GPList<lt_XMLTags> &
222lt_XMLTags::operator [] (const GUTF8String name) const
223{
224  return allTags[name];
225}
226
227inline const GPList<lt_XMLTags> &
228lt_XMLTags::operator [] (const GPosition &pos) const
229{
230  return allTags[pos];
231}
232
233
234#ifdef HAVE_NAMESPACES
235}
236# ifndef NOT_USING_DJVU_NAMESPACE
237using namespace DJVU;
238# endif
239#endif
240#endif /* _LT_XMLTAGS__ */
241
242
Note: See TracBrowser for help on using the repository browser.