forked from organicmaps/organicmaps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscoped_file.hpp
60 lines (42 loc) · 1.43 KB
/
scoped_file.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#pragma once
#include "platform/country_defines.hpp"
#include "platform/platform.hpp"
#include "base/macros.hpp"
#include <string>
namespace platform
{
class CountryFile;
namespace tests_support
{
class ScopedDir;
class ScopedFile
{
public:
enum class Mode : uint32_t
{
// Create or overwrite the file and remove it at scope exit.
Create,
// Remove the file at scope exit. The caller must
// ensure that the file has been created by that time.
DoNotCreate
};
// Creates a scoped file in the specified mode.
ScopedFile(std::string const & relativePath, Mode mode);
// Creates a scoped file in Mode::Create and writes |contents| to it.
ScopedFile(std::string const & relativePath, std::string const & contents);
// Creates a scoped file in Mode::Create using the path inferred from |countryFile|
// and |mapOptions|.
ScopedFile(ScopedDir const & dir, CountryFile const & countryFile, MapFileType type);
~ScopedFile();
std::string const & GetFullPath() const { return m_fullPath; }
void Reset() { m_reset = true; }
bool Exists() const { return GetPlatform().IsFileExistsByFullPath(GetFullPath()); }
private:
ScopedFile(std::string const & relativePath, std::string const & contents, Mode mode);
std::string const m_fullPath;
bool m_reset = false;
DISALLOW_COPY_AND_MOVE(ScopedFile);
};
std::string DebugPrint(ScopedFile const & file);
} // namespace tests_support
} // namespace platform