ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
E57XmlParser.h
Go to the documentation of this file.
1 /*
2  * Original work Copyright 2009 - 2010 Kevin Ackley (kackley@gwi.net)
3  * Modified work Copyright 2018 - 2020 Andy Maloney <asmaloney@gmail.com>
4  *
5  * Permission is hereby granted, free of charge, to any person or organization
6  * obtaining a copy of the software and accompanying documentation covered by
7  * this license (the "Software") to use, reproduce, display, distribute,
8  * execute, and transmit the Software, and to prepare derivative works of the
9  * Software, and to permit third-parties to whom the Software is furnished to
10  * do so, all subject to the following:
11  *
12  * The copyright notices in the Software and this entire statement, including
13  * the above license grant, this restriction and the following disclaimer,
14  * must be included in all copies of the Software, in whole or in part, and
15  * all derivative works of the Software, unless such copies or derivative
16  * works are solely in the form of machine-executable object code generated by
17  * a source language processor.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
22  * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
23  * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
24  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25  * DEALINGS IN THE SOFTWARE.
26  */
27 
28 #pragma once
29 
30 #include <stack>
31 
32 #include <xercesc/sax/InputSource.hpp>
33 #include <xercesc/sax2/DefaultHandler.hpp>
34 
35 #include "Common.h"
36 
37 using namespace XERCES_CPP_NAMESPACE;
38 
40 {
41  class SAX2XMLReader;
42 }
43 
44 namespace e57
45 {
46  class CheckedFile;
47 
48  class E57XmlParser : public DefaultHandler
49  {
50  public:
52  ~E57XmlParser() override;
53 
54  void init();
55 
56  void parse( InputSource &inputSource );
57 
58  private:
60  void startElement( const XMLCh *const uri, const XMLCh *const localName, const XMLCh *const qName,
61  const Attributes &attributes ) override;
62  void endElement( const XMLCh *const uri, const XMLCh *const localName, const XMLCh *const qName ) override;
63  void characters( const XMLCh *const chars, const XMLSize_t length ) override;
64 
66  void warning( const SAXParseException &ex ) override;
67  void error( const SAXParseException &ex ) override;
68  void fatalError( const SAXParseException &ex ) override;
69 
70  ustring toUString( const XMLCh *const xml_str );
71  ustring lookupAttribute( const Attributes &attributes, const XMLCh *attribute_name );
72  bool isAttributeDefined( const Attributes &attributes, const XMLCh *attribute_name );
73 
75 
76  struct ParseInfo
77  {
82  NodeType nodeType; // used by all types
83  int64_t minimum; // used in E57_INTEGER, E57_SCALED_INTEGER
84  int64_t maximum; // used in E57_INTEGER, E57_SCALED_INTEGER
85  double scale; // used in E57_SCALED_INTEGER
86  double offset; // used in E57_SCALED_INTEGER
87  FloatPrecision precision; // used in E57_FLOAT
88  double floatMinimum; // used in E57_FLOAT
89  double floatMaximum; // used in E57_FLOAT
90  int64_t fileOffset; // used in E57_BLOB, E57_COMPRESSED_VECTOR
91  int64_t length; // used in E57_BLOB
92  bool allowHeterogeneousChildren; // used in E57_VECTOR
93  int64_t recordCount; // used in E57_COMPRESSED_VECTOR
94  ustring childText; // used by all types, accumlates all child text between tags
95 
98  NodeImplSharedPtr container_ni;
99 
100  ParseInfo(); // default ctor
101  void dump( int indent = 0, std::ostream &os = std::cout ) const;
102  };
103  std::stack<ParseInfo> stack_;
104 
105  SAX2XMLReader *xmlReader;
106  };
107 
108  class E57XmlFileInputSource : public InputSource
109  {
110  public:
111  E57XmlFileInputSource( CheckedFile *cf, uint64_t logicalStart, uint64_t logicalLength );
112  ~E57XmlFileInputSource() override = default;
113 
116 
117  BinInputStream *makeStream() const override;
118 
119  private:
120  //??? lifetime of cf_ must be longer than this object!
121  CheckedFile *cf_;
122  uint64_t logicalStart_;
123  uint64_t logicalLength_;
124  };
125 }
int offset
E57XmlFileInputSource & operator=(const E57XmlFileInputSource &)=delete
~E57XmlFileInputSource() override=default
E57XmlFileInputSource(const E57XmlFileInputSource &)=delete
__host__ __device__ float length(float2 v)
Definition: cutil_math.h:1162
static void error(char *msg)
Definition: lsd.c:159
std::shared_ptr< class NodeImpl > NodeImplSharedPtr
Definition: Common.h:190
std::shared_ptr< class ImageFileImpl > ImageFileImplSharedPtr
Definition: Common.h:188
FloatPrecision
The IEEE floating point number precisions supported.
Definition: E57Format.h:71
std::string ustring
UTF-8 encodeded Unicode string.
Definition: E57Format.h:54
NodeType
Identifiers for types of E57 elements.
Definition: E57Format.h:58