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:
authorvng <viktor.govako@gmail.com>2013-12-03 17:24:08 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 02:08:08 +0300
commit55d0f1c27fc406da2acc2e041c6f651139e4a0e4 (patch)
treef416350050f3b1ffc9d08b242809b7f41adaa64f
parentea31feaa16e09b1e05938128292c9a9f0a2668e7 (diff)
Show more diagnostics in case of invalid categories.txt file.
-rw-r--r--indexer/categories_holder.cpp14
-rw-r--r--indexer/classificator.cpp12
-rw-r--r--indexer/classificator.hpp7
3 files changed, 27 insertions, 6 deletions
diff --git a/indexer/categories_holder.cpp b/indexer/categories_holder.cpp
index 5714359ba2..d22ec2ddc4 100644
--- a/indexer/categories_holder.cpp
+++ b/indexer/categories_holder.cpp
@@ -70,8 +70,10 @@ void CategoriesHolder::LoadFromStream(istream & s)
Classificator const & c = classif();
+ int lineNumber = 0;
while (s.good())
{
+ ++lineNumber;
getline(s, line);
strings::SimpleTokenizer iter(line, ":|");
@@ -88,7 +90,12 @@ void CategoriesHolder::LoadFromStream(istream & s)
strings::Tokenize(*iter, "-", MakeBackInsertFunctor(v));
// get classificator type
- types.push_back(c.GetTypeByPath(v));
+ uint32_t const type = c.GetTypeByPathSafe(v);
+ if (type != 0)
+ types.push_back(type);
+ else
+ LOG(LWARNING, ("Invalid type:", v, "at line:", lineNumber));
+
++iter;
}
@@ -104,10 +111,11 @@ void CategoriesHolder::LoadFromStream(istream & s)
state = EParseTypes;
continue;
}
+
int8_t const langCode = StringUtf8Multilang::GetLangIndex(*iter);
if (langCode == StringUtf8Multilang::UNSUPPORTED_LANGUAGE_CODE)
{
- LOG(LWARNING, ("Invalid language code:", *iter));
+ LOG(LWARNING, ("Invalid language code:", *iter, "at line:", lineNumber));
continue;
}
@@ -119,7 +127,7 @@ void CategoriesHolder::LoadFromStream(istream & s)
if (name.m_name.empty())
{
- LOG(LWARNING, ("Empty category name"));
+ LOG(LWARNING, ("Empty category name at line:", lineNumber));
continue;
}
diff --git a/indexer/classificator.cpp b/indexer/classificator.cpp
index 01efd1174c..0e1288c9b6 100644
--- a/indexer/classificator.cpp
+++ b/indexer/classificator.cpp
@@ -363,7 +363,7 @@ void Classificator::SortClassificator()
GetMutableRoot()->Sort();
}
-uint32_t Classificator::GetTypeByPath(vector<string> const & path) const
+uint32_t Classificator::GetTypeByPathSafe(vector<string> const & path) const
{
ClassifObject const * p = GetRoot();
@@ -373,7 +373,8 @@ uint32_t Classificator::GetTypeByPath(vector<string> const & path) const
while (i < path.size())
{
ClassifObjectPtr ptr = p->BinaryFind(path[i]);
- ASSERT ( ptr, ("Invalid path in Classificator::GetTypeByPath", path) );
+ if (!ptr)
+ return 0;
ftype::PushValue(type, ptr.GetIndex());
@@ -384,6 +385,13 @@ uint32_t Classificator::GetTypeByPath(vector<string> const & path) const
return type;
}
+uint32_t Classificator::GetTypeByPath(vector<string> const & path) const
+{
+ uint32_t const type = GetTypeByPathSafe(path);
+ ASSERT_NOT_EQUAL(type, 0, (path));
+ return type;
+}
+
void Classificator::ReadTypesMapping(istream & s)
{
m_mapping.Load(s);
diff --git a/indexer/classificator.hpp b/indexer/classificator.hpp
index 1e36c7ee06..b30a1f3607 100644
--- a/indexer/classificator.hpp
+++ b/indexer/classificator.hpp
@@ -181,9 +181,14 @@ public:
void Clear();
- /// Return type by path in classificator tree, example:
+ /// Return type by path in classificator tree, for example
/// path = ["natural", "caostline"].
+ //@{
+ /// @return 0 in case of nonexisting type
+ uint32_t GetTypeByPathSafe(vector<string> const & path) const;
+ /// Shows ASSERT in case of nonexisting type
uint32_t GetTypeByPath(vector<string> const & path) const;
+ //@}
uint32_t GetIndexForType(uint32_t t) const { return m_mapping.GetIndex(t); }
uint32_t GetTypeForIndex(uint32_t i) const { return m_mapping.GetType(i); }