Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXXML.h
1 /********************************************************************************
2 * *
3 * X M L R e a d e r & W r i t e r *
4 * *
5 *********************************************************************************
6 * Copyright (C) 2016,2017 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as published by *
10 * the Free Software Foundation; either version 3 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public License *
19 * along with this program. If not, see <http://www.gnu.org/licenses/> *
20 ********************************************************************************/
21 #ifndef FXXML_H
22 #define FXXML_H
23 
24 
25 namespace FX {
26 
27 
31 class FXAPI FXXML {
32 public:
33  enum Error {
34  ErrOK,
48  ErrEof
49  };
50  enum Direction {
51  Stop = 0,
52  Save = 1,
53  Load = 2
54  };
55  enum {
56  CRLF = 0x0001,
57  REFS = 0x0002,
58  };
59  enum {
60  UTF8 = 1,
61  UTF16LE = 2,
62  UTF16BE = 3,
63  UTF32LE = 4,
64  UTF32BE = 5
65  };
66 protected:
67  class Element; // Element info
68 protected:
69  FXchar *begptr; // Text buffer begin ptr
70  FXchar *endptr; // Text buffer end ptr
71  FXchar *sptr; // Text buffer start ptr
72  FXchar *rptr; // Text buffer read ptr
73  FXchar *wptr; // Text buffer write ptr
74  Element *current; // Current element instance
75  FXint column; // Column number
76  FXint line; // Line number
77  Direction dir; // Direction
78  FXString vers; // Version
79  FXuint enc; // Encoding
80  FXbool owns; // Owns the buffer
81 private:
82  FXbool need(FXival n);
83  FXuint guess();
84  Error emit(const FXchar* str,FXint count);
85  Error emit(FXchar ch,FXint count);
86  void spaces();
87  FXbool name();
88  FXbool match(FXchar ch);
89  FXbool match(const FXchar* str,FXint len);
90  Error parsestring(FXString& str);
91  Error parsexml();
92  Error parseversion();
93  Error parseencoding();
94  Error parsestandalone();
95  Error parseelementdecl();
96  Error parseexternalid();
97  Error parseinternalsubset();
98  Error parsedeclarations();
99  Error parseprocessing();
100  Error parsecomment();
101  Error parseattribute(Element& elm);
102  Error parsestarttag(Element& elm);
103  Error parseendtag(Element& elm);
104  Error parsecdata(Element& elm);
105  Error parsecontents(Element& elm);
106  Error parseelement();
107 private:
108  static const FXchar *const errors[];
109 private:
110  FXXML(const FXXML&){}
111  FXXML& operator=(const FXXML&);
112 public:
113 
115  FXCallback<Error () > startDocumentCB;
116 
118  FXCallback<Error (const FXString&,const FXStringDictionary&) > startElementCB;
119 
121  FXCallback<Error (const FXString&) > charactersCB;
122 
124  FXCallback<Error (const FXString&) > commentCB;
125 
127  FXCallback<Error (const FXString&,const FXString&) > processingCB;
128 
130  FXCallback<Error (const FXString&) > endElementCB;
131 
133  FXCallback<Error () > endDocumentCB;
134 
135 public:
136 
140  FXXML();
141 
146  FXXML(FXchar* data,FXuval sz=4096,Direction d=Load);
147 
152  FXbool open(FXchar* data=NULL,FXuval sz=4096,Direction d=Load);
153 
158  Error parse();
159 
161  Error startDocument();
162 
164  Error startElement(const FXString& tag);
165 
167  Error startElement(const FXString& tag,const FXStringDictionary& atts);
168 
170  Error characters(const FXString& text);
171 
173  Error comment(const FXString& text);
174 
176  Error processing(const FXString& target,const FXString& text);
177 
179  Error endElement(const FXString& tag);
180 
182  Error endDocument();
183 
187  FXuval size() const { return endptr-begptr; }
188 
192  Direction direction() const { return dir; }
193 
197  FXint getLine() const { return line; }
198 
202  FXint getColumn() const { return column; }
203 
205  static const FXchar* getError(Error err){ return errors[err]; }
206 
211  virtual FXbool fill();
212 
217  virtual FXbool flush();
218 
222  virtual FXbool close();
223 
227  static FXbool decode(FXString& dst,const FXString& src,FXuint flags=CRLF|REFS);
228 
232  static FXbool encode(FXString& dst,const FXString& src,FXuint flags=CRLF|REFS);
233 
237  virtual ~FXXML();
238  };
239 
240 }
241 
242 #endif

Copyright © 1997-2016 Jeroen van der Zijp