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:
authorIlya Zverev <zverik@textual.ru>2016-07-15 18:01:19 +0300
committerIlya Zverev <zverik@textual.ru>2016-07-19 12:53:21 +0300
commit46a5d58ba1fe3b274df149214fe1bbc7bb97b6e1 (patch)
tree3d9baa51399d40e78102e3e1c7a6add4573c0059 /indexer
parent989c84e7bb93994a02ba482e83e8ec3a90ff91fa (diff)
[generator] Add region info section to mwms
Diffstat (limited to 'indexer')
-rw-r--r--indexer/data_factory.cpp11
-rw-r--r--indexer/data_factory.hpp4
-rw-r--r--indexer/feature_meta.cpp44
-rw-r--r--indexer/feature_meta.hpp39
-rw-r--r--indexer/index.cpp3
-rw-r--r--indexer/index.hpp1
-rw-r--r--indexer/indexer_tests/feature_metadata_test.cpp23
-rw-r--r--indexer/mwm_set.hpp6
8 files changed, 113 insertions, 18 deletions
diff --git a/indexer/data_factory.cpp b/indexer/data_factory.cpp
index 965f3f1edf..5f1edc82c0 100644
--- a/indexer/data_factory.cpp
+++ b/indexer/data_factory.cpp
@@ -1,7 +1,9 @@
-#include "coding/file_container.hpp"
#include "indexer/data_factory.hpp"
#include "indexer/interval_index.hpp"
#include "indexer/old/interval_index_101.hpp"
+
+#include "coding/file_container.hpp"
+
#include "defines.hpp"
@@ -10,8 +12,11 @@ void IndexFactory::Load(FilesContainerR const & cont)
ReadVersion(cont, m_version);
m_header.Load(cont);
- ReaderSource<FilesContainerR::TReader> src(cont.GetReader(REGION_INFO_FILE_TAG));
- m_region.Deserialize(src);
+ if (cont.IsExist(REGION_INFO_FILE_TAG))
+ {
+ ReaderSource<FilesContainerR::TReader> src(cont.GetReader(REGION_INFO_FILE_TAG));
+ m_regionData.Deserialize(src);
+ }
}
IntervalIndexIFace * IndexFactory::CreateIndex(ModelReaderPtr reader) const
diff --git a/indexer/data_factory.hpp b/indexer/data_factory.hpp
index 3bda00c867..251b1e2323 100644
--- a/indexer/data_factory.hpp
+++ b/indexer/data_factory.hpp
@@ -12,14 +12,14 @@ class IndexFactory
{
version::MwmVersion m_version;
feature::DataHeader m_header;
- feature::RegionData m_region;
+ feature::RegionData m_regionData;
public:
void Load(FilesContainerR const & cont);
inline version::MwmVersion const & GetMwmVersion() const { return m_version; }
inline feature::DataHeader const & GetHeader() const { return m_header; }
- inline feature::RegionData const & GetRegion() const { return m_region; }
+ inline feature::RegionData const & GetRegionData() const { return m_regionData; }
IntervalIndexIFace * CreateIndex(ModelReaderPtr reader) const;
};
diff --git a/indexer/feature_meta.cpp b/indexer/feature_meta.cpp
index 6e614d5cb3..73e9451b2d 100644
--- a/indexer/feature_meta.cpp
+++ b/indexer/feature_meta.cpp
@@ -99,6 +99,50 @@ bool Metadata::TypeFromString(string const & k, Metadata::EType & outType)
return true;
}
+
+void RegionData::SetLanguages(vector<string> const & codes)
+{
+ string value;
+ for (string const & code : codes)
+ {
+ int8_t const lang = StringUtf8Multilang::GetLangIndex(code);
+ if (lang != StringUtf8Multilang::kUnsupportedLanguageCode)
+ value.push_back(lang);
+ }
+ MetadataBase::Set(RegionData::Type::RD_LANGUAGES, value);
+}
+
+void RegionData::GetLanguages(vector<int8_t> & langs) const
+{
+ for (auto const lang : Get(RegionData::Type::RD_LANGUAGES))
+ langs.push_back(lang);
+}
+
+bool RegionData::HasLanguage(int8_t const lang) const
+{
+ for (auto const lng : Get(RegionData::Type::RD_LANGUAGES))
+ {
+ if (lng == lang)
+ return true;
+ }
+ return false;
+}
+
+bool RegionData::IsSingleLanguage(int8_t const lang) const
+{
+ string const value = Get(RegionData::Type::RD_LANGUAGES);
+ if (value.size() != 1)
+ return false;
+ return value.front() == lang;
+}
+
+void RegionData::AddPublicHoliday(int8_t month, int8_t offset)
+{
+ string value = Get(RegionData::Type::RD_PUBLIC_HOLIDAYS);
+ value.push_back(month);
+ value.push_back(offset);
+ Set(RegionData::Type::RD_PUBLIC_HOLIDAYS, value);
+}
} // namespace feature
// Warning: exact osm tag keys should be returned for valid enum values.
diff --git a/indexer/feature_meta.hpp b/indexer/feature_meta.hpp
index 5fccebc38b..85cede6dc5 100644
--- a/indexer/feature_meta.hpp
+++ b/indexer/feature_meta.hpp
@@ -132,13 +132,8 @@ public:
/// Used to normalize tags like "contact:phone" and "phone" to a common metadata enum value.
static bool TypeFromString(string const & osmTagKey, feature::Metadata::EType & outType);
- void Set(EType type, string const & value)
- {
- MetadataBase::Set(type, value);
- }
-
+ void Set(EType type, string const & value) { MetadataBase::Set(type, value); }
void Drop(EType type) { Set(type, string()); }
-
string GetWikiURL() const;
// TODO: Commented code below is now longer neded, but I leave it here
@@ -190,22 +185,40 @@ public:
class RegionData : public MetadataBase
{
public:
- enum Type
+ enum Type : int8_t
{
- RD_LANGUAGES, // list of written languages
- RD_DRIVING, // left- or right-hand driving (letter 'l' or 'r')
- RD_TIMEZONE, // UTC timezone offset, floating signed number of hours: -3, 4.5
- RD_ADDRESS_FORMAT, // address format, re: mapzen
- RD_PHONE_FORMAT, // list of strings in "+N NNN NN-NN-NN" format
+ RD_LANGUAGES, // list of written languages
+ RD_DRIVING, // left- or right-hand driving (letter 'l' or 'r')
+ RD_TIMEZONE, // UTC timezone offset, floating signed number of hours: -3, 4.5
+ RD_ADDRESS_FORMAT, // address format, re: mapzen
+ RD_PHONE_FORMAT, // list of strings in "+N NNN NN-NN-NN" format
RD_POSTCODE_FORMAT, // list of strings in "AAA ANN" format
RD_PUBLIC_HOLIDAYS, // fixed PH dates
RD_ALLOW_HOUSENAMES // 'y' if housenames are commonly used
};
- void Add(Type type, string const & s)
+ // Special values for month references in public holiday definitions.
+ enum PHReference : int8_t
{
+ PH_EASTER = 20,
+ PH_ORTHODOX_EASTER = 21,
+ PH_VICTORIA_DAY = 22,
+ PH_CANADA_DAY = 23
+ };
+
+ void Set(Type type, string const & s)
+ {
+ CHECK_NOT_EQUAL(type, Type::RD_LANGUAGES, ("Please use RegionData::SetLanguages method"));
MetadataBase::Set(type, s);
}
+
+ void SetLanguages(vector<string> const & codes);
+ void GetLanguages(vector<int8_t> & langs) const;
+ bool HasLanguage(int8_t const lang) const;
+ bool IsSingleLanguage(int8_t const lang) const;
+
+ void AddPublicHoliday(int8_t month, int8_t offset);
+ // No public holidays getters until we know what to do with these.
};
} // namespace feature
diff --git a/indexer/index.cpp b/indexer/index.cpp
index 6caaa521f7..6811333464 100644
--- a/indexer/index.cpp
+++ b/indexer/index.cpp
@@ -58,6 +58,9 @@ unique_ptr<MwmInfo> Index::CreateInfo(platform::LocalCountryFile const & localFi
info->m_minScale = static_cast<uint8_t>(scaleR.first);
info->m_maxScale = static_cast<uint8_t>(scaleR.second);
info->m_version = value.GetMwmVersion();
+ // Copying to drop the const qualifier.
+ feature::RegionData regionData(value.GetRegionData());
+ info->m_data = regionData;
return unique_ptr<MwmInfo>(move(info));
}
diff --git a/indexer/index.hpp b/indexer/index.hpp
index 6979d7af10..91351a9c6f 100644
--- a/indexer/index.hpp
+++ b/indexer/index.hpp
@@ -51,6 +51,7 @@ public:
void SetTable(MwmInfoEx & info);
inline feature::DataHeader const & GetHeader() const { return m_factory.GetHeader(); }
+ inline feature::RegionData const & GetRegionData() const { return m_factory.GetRegionData(); }
inline version::MwmVersion const & GetMwmVersion() const { return m_factory.GetMwmVersion(); }
inline string const & GetCountryFileName() const { return m_file.GetCountryFile().GetName(); }
};
diff --git a/indexer/indexer_tests/feature_metadata_test.cpp b/indexer/indexer_tests/feature_metadata_test.cpp
index 1a1771c634..1f88dc780c 100644
--- a/indexer/indexer_tests/feature_metadata_test.cpp
+++ b/indexer/indexer_tests/feature_metadata_test.cpp
@@ -100,3 +100,26 @@ UNIT_TEST(Feature_Metadata_GetWikipedia)
TEST_EQUAL(m.GetWikiURL(), "https://en.wikipedia.org/wiki/Article", ());
#endif
}
+
+UNIT_TEST(Feature_Metadata_RegionData_Languages)
+{
+ {
+ feature::RegionData rd;
+ vector<string> const langs = {"ru", "en", "et"};
+ rd.SetLanguages(langs);
+ TEST(rd.HasLanguage(StringUtf8Multilang::GetLangIndex("ru")), ());
+ TEST(rd.HasLanguage(StringUtf8Multilang::GetLangIndex("en")), ());
+ TEST(rd.HasLanguage(StringUtf8Multilang::GetLangIndex("et")), ());
+ TEST(!rd.HasLanguage(StringUtf8Multilang::GetLangIndex("es")), ());
+ TEST(!rd.IsSingleLanguage(StringUtf8Multilang::GetLangIndex("ru")), ());
+ }
+ {
+ feature::RegionData rd;
+ vector<string> const langs = {"et"};
+ rd.SetLanguages(langs);
+ TEST(rd.HasLanguage(StringUtf8Multilang::GetLangIndex("et")), ());
+ TEST(rd.IsSingleLanguage(StringUtf8Multilang::GetLangIndex("et")), ());
+ TEST(!rd.HasLanguage(StringUtf8Multilang::GetLangIndex("en")), ());
+ TEST(!rd.IsSingleLanguage(StringUtf8Multilang::GetLangIndex("en")), ());
+ }
+}
diff --git a/indexer/mwm_set.hpp b/indexer/mwm_set.hpp
index c924f5dd97..9a334316e2 100644
--- a/indexer/mwm_set.hpp
+++ b/indexer/mwm_set.hpp
@@ -8,6 +8,8 @@
#include "base/macros.hpp"
+#include "indexer/feature_meta.hpp"
+
#include "std/atomic.hpp"
#include "std/deque.hpp"
#include "std/map.hpp"
@@ -66,6 +68,8 @@ public:
MwmTypeT GetType() const;
+ inline feature::RegionData const & GetRegionData() const { return m_data; }
+
/// Returns the lock counter value for test needs.
uint8_t GetNumRefs() const { return m_numRefs; }
@@ -77,6 +81,8 @@ protected:
return result;
}
+ feature::RegionData m_data;
+
platform::LocalCountryFile m_file; ///< Path to the mwm file.
atomic<Status> m_status; ///< Current country status.
uint32_t m_numRefs; ///< Number of active handles.