0023864: An & symbol is read incorrectly from a XML Ocaf file
[occt.git] / src / LDOM / LDOM_XmlReader.hxx
1 // Created on: 2001-07-20
2 // Created by: Alexander GRIGORIEV
3 // Copyright (c) 2001-2012 OPEN CASCADE SAS
4 //
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
9 //
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 //
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
19
20 //AGV 060302: Input from istream
21 //            AGV 130302: bug corr: was error if strlen(root_elem_name) < 7
22
23 #ifndef LDOM_XmlReader_HeaderFile
24 #define LDOM_XmlReader_HeaderFile
25
26 //#define XML_BUFFER_SIZE 1000
27 #define XML_BUFFER_SIZE 20480
28
29 #include <LDOM_BasicElement.hxx>
30
31 class TCollection_AsciiString;
32 class LDOM_OSStream;
33
34 //  Class LDOM_XmlReader
35 //
36
37 class LDOM_XmlReader 
38 {
39  public:
40   enum RecordType {
41     XML_UNKNOWN,
42     XML_HEADER,
43     XML_DOCTYPE,
44     XML_COMMENT,
45     XML_START_ELEMENT,
46     XML_END_ELEMENT,
47     XML_FULL_ELEMENT,
48     XML_TEXT,
49     XML_CDATA,
50     XML_EOF
51   };
52
53   // ---------- PUBLIC METHODS ----------
54   LDOM_XmlReader (const int aFileDes, const Handle(LDOM_MemManager)& aDocument,
55                   TCollection_AsciiString& anErrorString);
56   // Constructor - takes a file descriptor for input
57
58   LDOM_XmlReader (istream& anInput, const Handle(LDOM_MemManager)& aDocument,
59                   TCollection_AsciiString& anErrorString);
60   // Constructor - takes an istream for input
61
62   RecordType            ReadRecord      (LDOM_OSStream& theData);
63   // reading a markup or other element of XML format
64
65   LDOM_BasicElement&    GetElement      () const        { return * myElement; }
66   // get the last element retrieved from the stream
67
68   static Standard_Boolean getInteger    (LDOMBasicString&       theValue,
69                                          const char             * theStart,
70                                          const char             * theEnd);
71   // try convert string theStart to LDOM_AsciiInteger, return False on success
72
73  private:
74   // ---------- PRIVATE (PROHIBITED) METHODS ----------
75   LDOM_XmlReader (const LDOM_XmlReader& theOther);
76   // Copy constructor
77
78   LDOM_XmlReader& operator = (const LDOM_XmlReader& theOther);
79   // Assignment
80
81  private:
82   // ---------- PRIVATE FIELDS ----------
83
84   Standard_Boolean              myEOF;
85   int                           myFileDes; // alternative 1: file descriptor
86   istream&                      myIStream; // alternative 2: istream
87   TCollection_AsciiString       & myError;
88   Handle(LDOM_MemManager)       myDocument;
89   LDOM_BasicElement             * myElement;
90   const LDOM_BasicNode          * myLastChild;  // optim. reading attributes
91   const char                    * myPtr;
92   const char                    * myEndPtr;
93   char                          myBuffer [XML_BUFFER_SIZE+4];
94 };
95
96 #endif