0031340: LDOM fails to read XML file starting with BOM
[occt.git] / src / LDOM / LDOM_XmlReader.hxx
old mode 100755 (executable)
new mode 100644 (file)
index e0c9117..cc8965f
@@ -1,23 +1,19 @@
 // Created on: 2001-07-20
 // Created by: Alexander GRIGORIEV
-// Copyright (c) 2001-2012 OPEN CASCADE SAS
+// Copyright (c) 2001-2014 OPEN CASCADE SAS
 //
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
+// This file is part of Open CASCADE Technology software library.
 //
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
 //
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-//AGV 060302: Input from istream
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+//AGV 060302: Input from std::istream
 //            AGV 130302: bug corr: was error if strlen(root_elem_name) < 7
 
 #ifndef LDOM_XmlReader_HeaderFile
@@ -27,9 +23,9 @@
 #define XML_BUFFER_SIZE 20480
 
 #include <LDOM_BasicElement.hxx>
+#include <LDOM_OSStream.hxx>
 
 class TCollection_AsciiString;
-class LDOM_OSStream;
 
 //  Class LDOM_XmlReader
 //
@@ -51,25 +47,28 @@ class LDOM_XmlReader
   };
 
   // ---------- PUBLIC METHODS ----------
-  LDOM_XmlReader (const int aFileDes, const Handle(LDOM_MemManager)& aDocument,
-                  TCollection_AsciiString& anErrorString);
+  LDOM_XmlReader (const Handle(LDOM_MemManager)& aDocument,
+                  TCollection_AsciiString& anErrorString,
+                  const Standard_Boolean theTagPerStep = Standard_False);
   // Constructor - takes a file descriptor for input
+  // Constructor - takes an std::istream for input
 
-  LDOM_XmlReader (istream& anInput, const Handle(LDOM_MemManager)& aDocument,
-                  TCollection_AsciiString& anErrorString);
-  // Constructor - takes an istream for input
-
-  RecordType            ReadRecord      (LDOM_OSStream& theData);
+  RecordType            ReadRecord      (Standard_IStream& theIStream, LDOM_OSStream& theData);
   // reading a markup or other element of XML format
 
   LDOM_BasicElement&    GetElement      () const        { return * myElement; }
   // get the last element retrieved from the stream
 
+  void CreateElement (const char *theName, const Standard_Integer theLen);
+
   static Standard_Boolean getInteger    (LDOMBasicString&       theValue,
                                          const char             * theStart,
                                          const char             * theEnd);
   // try convert string theStart to LDOM_AsciiInteger, return False on success
 
+  // Returns the byte order mask defined at the start of a stream
+  LDOM_OSStream::BOMType GetBOM() const { return myBOM; }
+
  private:
   // ---------- PRIVATE (PROHIBITED) METHODS ----------
   LDOM_XmlReader (const LDOM_XmlReader& theOther);
@@ -82,8 +81,6 @@ class LDOM_XmlReader
   // ---------- PRIVATE FIELDS ----------
 
   Standard_Boolean              myEOF;
-  int                           myFileDes; // alternative 1: file descriptor
-  istream&                      myIStream; // alternative 2: istream
   TCollection_AsciiString       & myError;
   Handle(LDOM_MemManager)       myDocument;
   LDOM_BasicElement             * myElement;
@@ -91,6 +88,8 @@ class LDOM_XmlReader
   const char                    * myPtr;
   const char                    * myEndPtr;
   char                          myBuffer [XML_BUFFER_SIZE+4];
+  Standard_Boolean              myTagPerStep;
+  LDOM_OSStream::BOMType        myBOM;
 };
 
 #endif