diff options
author | vng <viktor.govako@gmail.com> | 2011-08-25 08:47:17 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:22:21 +0300 |
commit | 23894576db1c9c13ba55d9173488202a050a0d3a (patch) | |
tree | e8c7f3572c476271e431b6b7166595bf83565880 /indexer/feature_loader_base.hpp | |
parent | b9df96e89b57666178aada45c4c25eece8f8d756 (diff) |
[Refactoring] Factor out feature loading routine to separate instance.
Diffstat (limited to 'indexer/feature_loader_base.hpp')
-rw-r--r-- | indexer/feature_loader_base.hpp | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/indexer/feature_loader_base.hpp b/indexer/feature_loader_base.hpp new file mode 100644 index 0000000000..7ed75e1e5d --- /dev/null +++ b/indexer/feature_loader_base.hpp @@ -0,0 +1,90 @@ +#pragma once +#include "coding_params.hpp" +#include "data_header.hpp" + +#include "../coding/file_container.hpp" + + +class FeatureType; +class ArrayByteSource; + +namespace feature +{ + class LoaderBase; + + /// This info is created once. + class SharedLoadInfo + { + FilesContainerR m_cont; + DataHeader const & m_header; + + typedef FilesContainerR::ReaderT ReaderT; + + public: + SharedLoadInfo(FilesContainerR const & cont, DataHeader const & header); + + ReaderT GetDataReader() const; + ReaderT GetGeometryReader(int ind) const; + ReaderT GetTrianglesReader(int ind) const; + + LoaderBase * CreateLoader() const; + + inline serial::CodingParams const & GetCodingParams() const + { + return m_header.GetCodingParams(); + } + inline int GetScalesCount() const { return m_header.GetScalesCount(); } + inline int GetScale(int i) const { return m_header.GetScale(i); } + }; + + class LoaderBase + { + public: + LoaderBase(SharedLoadInfo const & info); + virtual ~LoaderBase() {} + + inline void AssignFeature(FeatureType * p) { m_pF = p; } + + // It seems like no need to store a copy of buffer (see FeaturesVector). + typedef char const * BufferT; + + virtual uint8_t GetHeader() = 0; + + virtual void ParseTypes() = 0; + virtual void ParseCommon() = 0; + virtual void ParseHeader2() = 0; + virtual uint32_t ParseGeometry(int scale) = 0; + virtual uint32_t ParseTriangles(int scale) = 0; + + void Deserialize(BufferT data); + + inline uint32_t GetTypesSize() const { return m_CommonOffset - m_TypesOffset; } + + protected: + inline char const * DataPtr() const { return m_Data; } + + uint32_t CalcOffset(ArrayByteSource const & source) const; + + inline serial::CodingParams const & GetCodingParams() const + { + return m_Info.GetCodingParams(); + } + + uint8_t Header() const { return static_cast<uint8_t>(*DataPtr()); } + + protected: + SharedLoadInfo const & m_Info; + FeatureType * m_pF; + + BufferT m_Data; + + static uint32_t const m_TypesOffset = 1; + uint32_t m_CommonOffset, m_Header2Offset; + + uint32_t m_ptsSimpMask; + + typedef array<uint32_t, 4> offsets_t; // should be synchronized with ARRAY_SIZE(g_arrScales) + + offsets_t m_ptsOffsets, m_trgOffsets; + }; +} |