Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--coding/coding.pro1
-rw-r--r--coding/parse_xml.hpp64
-rw-r--r--coding/reader.hpp22
-rw-r--r--coding/source.hpp19
-rw-r--r--generator/xml_element.cpp10
-rw-r--r--map/feature_vec_model.cpp2
-rw-r--r--platform/chunks_download_strategy.cpp2
7 files changed, 54 insertions, 66 deletions
diff --git a/coding/coding.pro b/coding/coding.pro
index b87816960c..7852a26118 100644
--- a/coding/coding.pro
+++ b/coding/coding.pro
@@ -53,7 +53,6 @@ HEADERS += \
reader.hpp \
diff.hpp \
diff_patch_common.hpp \
- source.hpp \
lodepng.hpp \
lodepng_io.hpp \
lodepng_io_private.hpp \
diff --git a/coding/parse_xml.hpp b/coding/parse_xml.hpp
index b5ca32b904..9896155bc2 100644
--- a/coding/parse_xml.hpp
+++ b/coding/parse_xml.hpp
@@ -1,39 +1,59 @@
#pragma once
#include "internal/xmlparser.h"
-#include "source.hpp"
#include "../base/assert.hpp"
-static const size_t KMaxXMLFileBufferSize = 16384;
-
-template <typename XMLDispatcherT, typename SourceT>
-bool ParseXML(SourceT & source, XMLDispatcherT & dispatcher, bool useCharData = false)
+template <typename XMLDispatcherT, typename SequenceT>
+uint64_t ParseXMLSequence(SequenceT & source, XMLDispatcherT & dispatcher, bool useCharData = false)
{
// Create the parser
XmlParser<XMLDispatcherT> parser(dispatcher, useCharData);
if (!parser.Create())
- return false;
+ return 0;
- try
+ int const BUFFER_SIZE = 16 * 1024;
+
+ uint64_t res = 0;
+ int readed;
+ do
{
- while (true)
- {
- char * buffer = static_cast<char *>(parser.GetBuffer(KMaxXMLFileBufferSize));
- CHECK(buffer, ());
- source.Read(buffer, KMaxXMLFileBufferSize);
- if (!parser.ParseBuffer(KMaxXMLFileBufferSize, false))
- return false;
- }
- }
- catch (SourceOutOfBoundsException & e)
+ char * buffer = static_cast<char *>(parser.GetBuffer(BUFFER_SIZE));
+ ASSERT(buffer, ());
+
+ readed = source.Read(buffer, BUFFER_SIZE);
+ if (readed == 0 || !parser.ParseBuffer(readed, false))
+ return res;
+
+ res += readed;
+ } while (readed == BUFFER_SIZE);
+
+ return res;
+}
+
+namespace
+{
+
+template <class SourceT> class SequenceAdapter
+{
+ SourceT & m_source;
+public:
+ SequenceAdapter(SourceT & source) : m_source(source) {}
+ uint64_t Read(void * p, uint64_t size)
{
- size_t const toRead = e.BytesRead();
- // 0 - means Reader overflow (see ReaderSource::Read)
- if (toRead == 0 || !parser.ParseBuffer(toRead, true))
- return false;
+ uint64_t const correctSize = min(size, m_source.Size());
+ m_source.Read(p, correctSize);
+ return correctSize;
}
+};
- return true;
+}
+
+template <typename XMLDispatcherT, typename SourceT>
+bool ParseXML(SourceT & source, XMLDispatcherT & dispatcher, bool useCharData = false)
+{
+ uint64_t const size = source.Size();
+ SequenceAdapter<SourceT> adapter(source);
+ return (ParseXMLSequence(adapter, dispatcher, useCharData) == size);
}
diff --git a/coding/reader.hpp b/coding/reader.hpp
index 6e2a106034..25dd91218b 100644
--- a/coding/reader.hpp
+++ b/coding/reader.hpp
@@ -1,6 +1,5 @@
#pragma once
#include "endianness.hpp"
-#include "source.hpp"
#include "../base/assert.hpp"
#include "../base/logging.hpp"
@@ -180,23 +179,10 @@ public:
void Read(void * p, size_t size)
{
- uint64_t const readerSize = m_reader.Size();
- if (m_pos + size > readerSize)
- {
- size_t remainingSize = 0;
- if (readerSize >= m_pos)
- {
- remainingSize = static_cast<size_t>(readerSize - m_pos);
- m_reader.Read(m_pos, p, remainingSize);
- m_pos = readerSize;
- }
- MYTHROW1(SourceOutOfBoundsException, remainingSize, ());
- }
- else
- {
- m_reader.Read(m_pos, p, size);
- m_pos += size;
- }
+ ASSERT(m_pos + size <= m_reader.Size(), (m_pos, size, m_reader.Size()));
+
+ m_reader.Read(m_pos, p, size);
+ m_pos += size;
}
void Skip(uint64_t size)
diff --git a/coding/source.hpp b/coding/source.hpp
deleted file mode 100644
index 1a4c7274c9..0000000000
--- a/coding/source.hpp
+++ /dev/null
@@ -1,19 +0,0 @@
-#pragma once
-
-#include "../base/base.hpp"
-#include "../base/exception.hpp"
-
-
-class SourceOutOfBoundsException : public RootException
-{
-public:
- SourceOutOfBoundsException(size_t bytesRead, char const * what, string const & msg)
- : RootException(what, msg), m_BytesRead(bytesRead)
- {
- }
-
- size_t BytesRead() const { return m_BytesRead; }
-
-private:
- size_t const m_BytesRead;
-};
diff --git a/generator/xml_element.cpp b/generator/xml_element.cpp
index 294dbaf552..df1ace1957 100644
--- a/generator/xml_element.cpp
+++ b/generator/xml_element.cpp
@@ -2,9 +2,11 @@
#include "../coding/parse_xml.hpp"
#include "../coding/reader.hpp"
-#include "../std/cstdio.hpp"
+#include "../std/cstdio.hpp"
#include "../std/algorithm.hpp"
+#include "../std/limits.hpp"
+
bool BaseOSMParser::is_our_tag(string const & name)
{
@@ -62,7 +64,7 @@ void BaseOSMParser::Pop(string const &)
struct StdinReader
{
- size_t Read(char * buffer, size_t bufferSize)
+ uint64_t Read(char * buffer, uint64_t bufferSize)
{
return fread(buffer, sizeof(char), bufferSize, stdin);
}
@@ -72,11 +74,11 @@ struct StdinReader
void ParseXMLFromStdIn(BaseOSMParser & parser)
{
StdinReader reader;
- ParseXML(reader, parser);
+ (void)ParseXMLSequence(reader, parser);
}
void ParseXMLFromFile(FileReader const & reader, BaseOSMParser & parser)
{
ReaderSource<FileReader> src(reader);
- ParseXML(src, parser);
+ CHECK(ParseXML(src, parser), ());
}
diff --git a/map/feature_vec_model.cpp b/map/feature_vec_model.cpp
index 958394e8b1..bc5287c9a1 100644
--- a/map/feature_vec_model.cpp
+++ b/map/feature_vec_model.cpp
@@ -17,7 +17,7 @@ namespace model
{
// While reading any files (classificator or mwm), there are 2 types of possible exceptions:
-// Reader::Exception; FileAbsentException; SourceOutOfBoundsException.
+// Reader::Exception, FileAbsentException.
// Let's process RootException everywhere, to supress such errors.
void FeaturesFetcher::InitClassificator()
diff --git a/platform/chunks_download_strategy.cpp b/platform/chunks_download_strategy.cpp
index 14670b649f..57e4a7353e 100644
--- a/platform/chunks_download_strategy.cpp
+++ b/platform/chunks_download_strategy.cpp
@@ -121,7 +121,7 @@ int64_t ChunksDownloadStrategy::LoadOrInitChunks( string const & fName,
}
catch (RootException const & e)
{
- // Usually - file not exists. May be SourceOutOfBoundsException.
+ // Usually - file not exists or Reader::Exception.
LOG(LDEBUG, (e.Msg()));
}