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:
authorSergey Magidovich <mgsergio@mapswithme.com>2017-06-28 16:00:02 +0300
committerYuri Gorshenin <mipt.vi002@gmail.com>2017-07-05 13:32:16 +0300
commit7d8853ea7c98f08a84f0bec04d9aab4e07c674e1 (patch)
tree327662ddece16de9486bd538a37fc5c7b7b0a403
parentda19077d3b927d26b197e9f09fe161c795cbe7e4 (diff)
[OPENLR] Report more errors.
-rw-r--r--openlr/openlr_sample.cpp24
-rw-r--r--openlr/openlr_stat/openlr_stat.cpp31
2 files changed, 43 insertions, 12 deletions
diff --git a/openlr/openlr_sample.cpp b/openlr/openlr_sample.cpp
index 68efa6f9ee..76d4248766 100644
--- a/openlr/openlr_sample.cpp
+++ b/openlr/openlr_sample.cpp
@@ -26,16 +26,28 @@ void ParseMWMSegments(std::string const & line, uint32_t const lineNumber,
uint32_t featureIndex;
if (!strings::to_uint(segParts[1], featureIndex))
- MYTHROW(openlr::SamplePoolLoadError, ("Can't parse MWMSegment", seg, "line:", lineNumber));
+ {
+ MYTHROW(openlr::SamplePoolLoadError, ("Can't parse feature index of MWMSegment: uint expected",
+ seg, "uint expected, got:", segParts[1],
+ "line:", lineNumber));
+ }
uint32_t segId;
if (!strings::to_uint(segParts[2], segId))
- MYTHROW(openlr::SamplePoolLoadError, ("Can't parse MWMSegment", seg, "line:", lineNumber));
+ {
+ MYTHROW(openlr::SamplePoolLoadError, ("Can't parse segment id of MWMSegment:",
+ seg, "uint expected, got:", segParts[2],
+ "line:", lineNumber));
+ }
bool const isForward = (segParts[3] == "fwd");
double length = 0;
if (!strings::to_double(segParts[4], length))
- MYTHROW(openlr::SamplePoolLoadError, ("Can't parse MWMSegment", seg, "line:", lineNumber));
+ {
+ MYTHROW(openlr::SamplePoolLoadError, ("Can't parse segment length of MWMSegment:",
+ seg, "double expected, got:", segParts[4],
+ "line:", lineNumber));
+ }
segments.push_back({FeatureID(mwmId, featureIndex), segId, isForward, length});
}
@@ -124,6 +136,12 @@ SamplePool LoadSamplePool(std::string const & fileName, Index const & index)
pool.push_back(item);
}
+ if (sample.fail() && !sample.eof())
+ MYTHROW(SamplePoolLoadError, ("Can't read from file", fileName, strerror(errno)));
+
+ if (pool.empty())
+ MYTHROW(SamplePoolLoadError, ("No sample is read,", fileName, "probably empty"));
+
return pool;
}
diff --git a/openlr/openlr_stat/openlr_stat.cpp b/openlr/openlr_stat/openlr_stat.cpp
index 3cfbe60e18..d8c6024d4c 100644
--- a/openlr/openlr_stat/openlr_stat.cpp
+++ b/openlr/openlr_stat/openlr_stat.cpp
@@ -9,12 +9,14 @@
#include "coding/file_name_utils.hpp"
-#include "std/cstdint.hpp"
-#include "std/cstdio.hpp"
-#include "std/vector.hpp"
-
#include "3party/gflags/src/gflags/gflags.h"
+#include <cstdint>
+#include <cstdio>
+#include <vector>
+
+#include <sys/stat.h>
+
DEFINE_string(input, "", "Path to OpenLR file.");
DEFINE_string(output, "output.txt", "Path to output file");
DEFINE_string(mwms_path, "", "Path to a folder with mwms.");
@@ -30,13 +32,24 @@ namespace
const int32_t kMinNumThreads = 1;
const int32_t kMaxNumThreads = 128;
-void LoadIndexes(string const & pathToMWMFolder, vector<Index> & indexes)
+bool IsDirectory(std::string const & path)
+{
+ struct ::stat st;
+ stat(path.data(), &st);
+ return S_ISDIR(st.st_mode);
+}
+
+void LoadIndexes(std::string const & pathToMWMFolder, std::vector<Index> & indexes)
{
+ CHECK(IsDirectory(pathToMWMFolder), (pathToMWMFolder, "must be a directory."));
+
Platform::FilesList files;
- Platform::GetFilesByRegExp(pathToMWMFolder, string(".*\\") + DATA_FILE_EXTENSION, files);
+ Platform::GetFilesByRegExp(pathToMWMFolder, std::string(".*\\") + DATA_FILE_EXTENSION, files);
+
+ CHECK(!files.empty(), (pathToMWMFolder, "Contains no .mwm files."));
size_t const numIndexes = indexes.size();
- vector<uint64_t> numCountries(numIndexes);
+ std::vector<uint64_t> numCountries(numIndexes);
for (auto const & fileName : files)
{
@@ -98,7 +111,7 @@ bool ValidateNumThreads(char const * flagname, int32_t value)
return true;
}
-bool ValidataMwmPath(char const * flagname, string const & value)
+bool ValidataMwmPath(char const * flagname, std::string const & value)
{
if (value.empty())
{
@@ -124,7 +137,7 @@ int main(int argc, char * argv[])
auto const numThreads = static_cast<uint32_t>(FLAGS_num_threads);
- vector<Index> indexes(numThreads);
+ std::vector<Index> indexes(numThreads);
LoadIndexes(FLAGS_mwms_path, indexes);
OpenLRSimpleDecoder::SegmentsFilter filter(FLAGS_ids_path, FLAGS_multipoints_only);