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:
authorLev Dragunov <l.dragunov@corp.mail.ru>2015-03-06 15:16:43 +0300
committerAlex Zolotarev <alex@maps.me>2015-09-23 02:38:24 +0300
commit21d8c2650fcedb1e0babbb8fb6cbd8c2edc09082 (patch)
tree60021afc4e63c2480c78f26e806ad700562e288d
parentc30ae8eab34ab5de5e7684400f5e9032fa8f3736 (diff)
Mkdir platfom method
-rw-r--r--android/jni/com/mapswithme/platform/Platform.cpp9
-rw-r--r--indexer/features_offsets_table.cpp2
-rw-r--r--indexer/features_offsets_table.hpp4
-rw-r--r--indexer/indexer_tests/features_offsets_table_test.cpp8
-rw-r--r--platform/platform.cpp9
-rw-r--r--platform/platform.hpp3
-rw-r--r--platform/platform_android.cpp5
-rw-r--r--platform/platform_ios.mm9
-rw-r--r--platform/platform_linux.cpp9
-rw-r--r--platform/platform_mac.mm9
-rw-r--r--platform/platform_qt.cpp5
-rw-r--r--platform/platform_tizen.cpp8
-rw-r--r--platform/platform_win.cpp7
-rw-r--r--routing/osrm2feature_map.cpp27
-rw-r--r--routing/osrm2feature_map.hpp21
15 files changed, 59 insertions, 76 deletions
diff --git a/android/jni/com/mapswithme/platform/Platform.cpp b/android/jni/com/mapswithme/platform/Platform.cpp
index 7aaa4b8b6b..2117cdde8a 100644
--- a/android/jni/com/mapswithme/platform/Platform.cpp
+++ b/android/jni/com/mapswithme/platform/Platform.cpp
@@ -11,7 +11,6 @@
#include "../../../../../std/algorithm.hpp"
-#include <sys/stat.h>
string Platform::UniqueClientId() const
{
@@ -56,14 +55,6 @@ string Platform::UniqueClientId() const
return res;
}
-string Platform::WritablePathForFileIndexes(string const & country_name) const
-{
- string dir = WritableDir() + country_name + '/';
- if (!IsFileExistsByFullPath(dir))
- mkdir(dir.c_str(), 0755);
- return dir;
-}
-
void Platform::RunOnGuiThread(TFunctor const & fn)
{
android::Platform::RunOnGuiThreadImpl(fn);
diff --git a/indexer/features_offsets_table.cpp b/indexer/features_offsets_table.cpp
index 96eda2fbb8..0a934cb5e4 100644
--- a/indexer/features_offsets_table.cpp
+++ b/indexer/features_offsets_table.cpp
@@ -99,7 +99,6 @@ namespace feature
{
ASSERT_LESS_OR_EQUAL(offset, m_table.select(size() - 1), ("Offset out of bounds", offset,
m_table.select(size() - 1)));
-
//Binary search in elias_fano list
size_t first = 0, last = size();
size_t count = last - first, step, current;
@@ -116,7 +115,6 @@ namespace feature
count = step;
}
return current;
-
}
string FeaturesOffsetsTable::GetIndexFileName(string const & countryName)
diff --git a/indexer/features_offsets_table.hpp b/indexer/features_offsets_table.hpp
index eb0537c6ba..7d735a3ac9 100644
--- a/indexer/features_offsets_table.hpp
+++ b/indexer/features_offsets_table.hpp
@@ -102,8 +102,8 @@ namespace feature
return succinct::mapper::size_of(m_table);
}
- /// Delete temporary index file
- static void CleanIndexFiles(string const & countryName)
+ /// Delete temporary index file (only for features offsets table)
+ static void CleanIndexFile(string const & countryName)
{
FileWriter::DeleteFileX(GetIndexFileName(countryName));
}
diff --git a/indexer/indexer_tests/features_offsets_table_test.cpp b/indexer/indexer_tests/features_offsets_table_test.cpp
index 50e34e27a0..010d40e0c3 100644
--- a/indexer/indexer_tests/features_offsets_table_test.cpp
+++ b/indexer/indexer_tests/features_offsets_table_test.cpp
@@ -61,8 +61,9 @@ namespace feature
string const testFileName = "minsk-pass";
Platform & p = GetPlatform();
FilesContainerR baseContainer(p.GetReader(testFileName + DATA_FILE_EXTENSION));
- FeaturesOffsetsTable::CleanIndexFiles(testFileName);
+ FeaturesOffsetsTable::CleanIndexFile(testFileName);
unique_ptr<FeaturesOffsetsTable> table(FeaturesOffsetsTable::CreateIfNotExistsAndLoad(testFileName));
+ MY_SCOPE_GUARD(deleteTestFileIndexGuard, bind(&FeaturesOffsetsTable::CleanIndexFile, cref(testFileName)));
TEST(table.get(), ());
feature::DataHeader header;
@@ -101,6 +102,7 @@ namespace feature
string const testFile = p.WritablePathForFile(testFileName + DATA_FILE_EXTENSION);
MY_SCOPE_GUARD(deleteTestFileGuard, bind(&FileWriter::DeleteFileX, cref(testFile)));
+ MY_SCOPE_GUARD(deleteTestFileIndexGuard, bind(&FeaturesOffsetsTable::CleanIndexFile, cref(testFileName)));
// Store table in a temporary data file.
{
@@ -112,13 +114,13 @@ namespace feature
{
testContainer.Write(baseContainer.GetReader(tag), tag);
});
- table->Save("test_file");
+ table->Save(testFileName);
testContainer.Finish();
}
// Load table from the temporary data file.
{
- MY_SCOPE_GUARD(testTableGuard, [&testFileName](){FeaturesOffsetsTable::CleanIndexFiles(testFileName);});
+ MY_SCOPE_GUARD(testTableGuard, bind(&FeaturesOffsetsTable::CleanIndexFile, cref(testFileName)));
unique_ptr<FeaturesOffsetsTable> loadedTable(FeaturesOffsetsTable::Load(testFileName));
TEST(loadedTable.get(), ());
diff --git a/platform/platform.cpp b/platform/platform.cpp
index 40ba3db712..021fe99289 100644
--- a/platform/platform.cpp
+++ b/platform/platform.cpp
@@ -2,6 +2,7 @@
#include "../coding/sha2.hpp"
#include "../coding/base64.hpp"
+#include "../coding/file_name_utils.hpp"
#include "../base/logging.hpp"
@@ -93,3 +94,11 @@ string Platform::DeviceName() const
{
return OMIM_OS_NAME;
}
+
+string Platform::WritablePathForFileIndexes(string const & country_name) const
+{
+ string dir = WritableDir() + country_name + my::GetNativeSeparator();
+ if (!IsFileExistsByFullPath(dir))
+ MkDir(dir);
+ return dir;
+}
diff --git a/platform/platform.hpp b/platform/platform.hpp
index 6605e7b852..447886c671 100644
--- a/platform/platform.hpp
+++ b/platform/platform.hpp
@@ -66,6 +66,9 @@ public:
/// @return resource dir (on some platforms it's differ from Writable dir)
string ResourcesDir() const { return m_resourcesDir; }
+ /// Creates directory at filesystem
+ void MkDir(string const & directory_name) const;
+
/// @return path for directory with temporary files with slash at the end
string TmpDir() const { return m_tmpDir; }
/// @return full path to file in the temporary directory
diff --git a/platform/platform_android.cpp b/platform/platform_android.cpp
index 027ebfc7b2..a265d060ca 100644
--- a/platform/platform_android.cpp
+++ b/platform/platform_android.cpp
@@ -244,6 +244,11 @@ bool Platform::GetFileSizeByName(string const & fileName, uint64_t & size) const
}
}
+void Platform::MkDir(string const & directory_name) const
+{
+ mkdir(directory_name.c_str(), 0755);
+}
+
namespace
{
class SelfDeleteRoutine : public threads::IRoutine
diff --git a/platform/platform_ios.mm b/platform/platform_ios.mm
index 302013ab53..280212711a 100644
--- a/platform/platform_ios.mm
+++ b/platform/platform_ios.mm
@@ -3,7 +3,6 @@
#include "constants.hpp"
#include "../coding/file_reader.hpp"
-#include "../coding/file_name_utils.hpp"
#include <sys/types.h>
#include <sys/socket.h>
@@ -50,13 +49,9 @@ Platform::Platform()
[pool release];
}
-
-string Platform::WritablePathForFileIndexes(string const & country_name) const
+void Platform::MkDir(string const & directory_name) const
{
- string dir = m_writableDir + country_name.c_str() + '/';
- if (!IsFileExistsByFullPath(dir))
- ::mkdir(dir.c_str(), 0755);
- return dir;
+ ::mkdir(directory_name.c_str(), 0755);
}
void Platform::GetFilesByRegExp(string const & directory, string const & regexp, FilesList & res)
diff --git a/platform/platform_linux.cpp b/platform/platform_linux.cpp
index 52d054d4c8..f99bdb027f 100644
--- a/platform/platform_linux.cpp
+++ b/platform/platform_linux.cpp
@@ -2,7 +2,6 @@
#include "../base/logging.hpp"
#include "../coding/file_reader.hpp"
-#include "../coding/file_name_utils.hpp"
#include <stdlib.h>
#include <unistd.h>
@@ -91,14 +90,6 @@ Platform::Platform()
LOG(LDEBUG, ("Client ID:", UniqueClientId()));
}
-string Platform::WritablePathForFileIndexes(string const & country_name) const
-{
- string dir = WritableDir() + country_name + my::GetNativeSeparator();
- if (!IsFileExistsByFullPath(dir))
- mkdir(dir.c_str(), 0755);
- return dir;
-}
-
int Platform::CpuCores() const
{
const long numCPU = sysconf(_SC_NPROCESSORS_ONLN);
diff --git a/platform/platform_mac.mm b/platform/platform_mac.mm
index cd5eea67c7..fcbdc6d081 100644
--- a/platform/platform_mac.mm
+++ b/platform/platform_mac.mm
@@ -78,15 +78,6 @@ Platform::Platform()
[pool release];
}
-string Platform::WritablePathForFileIndexes(string const & country_name) const
-{
-
- string dir = m_writableDir + country_name.c_str() + '/';
- if (!IsFileExistsByFullPath(dir))
- ::mkdir(dir.c_str(), 0755);
- return dir;
-}
-
int Platform::CpuCores() const
{
int mib[2], numCPU = 0;
diff --git a/platform/platform_qt.cpp b/platform/platform_qt.cpp
index 24e73e6f76..9a82b2ee08 100644
--- a/platform/platform_qt.cpp
+++ b/platform/platform_qt.cpp
@@ -56,6 +56,11 @@ int Platform::VideoMemoryLimit() const
return 20 * 1024 * 1024;
}
+void Platform::MkDir(string const & directory_name) const
+{
+ QDir().mkdir(directory_name.c_str());
+}
+
extern Platform & GetPlatform()
{
diff --git a/platform/platform_tizen.cpp b/platform/platform_tizen.cpp
index 47a8f01b60..12d15da2fe 100644
--- a/platform/platform_tizen.cpp
+++ b/platform/platform_tizen.cpp
@@ -10,7 +10,6 @@
#include <sys/types.h>
#include "../coding/file_reader.hpp"
-#include "../coding/file_name_utils.hpp"
#include "../base/logging.hpp"
@@ -44,12 +43,9 @@ Platform::Platform()
m_flags[HAS_ROUTING] = true;
}
-string Platform::WritablePathForFileIndexes(string const & country_name) const
+void Platform::MkDir(string const & directory_name) const
{
- string dir = WritableDir() + country_name + my::GetNativeSeparator();
- if (!IsFileExistsByFullPath(dir))
- Tizen::Io::Directory::Create(dir.c_str(), true);
- return dir;
+ Tizen::Io::Directory::Create(directory_name.c_str(), true);
}
int Platform::CpuCores() const
diff --git a/platform/platform_win.cpp b/platform/platform_win.cpp
index ddddc4ebfa..271a5f1a07 100644
--- a/platform/platform_win.cpp
+++ b/platform/platform_win.cpp
@@ -4,7 +4,6 @@
#include "../base/logging.hpp"
#include "../coding/file_writer.hpp"
-#include "../coding/file_name_utils.hpp"
#include "../std/windows.hpp"
#include "../std/bind.hpp"
@@ -87,12 +86,6 @@ Platform::Platform()
LOG(LDEBUG, ("Settings Directory:", m_settingsDir));
}
-string Platform::WritablePathForFileIndexes(string const & country_name) const
-{
- string dir = WritableDir() + country_name + my::GetNativeSeparator();
- return dir;
-}
-
bool Platform::IsFileExistsByFullPath(string const & filePath)
{
return ::GetFileAttributesA(filePath.c_str()) != INVALID_FILE_ATTRIBUTES;
diff --git a/routing/osrm2feature_map.cpp b/routing/osrm2feature_map.cpp
index 865a6d4361..d65a4d9652 100644
--- a/routing/osrm2feature_map.cpp
+++ b/routing/osrm2feature_map.cpp
@@ -197,7 +197,7 @@ void OsrmFtSegMapping::GetOsrmNodes(FtSegSetT & segments, OsrmNodesT & res, vola
uint32_t nodeId = m_backwardIndex.GetNodeIdByFid(seg.m_fid);
auto range = GetSegmentsRange(nodeId);
- for (int i = range.first; i < range.second; ++i)
+ for (int i = range.first; i != range.second; ++i)
{
OsrmMappingTypes::FtSeg const s(m_segments[i]);
if (s.m_fid != seg.m_fid)
@@ -345,7 +345,7 @@ bool OsrmFtSegBackwardIndex::Load(string const & countryName)
string const nodesName = dir + countryName + FTSEG_MAPPING_BACKWARD_INDEX_NODES_EXT;
string const bitsName = dir + countryName + FTSEG_MAPPING_BACKWARD_INDEX_BITS_EXT;
uint64_t size;
- if (! GetPlatform().GetFileSizeByFullPath(nodesName, size) || ! GetPlatform().GetFileSizeByFullPath(bitsName, size))
+ if (!GetPlatform().GetFileSizeByFullPath(nodesName, size) || !GetPlatform().GetFileSizeByFullPath(bitsName, size))
return false;
m_pMappedNodes = unique_ptr<MmapReader>(new MmapReader(nodesName));
m_pMappedBits = unique_ptr<MmapReader>(new MmapReader(bitsName));
@@ -372,7 +372,7 @@ void OsrmFtSegBackwardIndex::Construct(const OsrmFtSegMapping & mapping, const u
for (uint32_t i = 0; i < maxNodeId; ++i)
{
auto indexes = mapping.GetSegmentsRange(i);
- for (size_t j = indexes.first; j < indexes.second; ++j)
+ for (size_t j = indexes.first; j != indexes.second; ++j)
{
OsrmMappingTypes::FtSeg seg;
mapping.GetSegmentByIndex(j, seg);
@@ -403,4 +403,25 @@ void OsrmFtSegBackwardIndex::Construct(const OsrmFtSegMapping & mapping, const u
Save(name);
}
+uint32_t OsrmFtSegBackwardIndex::GetNodeIdByFid(const uint32_t fid) const
+{
+ if (!m_table)
+ return INVALID_NODE_ID;
+ size_t const index = m_table->GetFeatureIndexbyOffset(fid);
+ if (index == m_table->size())
+ return INVALID_NODE_ID;
+ size_t node_index = m_rankIndex.rank(index);
+ ASSERT_LESS(node_index, m_nodeIds.size(), ());
+ return m_nodeIds[node_index];
+}
+
+void OsrmFtSegBackwardIndex::Clear()
+{
+ ClearContainer(m_nodeIds);
+ ClearContainer(m_rankIndex);
+ m_table = unique_ptr<feature::FeaturesOffsetsTable>();
+ m_pMappedBits = nullptr;
+ m_pMappedNodes = nullptr;
+}
+
}
diff --git a/routing/osrm2feature_map.hpp b/routing/osrm2feature_map.hpp
index 33c66a0a65..7343ff1af9 100644
--- a/routing/osrm2feature_map.hpp
+++ b/routing/osrm2feature_map.hpp
@@ -114,26 +114,9 @@ class OsrmFtSegBackwardIndex
public:
void Construct(OsrmFtSegMapping const & mapping, uint32_t const maxNodeId, FilesMappingContainer & routingFile);
- uint32_t GetNodeIdByFid(uint32_t const fid) const
- {
- if (!m_table)
- return INVALID_NODE_ID;
- size_t index = m_table->GetFeatureIndexbyOffset(fid);
- if (index == m_table->size())
- return INVALID_NODE_ID;
- size_t node_index = m_rankIndex.rank(index);
- ASSERT_LESS(node_index, m_nodeIds.size(), ());
- return m_nodeIds[node_index];
- }
+ uint32_t GetNodeIdByFid(uint32_t const fid) const;
- void Clear()
- {
- ClearContainer(m_nodeIds);
- ClearContainer(m_rankIndex);
- m_table = unique_ptr<feature::FeaturesOffsetsTable>();
- m_pMappedBits = nullptr;
- m_pMappedNodes = nullptr;
- }
+ void Clear();
};