diff options
author | Alex Zolotarev <deathbaba@gmail.com> | 2011-07-03 19:47:31 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:20:29 +0300 |
commit | adde2107d1effebd18358b60bc190c7bd4e5d75b (patch) | |
tree | c32e80f0f03c999ed3738e3331ae45b00a037ee5 /words | |
parent | 1f30f7f693ac1d66c3cfd66413f6bb78be256479 (diff) |
Removed Platform::ReadPathForFile
Diffstat (limited to 'words')
-rw-r--r-- | words/sloynik_engine.cpp | 22 | ||||
-rw-r--r-- | words/sloynik_engine.hpp | 4 | ||||
-rw-r--r-- | words/sloynik_index.cpp | 6 | ||||
-rw-r--r-- | words/sloynik_index.hpp | 2 | ||||
-rw-r--r-- | words/words_tests/words_tests.pro | 4 |
5 files changed, 25 insertions, 13 deletions
diff --git a/words/sloynik_engine.cpp b/words/sloynik_engine.cpp index 3c2c74fac3..379a65ba7f 100644 --- a/words/sloynik_engine.cpp +++ b/words/sloynik_engine.cpp @@ -1,16 +1,21 @@ #include "sloynik_engine.hpp" #include "slof_dictionary.hpp" #include "sloynik_index.hpp" + +#include "../platform/platform.hpp" + #include "../coding/file_reader.hpp" #include "../coding/file_writer.hpp" + #include "../base/logging.hpp" #include "../base/macros.hpp" -sl::SloynikEngine::SloynikEngine(string const & dictionaryPath, - string const & indexPath, +sl::SloynikEngine::SloynikEngine(string const & dictionary, + string const & index, StrFn const & strFn) { - FileReader * pDicFileReader = new FileReader(dictionaryPath); + Platform & pl = GetPlatform(); + Reader * pDicFileReader = pl.GetReader(dictionary); // m_pDictionary takes ownership of pDicFileReader. m_pDictionary.reset(new sl::SlofDictionary(pDicFileReader)); @@ -20,11 +25,11 @@ sl::SloynikEngine::SloynikEngine(string const & dictionaryPath, stamp.push_back(m_pDictionary->KeyCount()); stamp.push_back(pDicFileReader->Size()); - string const stampPath = indexPath + ".stamp"; + string const stampFile = index + ".stamp"; bool needIndexBuild = false; try { - FileReader stampReader(stampPath); + ReaderPtr<Reader> stampReader(pl.GetReader(stampFile)); if (stampReader.Size() != stamp.size() * sizeof(stamp[0])) needIndexBuild = true; else @@ -45,8 +50,9 @@ sl::SloynikEngine::SloynikEngine(string const & dictionaryPath, // Uncomment to always rebuild the index: needIndexBuild = true; if (needIndexBuild) { + string const stampPath = pl.WritablePathForFile(stampFile); FileWriter::DeleteFileX(stampPath); - sl::SortedIndex::Build(*m_pDictionary, strFn, indexPath); + sl::SortedIndex::Build(*m_pDictionary, strFn, index); FileWriter stampWriter(stampPath); stampWriter.Write(&stamp[0], stamp.size() * sizeof(stamp[0])); @@ -54,7 +60,9 @@ sl::SloynikEngine::SloynikEngine(string const & dictionaryPath, // By VNG: SortedIndex takes ownership of index reader, so no need to store it here. //m_pIndexReader.reset(new FileReader(indexPath + ".idx")); - m_pSortedIndex.reset(new sl::SortedIndex(*m_pDictionary, new FileReader(indexPath + ".idx"), strFn)); + m_pSortedIndex.reset(new sl::SortedIndex(*m_pDictionary, + new FileReader(pl.WritablePathForFile(index + ".idx")), + strFn)); } sl::SloynikEngine::~SloynikEngine() diff --git a/words/sloynik_engine.hpp b/words/sloynik_engine.hpp index 1c1bc6d288..c235890f8b 100644 --- a/words/sloynik_engine.hpp +++ b/words/sloynik_engine.hpp @@ -17,8 +17,8 @@ class SortedIndex; class SloynikEngine { public: - SloynikEngine(string const & dictionaryPath, - string const & indexPath, + SloynikEngine(string const & dictionary, + string const & index, sl::StrFn const & strFn); ~SloynikEngine(); diff --git a/words/sloynik_index.cpp b/words/sloynik_index.cpp index 332b65ae76..7fb9831e61 100644 --- a/words/sloynik_index.cpp +++ b/words/sloynik_index.cpp @@ -1,6 +1,8 @@ #include "sloynik_index.hpp" #include "dictionary.hpp" +#include "../platform/platform.hpp" + #include "../coding/file_writer.hpp" #include "../coding/timsort/timsort.hpp" @@ -189,7 +191,7 @@ sl::SortedIndex::Pos sl::SortedIndex::PrefixSearch(string const & prefix) void sl::SortedIndex::Build(sl::Dictionary const & dictionary, StrFn const & strFn, - string const & indexPathPrefix) + string const & indexPrefix) { LOG(LINFO, ("Building sorted index.")); @@ -214,7 +216,7 @@ void sl::SortedIndex::Build(sl::Dictionary const & dictionary, // stable_sort(ids.begin(), ids.end(), MakeLessRefProxy(compareLess)); } - FileWriter idxWriter((indexPathPrefix + ".idx").c_str()); + FileWriter idxWriter(GetPlatform().WritablePathForFile(indexPrefix + ".idx").c_str()); idxWriter.Write(&ids[0], ids.size() * sizeof(ids[0])); LOG(LINFO, ("Building sorted index done.")); diff --git a/words/sloynik_index.hpp b/words/sloynik_index.hpp index c6696a79a8..c549653f08 100644 --- a/words/sloynik_index.hpp +++ b/words/sloynik_index.hpp @@ -44,7 +44,7 @@ public: // Build index. static void Build(Dictionary const & dictionary, StrFn const & strFn, - string const & indexPathPrefix); + string const & indexPrefix); private: #pragma pack(push, 1) diff --git a/words/words_tests/words_tests.pro b/words/words_tests/words_tests.pro index 3056ec2749..98bf9fb670 100644 --- a/words/words_tests/words_tests.pro +++ b/words/words_tests/words_tests.pro @@ -4,10 +4,12 @@ CONFIG += console CONFIG -= app_bundle ROOT_DIR = ../.. -DEPENDENCIES = words coding base zlib bzip2 +DEPENDENCIES = platform words coding base zlib bzip2 include($$ROOT_DIR/common.pri) +QT += core + SOURCES += $$ROOT_DIR/testing/testingmain.cpp \ sorted_index_test.cpp \ |