diff --git a/indexer/categories_holder.hpp b/indexer/categories_holder.hpp index b6717020ad..feaad857d5 100644 --- a/indexer/categories_holder.hpp +++ b/indexer/categories_holder.hpp @@ -44,10 +44,7 @@ private: Name2CatContT m_name2type; public: - CategoriesHolder() {} - /// Takes ownership of reader. explicit CategoriesHolder(Reader * reader); - void LoadFromStream(istream & s); template @@ -104,3 +101,6 @@ inline void swap(CategoriesHolder & a, CategoriesHolder & b) { return a.Swap(b); } + +// Defined in categories_holder_loader.cpp. +CategoriesHolder const & GetDefaultCategories(); diff --git a/indexer/categories_holder_loader.cpp b/indexer/categories_holder_loader.cpp new file mode 100644 index 0000000000..4210ea020c --- /dev/null +++ b/indexer/categories_holder_loader.cpp @@ -0,0 +1,11 @@ +#include "categories_holder.hpp" + +#include "platform/platform.hpp" + +#include "defines.hpp" + +CategoriesHolder const & GetDefaultCategories() +{ + static CategoriesHolder const instance(GetPlatform().GetReader(SEARCH_CATEGORIES_FILE_NAME)); + return instance; +} diff --git a/indexer/indexer.pro b/indexer/indexer.pro index ab1f530271..ee648a277d 100644 --- a/indexer/indexer.pro +++ b/indexer/indexer.pro @@ -11,6 +11,7 @@ include($$ROOT_DIR/common.pri) SOURCES += \ categories_holder.cpp \ + categories_holder_loader.cpp \ classificator.cpp \ classificator_loader.cpp \ coding_params.cpp \ diff --git a/indexer/indexer_tests/categories_test.cpp b/indexer/indexer_tests/categories_test.cpp index 77d36a9153..8174bbdaf8 100644 --- a/indexer/indexer_tests/categories_test.cpp +++ b/indexer/indexer_tests/categories_test.cpp @@ -5,6 +5,7 @@ #include "indexer/classificator_loader.hpp" #include "coding/multilang_utf8_string.hpp" +#include "coding/reader.hpp" #include "std/sstream.hpp" @@ -86,10 +87,7 @@ UNIT_TEST(LoadCategories) { classificator::Load(); - CategoriesHolder h; - istringstream buffer(TEST_STRING); - h.LoadFromStream(buffer); - + CategoriesHolder h(new MemReader(TEST_STRING, strlen(TEST_STRING))); size_t count = 0; Checker f(count); h.ForEachCategory(f); diff --git a/map/framework.cpp b/map/framework.cpp index 930af0c2e5..652b90af5f 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -1116,12 +1116,10 @@ void Framework::InitSearchEngine() { ASSERT(!m_searchEngine.get(), ("InitSearchEngine() must be called only once.")); ASSERT(m_infoGetter.get(), ()); - Platform const & platform = GetPlatform(); - try { m_searchEngine.reset(new search::Engine( - const_cast(m_model.GetIndex()), platform.GetReader(SEARCH_CATEGORIES_FILE_NAME), + const_cast(m_model.GetIndex()), GetDefaultCategories(), *m_infoGetter, languages::GetCurrentOrig(), make_unique())); } catch (RootException const & e) diff --git a/search/search_engine.cpp b/search/search_engine.cpp index 0a243a544b..7267125a40 100644 --- a/search/search_engine.cpp +++ b/search/search_engine.cpp @@ -112,9 +112,9 @@ void QueryHandle::Detach() m_query = nullptr; } -Engine::Engine(Index & index, Reader * categoriesR, storage::CountryInfoGetter const & infoGetter, +Engine::Engine(Index & index, CategoriesHolder const & categories, storage::CountryInfoGetter const & infoGetter, string const & locale, unique_ptr && factory) - : m_categories(categoriesR), m_factory(move(factory)), m_shutdown(false) + : m_categories(categories), m_factory(move(factory)), m_shutdown(false) { InitSuggestions doInit; m_categories.ForEachName(bind(ref(doInit), _1)); diff --git a/search/search_engine.hpp b/search/search_engine.hpp index 26e2c6c413..d505204fec 100644 --- a/search/search_engine.hpp +++ b/search/search_engine.hpp @@ -78,7 +78,7 @@ class Engine { public: // Doesn't take ownership of index. Takes ownership of categoriesR. - Engine(Index & index, Reader * categoriesR, storage::CountryInfoGetter const & infoGetter, + Engine(Index & index, CategoriesHolder const & categories, storage::CountryInfoGetter const & infoGetter, string const & locale, unique_ptr && factory); ~Engine(); @@ -112,7 +112,7 @@ private: void DoClearCaches(); - CategoriesHolder m_categories; + CategoriesHolder const & m_categories; vector m_suggests; unique_ptr m_query; diff --git a/search/search_tests_support/test_search_engine.cpp b/search/search_tests_support/test_search_engine.cpp index 725b0da7d1..f4a9fecc82 100644 --- a/search/search_tests_support/test_search_engine.cpp +++ b/search/search_tests_support/test_search_engine.cpp @@ -54,7 +54,7 @@ TestSearchEngine::TestSearchEngine(string const & locale) : m_platform(GetPlatform()) , m_infoGetter(new storage::CountryInfoReader(m_platform.GetReader(PACKED_POLYGONS_FILE), m_platform.GetReader(COUNTRIES_FILE))) - , m_engine(*this, m_platform.GetReader(SEARCH_CATEGORIES_FILE_NAME), *m_infoGetter, locale, + , m_engine(*this, GetDefaultCategories(), *m_infoGetter, locale, make_unique()) { } @@ -63,7 +63,7 @@ TestSearchEngine::TestSearchEngine(string const & locale, unique_ptr infoGetter) : m_platform(GetPlatform()) , m_infoGetter(move(infoGetter)) - , m_engine(*this, m_platform.GetReader(SEARCH_CATEGORIES_FILE_NAME), *m_infoGetter, locale, + , m_engine(*this, GetDefaultCategories(), *m_infoGetter, locale, make_unique()) { } @@ -73,7 +73,7 @@ TestSearchEngine::TestSearchEngine(string const & locale, unique_ptr<::search::SearchQueryFactory> factory) : m_platform(GetPlatform()) , m_infoGetter(move(infoGetter)) - , m_engine(*this, m_platform.GetReader(SEARCH_CATEGORIES_FILE_NAME), *m_infoGetter, locale, + , m_engine(*this, GetDefaultCategories(), *m_infoGetter, locale, move(factory)) { } @@ -83,7 +83,7 @@ TestSearchEngine::TestSearchEngine(string const & locale, : m_platform(GetPlatform()) , m_infoGetter(new storage::CountryInfoReader(m_platform.GetReader(PACKED_POLYGONS_FILE), m_platform.GetReader(COUNTRIES_FILE))) - , m_engine(*this, m_platform.GetReader(SEARCH_CATEGORIES_FILE_NAME), *m_infoGetter, locale, + , m_engine(*this, GetDefaultCategories(), *m_infoGetter, locale, move(factory)) { }