ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ImageFileImpl.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 <memory>
31 
32 #include "Common.h"
33 
34 namespace e57
35 {
36  class CheckedFile;
37 
38  struct E57FileHeader;
39  struct NameSpace;
40 
41  class ImageFileImpl : public std::enable_shared_from_this<ImageFileImpl>
42  {
43  public:
45  void construct2( const ustring &fileName, const ustring &mode );
46  void construct2( const char *input, const uint64_t size );
47  std::shared_ptr<StructureNodeImpl> root();
48  void close();
49  void cancel();
50  bool isOpen() const;
51  bool isWriter() const;
52  int writerCount() const;
53  int readerCount() const;
55 
56  uint64_t allocateSpace( uint64_t byteCount, bool doExtendNow );
57  CheckedFile *file() const;
58  ustring fileName() const;
59 
61  void extensionsAdd( const ustring &prefix, const ustring &uri );
62  bool extensionsLookupPrefix( const ustring &prefix, ustring &uri ) const;
63  bool extensionsLookupUri( const ustring &uri, ustring &prefix ) const;
64  size_t extensionsCount() const;
65  ustring extensionsPrefix( const size_t index ) const;
66  ustring extensionsUri( const size_t index ) const;
67 
69  bool isElementNameExtended( const ustring &elementName );
70  bool isElementNameLegal( const ustring &elementName, bool allowNumber = true );
71  bool isPathNameLegal( const ustring &pathName );
72  void checkElementNameLegal( const ustring &elementName, bool allowNumber = true );
73  void elementNameParse( const ustring &elementName, ustring &prefix, ustring &localPart, bool allowNumber = true );
74 
75  void pathNameCheckWellFormed( const ustring &pathName );
76  void pathNameParse( const ustring &pathName, bool &isRelative, StringList &fields );
77  ustring pathNameUnparse( bool isRelative, const StringList &fields );
78 
79  unsigned bitsNeeded( int64_t minimum, int64_t maximum );
80  void incrWriterCount();
81  void decrWriterCount();
82  void incrReaderCount();
83  void decrReaderCount();
84 
86 #ifdef E57_DEBUG
87  void dump( int indent = 0, std::ostream &os = std::cout ) const;
88 #endif
89 
90  private:
91  friend class E57XmlParser;
92  friend class BlobNodeImpl;
94  friend class CompressedVectorReaderImpl; //??? add file() instead of
95  // accessing file_, others
96  // friends too
97 
98  static void readFileHeader( CheckedFile *file, E57FileHeader &header );
99 
100  void checkImageFileOpen( const char *srcFileName, int srcLineNumber, const char *srcFunctionName ) const;
101 
102  ustring fileName_;
103  bool isWriter_;
104  int writerCount_;
105  int readerCount_;
106 
107  ReadChecksumPolicy checksumPolicy;
108 
109  CheckedFile *file_;
110 
112  uint64_t xmlLogicalOffset_;
113  uint64_t xmlLogicalLength_;
114 
116  uint64_t unusedLogicalStart_;
117 
119  std::vector<NameSpace> nameSpaces_;
120 
122  std::shared_ptr<StructureNodeImpl> root_;
123  };
124 }
int size
std::vector< PCLPointField > fields
ImageFileImpl(ReadChecksumPolicy policy)
std::shared_ptr< StructureNodeImpl > root()
bool isElementNameLegal(const ustring &elementName, bool allowNumber=true)
CheckedFile * file() const
bool isWriter() const
void dump(int indent=0, std::ostream &os=std::cout) const
Diagnostic functions:
int writerCount() const
int readerCount() const
void extensionsAdd(const ustring &prefix, const ustring &uri)
Manipulate registered extensions in the file.
unsigned bitsNeeded(int64_t minimum, int64_t maximum)
size_t extensionsCount() const
void checkElementNameLegal(const ustring &elementName, bool allowNumber=true)
bool extensionsLookupUri(const ustring &uri, ustring &prefix) const
void construct2(const ustring &fileName, const ustring &mode)
ustring pathNameUnparse(bool isRelative, const StringList &fields)
uint64_t allocateSpace(uint64_t byteCount, bool doExtendNow)
bool isPathNameLegal(const ustring &pathName)
void pathNameParse(const ustring &pathName, bool &isRelative, StringList &fields)
bool isElementNameExtended(const ustring &elementName)
Utility functions:
ustring fileName() const
void elementNameParse(const ustring &elementName, ustring &prefix, ustring &localPart, bool allowNumber=true)
ustring extensionsPrefix(const size_t index) const
bool extensionsLookupPrefix(const ustring &prefix, ustring &uri) const
ustring extensionsUri(const size_t index) const
void pathNameCheckWellFormed(const ustring &pathName)
int ReadChecksumPolicy
Specifies the percentage of checksums which are verified when reading an ImageFile (0-100%).
Definition: E57Format.h:95
std::string ustring
UTF-8 encodeded Unicode string.
Definition: E57Format.h:54
std::vector< std::string > StringList
Definition: Common.h:193