[platform] Got rid of std/*.hpp includes in platform.{c,h}pp.

This commit is contained in:
Maxim Pimenov 2018-03-16 20:15:43 +03:00 committed by Tatiana Yan
parent c259f9b241
commit 9f8a29bf59
2 changed files with 67 additions and 62 deletions

View file

@ -1,4 +1,5 @@
#include "platform/platform.hpp"
#include "platform/local_country_file.hpp"
#include "coding/base64.hpp"
@ -9,13 +10,16 @@
#include "base/logging.hpp"
#include "base/string_utils.hpp"
#include <thread>
#include "std/target_os.hpp"
#include "std/thread.hpp"
#include "private.h"
#include <errno.h>
using namespace std;
namespace
{
bool IsSpecialDirName(string const & dirName)

View file

@ -12,13 +12,11 @@
#include "base/task_loop.hpp"
#include "base/worker_thread.hpp"
#include "std/bitset.hpp"
#include "std/function.hpp"
#include "std/map.hpp"
#include "std/string.hpp"
#include "std/unique_ptr.hpp"
#include "std/utility.hpp"
#include "std/vector.hpp"
#include <cstdint>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "defines.hpp"
@ -89,27 +87,27 @@ public:
Gui
};
using TFilesWithType = vector<pair<string, EFileType>>;
using TFilesWithType = std::vector<std::pair<std::string, EFileType>>;
protected:
/// Usually read-only directory for application resources
string m_resourcesDir;
std::string m_resourcesDir;
/// Writable directory to store downloaded map data
/// @note on some systems it can point to external ejectable storage
string m_writableDir;
std::string m_writableDir;
/// Application private directory.
string m_privateDir;
std::string m_privateDir;
/// Temporary directory, can be cleaned up by the system
string m_tmpDir;
std::string m_tmpDir;
/// Writable directory to store persistent application data
string m_settingsDir;
std::string m_settingsDir;
/// Extended resource files.
/// Used in Android only (downloaded zip files as a container).
vector<string> m_extResFiles;
std::vector<std::string> m_extResFiles;
/// Default search scope for resource files.
/// Used in Android only and initialized according to the market type (Play, Amazon, Samsung).
string m_androidDefResScope;
std::string m_androidDefResScope;
/// Used in Android only to get corret GUI elements layout.
bool m_isTablet;
@ -123,105 +121,108 @@ protected:
/// Platform-dependent secure storage.
platform::SecureStorage m_secureStorage;
unique_ptr<base::TaskLoop> m_guiThread;
std::unique_ptr<base::TaskLoop> m_guiThread;
unique_ptr<base::WorkerThread> m_networkThread;
unique_ptr<base::WorkerThread> m_fileThread;
std::unique_ptr<base::WorkerThread> m_networkThread;
std::unique_ptr<base::WorkerThread> m_fileThread;
public:
Platform();
virtual ~Platform() = default;
static bool IsFileExistsByFullPath(string const & filePath);
static void DisableBackupForFile(string const & filePath);
static bool IsFileExistsByFullPath(std::string const & filePath);
static void DisableBackupForFile(std::string const & filePath);
/// @returns path to current working directory.
/// @note In case of an error returns an empty string.
static string GetCurrentWorkingDirectory() noexcept;
/// @note In case of an error returns an empty std::string.
static std::string GetCurrentWorkingDirectory() noexcept;
/// @return always the same writable dir for current user with slash at the end
string const & WritableDir() const { return m_writableDir; }
std::string const & WritableDir() const { return m_writableDir; }
/// Set writable dir — use for testing and linux stuff only
void SetWritableDirForTests(string const & path);
void SetWritableDirForTests(std::string const & path);
/// @return full path to file in user's writable directory
string WritablePathForFile(string const & file) const { return WritableDir() + file; }
std::string WritablePathForFile(std::string const & file) const { return WritableDir() + file; }
/// Uses m_writeableDir [w], m_resourcesDir [r], m_settingsDir [s].
string ReadPathForFile(string const & file, string searchScope = string()) const;
std::string ReadPathForFile(std::string const & file,
std::string searchScope = std::string()) const;
/// @return resource dir (on some platforms it's differ from Writable dir)
string const & ResourcesDir() const { return m_resourcesDir; }
std::string const & ResourcesDir() const { return m_resourcesDir; }
/// @note! This function is used in generator_tool and unit tests.
/// Client app should not replace default resource dir.
void SetResourceDir(string const & path);
void SetResourceDir(std::string const & path);
/// Creates the directory in the filesystem.
WARN_UNUSED_RESULT static EError MkDir(string const & dirName);
WARN_UNUSED_RESULT static EError MkDir(std::string const & dirName);
/// Creates the directory. Returns true on success.
/// Returns false and logs the reason on failure.
WARN_UNUSED_RESULT static bool MkDirChecked(string const & dirName);
WARN_UNUSED_RESULT static bool MkDirChecked(std::string const & dirName);
/// Removes empty directory from the filesystem.
static EError RmDir(string const & dirName);
static EError RmDir(std::string const & dirName);
/// Removes directory from the filesystem.
/// @note Directory can be non empty.
/// @note If function fails, directory can be partially removed.
static bool RmDirRecursively(string const & dirName);
static bool RmDirRecursively(std::string const & dirName);
/// @return path for directory with temporary files with slash at the end
string const & TmpDir() const { return m_tmpDir; }
std::string const & TmpDir() const { return m_tmpDir; }
/// @return full path to file in the temporary directory
string TmpPathForFile(string const & file) const { return TmpDir() + file; }
std::string TmpPathForFile(std::string const & file) const { return TmpDir() + file; }
/// @return full path to the file where data for unit tests is stored.
string TestsDataPathForFile(string const & file) const { return ReadPathForFile(file); }
std::string TestsDataPathForFile(std::string const & file) const { return ReadPathForFile(file); }
/// @return path for directory in the persistent memory, can be the same
/// as WritableDir, but on some platforms it's different
string const & SettingsDir() const { return m_settingsDir; }
void SetSettingsDir(string const & path);
std::string const & SettingsDir() const { return m_settingsDir; }
void SetSettingsDir(std::string const & path);
/// @return full path to file in the settings directory
string SettingsPathForFile(string const & file) const { return SettingsDir() + file; }
std::string SettingsPathForFile(std::string const & file) const { return SettingsDir() + file; }
/// Returns application private directory.
string const & PrivateDir() const { return m_privateDir; }
std::string const & PrivateDir() const { return m_privateDir; }
/// @return reader for file decriptor.
/// @throws FileAbsentException
/// @param[in] file name or full path which we want to read
/// @param[in] searchScope looks for file in dirs in given order: \n
/// [w]ritable, [r]esources, [s]ettings, by [f]ull path, [e]xternal resources,
unique_ptr<ModelReader>
GetReader(string const & file, string const & searchScope = string()) const;
std::unique_ptr<ModelReader> GetReader(std::string const & file,
std::string const & searchScope = std::string()) const;
/// @name File operations
//@{
typedef vector<string> FilesList;
using FilesList = std::vector<std::string>;
/// Retrieves files list contained in given directory
/// @param directory directory path with slash at the end
//@{
/// @param ext files extension to find, like ".mwm".
static void GetFilesByExt(string const & directory, string const & ext, FilesList & outFiles);
static void GetFilesByRegExp(string const & directory, string const & regexp, FilesList & outFiles);
static void GetFilesByExt(std::string const & directory, std::string const & ext,
FilesList & outFiles);
static void GetFilesByRegExp(std::string const & directory, std::string const & regexp,
FilesList & outFiles);
//@}
static void GetFilesByType(string const & directory, unsigned typeMask,
static void GetFilesByType(std::string const & directory, unsigned typeMask,
TFilesWithType & outFiles);
static void GetFilesRecursively(string const & directory, FilesList & filesList);
static void GetFilesRecursively(std::string const & directory, FilesList & filesList);
static bool IsDirectoryEmpty(string const & directory);
static bool IsDirectoryEmpty(std::string const & directory);
// Returns true if |path| refers to a directory. Returns false otherwise or on error.
static bool IsDirectory(string const & path);
static bool IsDirectory(std::string const & path);
static EError GetFileType(string const & path, EFileType & type);
static EError GetFileType(std::string const & path, EFileType & type);
/// @return false if file is not exist
/// @note Check files in Writable dir first, and in ReadDir if not exist in Writable dir
bool GetFileSizeByName(string const & fileName, uint64_t & size) const;
bool GetFileSizeByName(std::string const & fileName, uint64_t & size) const;
/// @return false if file is not exist
/// @note Try do not use in client production code
static bool GetFileSizeByFullPath(string const & filePath, uint64_t & size);
static bool GetFileSizeByFullPath(std::string const & filePath, uint64_t & size);
//@}
/// Used to check available free storage space for downloading.
@ -244,27 +245,27 @@ public:
int PreCachingDepth() const;
string DeviceName() const;
std::string DeviceName() const;
string DeviceModel() const;
std::string DeviceModel() const;
string UniqueClientId() const;
std::string UniqueClientId() const;
/// @return url for clients to download maps
//@{
string MetaServerUrl() const;
string ResourcesMetaServerUrl() const;
std::string MetaServerUrl() const;
std::string ResourcesMetaServerUrl() const;
//@}
/// @return JSON-encoded list of urls if metaserver is unreachable
string DefaultUrlsJSON() const;
std::string DefaultUrlsJSON() const;
bool IsTablet() const { return m_isTablet; }
/// @return information about kinds of memory which are relevant for a platform.
/// This method is implemented for iOS and Android only.
/// @TODO Add implementation
string GetMemoryInfo() const;
std::string GetMemoryInfo() const;
static EConnectionType ConnectionStatus();
static bool IsConnected() { return ConnectionStatus() != EConnectionType::CONNECTION_NONE; }
@ -313,7 +314,7 @@ public:
}
// Use this method for testing purposes only.
void SetGuiThread(unique_ptr<base::TaskLoop> guiThread);
void SetGuiThread(std::unique_ptr<base::TaskLoop> guiThread);
private:
void RunThreads();
@ -325,5 +326,5 @@ private:
void GetSystemFontNames(FilesList & res) const;
};
string DebugPrint(Platform::EError err);
string DebugPrint(Platform::ChargingStatus status);
std::string DebugPrint(Platform::EError err);
std::string DebugPrint(Platform::ChargingStatus status);