0027077: OCAF: Implementation of streaming save/load (OCC26229) is incomplete/incorrect
[occt.git] / src / LDOM / LDOM_XmlReader.hxx
1 // Created on: 2001-07-20
2 // Created by: Alexander GRIGORIEV
3 // Copyright (c) 2001-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 //AGV 060302: Input from istream
17 //            AGV 130302: bug corr: was error if strlen(root_elem_name) < 7
18
19 #ifndef LDOM_XmlReader_HeaderFile
20 #define LDOM_XmlReader_HeaderFile
21
22 //#define XML_BUFFER_SIZE 1000
23 #define XML_BUFFER_SIZE 20480
24
25 #include <LDOM_BasicElement.hxx>
26
27 class TCollection_AsciiString;
28 class LDOM_OSStream;
29
30 //  Class LDOM_XmlReader
31 //
32
33 class LDOM_XmlReader 
34 {
35  public:
36   enum RecordType {
37     XML_UNKNOWN,
38     XML_HEADER,
39     XML_DOCTYPE,
40     XML_COMMENT,
41     XML_START_ELEMENT,
42     XML_END_ELEMENT,
43     XML_FULL_ELEMENT,
44     XML_TEXT,
45     XML_CDATA,
46     XML_EOF
47   };
48
49   // ---------- PUBLIC METHODS ----------
50   LDOM_XmlReader (const Handle(LDOM_MemManager)& aDocument,
51                   TCollection_AsciiString& anErrorString,
52                   const Standard_Boolean theTagPerStep = Standard_False);
53   // Constructor - takes a file descriptor for input
54   // Constructor - takes an istream for input
55
56   RecordType            ReadRecord      (Standard_IStream& theIStream, LDOM_OSStream& theData);
57   // reading a markup or other element of XML format
58
59   LDOM_BasicElement&    GetElement      () const        { return * myElement; }
60   // get the last element retrieved from the stream
61
62   void CreateElement (const char *theName, const Standard_Integer theLen);
63
64   static Standard_Boolean getInteger    (LDOMBasicString&       theValue,
65                                          const char             * theStart,
66                                          const char             * theEnd);
67   // try convert string theStart to LDOM_AsciiInteger, return False on success
68
69  private:
70   // ---------- PRIVATE (PROHIBITED) METHODS ----------
71   LDOM_XmlReader (const LDOM_XmlReader& theOther);
72   // Copy constructor
73
74   LDOM_XmlReader& operator = (const LDOM_XmlReader& theOther);
75   // Assignment
76
77  private:
78   // ---------- PRIVATE FIELDS ----------
79
80   Standard_Boolean              myEOF;
81   TCollection_AsciiString       & myError;
82   Handle(LDOM_MemManager)       myDocument;
83   LDOM_BasicElement             * myElement;
84   const LDOM_BasicNode          * myLastChild;  // optim. reading attributes
85   const char                    * myPtr;
86   const char                    * myEndPtr;
87   char                          myBuffer [XML_BUFFER_SIZE+4];
88   Standard_Boolean              myTagPerStep;
89 };
90
91 #endif