All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ChunkStream.h
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
5 #include "Types.h"
6 #include "BinaryParsing.h"
7 #include <istream>
8 #include <string>
9 
10 namespace Eegeo
11 {
12  namespace IO
13  {
14  namespace ChunkedFileFormat
15  {
16  static const std::string ChunkedFileTag = "HCFF";
17  static const std::string CellModelTag = "CMDL";
18  static const std::string QuantizedCompressedMeshSetTag = "QCMS";
19  static const std::string NavGraphTag = "NAVG";
20  static const std::string RoadNamesTag = "RDNM";
21  static const std::string LcmTerrainTag = "LCMT";
22  static const std::string TreeTag = "TREE";
23  static const std::string RoadTag = "ROAD";
24  static const std::string RailTag = "RAIL";
25  static const std::string TramlineTag = "TRAM";
26  static const std::string Glowmap = "GLOW";
27  static const std::string Jpeg = "JPEG";
28  static const std::string PlacenameTag = "PLAC";
29  static const std::string InteriorTag = "INTR";
30  static const std::string InteriorMetadataTag = "INTM";
31  static const std::string InteriorInstanceDataTag = "INST";
32  static const std::string PropModelTag = "PMDL";
33  static const std::string InteriorsFloorTag = "FLOR";
34  static const std::string InteriorEntityTag = "ENTI";
35  static const std::string InteriorMarkersTag = "IMKR";
36  static const std::string TextTag = "TEXT";
37  static const std::string CoverageManifestTag = "CTMN";
38  static const std::string CoverageTreeListTag = "CTLS";
39  static const std::string BlockCoverageTreeTag = "BLCT";
40  static const std::string BuildingFootprintsListTag = "BFLS";
41  static const std::string BuildingFootprintsTag = "BDFP";
42  static const std::string HighlightGeometryTag = "HIGH";
43  static const std::string ReferencedChunkStoreTag = "REFS";
44  static const std::string ReferenceChunkTag = "REFC";
45  static const std::string ThemeManifestTag = "THMN";
46  static const std::string InteriorMaterialsTag = "IMTS";
47  static const std::string InteriorMaterialTag = "IMAT";
48  static const std::string ThemesTag = "THMS";
49  static const std::string ThemeTag = "THME";
50  static const std::string PlaceNameStylesTag = "PSTL";
51  static const std::string PlaceNameStyleTag = "PSTE";
52  static const std::string VehiclesTag = "VCLS";
53  static const std::string VehicleTypeTag = "VTLS";
54  static const std::string VehicleTag = "VHCL";
55  static const std::string ThemeStatesTag = "TSTS";
56  static const std::string ThemeStateTag = "THST";
57  static const std::string ThemeLightingTag = "THLI";
58  static const std::string ThemeTexturesTag = "THTX";
59  static const std::string ThemeOverlayTag = "THOV";
60  static const std::string ThemeLcmTexturesTag = "THLT";
61  static const std::string BinaryFontInfoTag = "BFIN";
62  static const std::string BinaryFontCommonTag = "BFCO";
63  static const std::string BinaryFontPagesTag = "BFPA";
64  static const std::string BinaryFontCharsTag = "BFCH";
65  static const std::string BinaryFontKerningTag = "BFKE";
66  static const std::string IndoorEntityTag = "IENT";
67 
69  {
70  public:
71  ChunkStream();
72  ~ChunkStream();
73 
74  static bool Requires_Ios5_Cpp11_Runtime_Fix;
75 
76  bool TrySetStream(std::istream* bytes);
77 
78  const std::string& GetCurrentTag() const { Eegeo_ASSERT(!AtEndOfStream()); return m_currentTag; }
79  u32 GetHeaderVersion() const { Eegeo_ASSERT(!AtEndOfStream()); return m_headerVersion; }
80  u32 GetCurrentBodyVersion() const { Eegeo_ASSERT(!AtEndOfStream()); return m_currentBodyVersion; }
81  u32 GetCurrentBodyAlignment() const { Eegeo_ASSERT(!AtEndOfStream()); return m_currentBodyAlignment; }
82  u32 GetCurrentNumOfChildren() const { Eegeo_ASSERT(!AtEndOfStream()); return m_currentNumberOfChildren; }
83  u32 GetCurrentBodyLength() const { Eegeo_ASSERT(!AtEndOfStream()); return static_cast<u32>(m_currentBodyLength); }
84 
85  bool HasAlignedData() const;
86 
87  // eof bit is only set if we have read past the end of stream (and not if we have tellg / seeked past the end of stream)
88  bool AtEndOfStream() const { return m_pBytes->eof(); }
89  std::istream* GetCurrentBodyData();
90  bool AdvanceToNextChunk();
91  u32 SkipSubtree(std::string expectedTag);
92 
93  private:
94 
95  std::istream* m_pBytes;
96  u32 m_headerVersion;
97 
98  std::string m_currentTag;
99  u32 m_currentBodyVersion;
100  u32 m_currentBodyAlignment;
101  u32 m_currentNumberOfChildren;
102  std::istream::off_type m_currentBodyLength;
103  std::istream::pos_type m_currentBodyStreamPosition;
105 
106  std::istream::pos_type GetPositionOfNextChunk();
107  bool TryReadRootChunkHeader();
108  bool TryReadChunkHeader(bool isHcffRootChunk);
109  void Reset();
110  void ClearCurrent();
111  };
112  }
113  }
114 }