summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2014-06-19 23:00:35 (GMT)
committerNico Weber <nicolasweber@gmx.de>2014-06-19 23:00:35 (GMT)
commite88a8daa10bb27a0617c74f3bc6eec66823f3a99 (patch)
treeaa93589817d8552164f5a00edc89705b64b45745
parentfcca327e0c66dfec49af28f09f94b94ac49c5cb4 (diff)
downloadNinja-e88a8daa10bb27a0617c74f3bc6eec66823f3a99.zip
Ninja-e88a8daa10bb27a0617c74f3bc6eec66823f3a99.tar.gz
Ninja-e88a8daa10bb27a0617c74f3bc6eec66823f3a99.tar.bz2
make Stat() a const method
-rw-r--r--src/disk_interface.cc2
-rw-r--r--src/disk_interface.h6
-rw-r--r--src/disk_interface_test.cc8
-rw-r--r--src/test.cc4
-rw-r--r--src/test.h2
5 files changed, 11 insertions, 11 deletions
diff --git a/src/disk_interface.cc b/src/disk_interface.cc
index c329aa3..ae2146e 100644
--- a/src/disk_interface.cc
+++ b/src/disk_interface.cc
@@ -152,7 +152,7 @@ bool DiskInterface::MakeDirs(const string& path) {
// RealDiskInterface -----------------------------------------------------------
-TimeStamp RealDiskInterface::Stat(const string& path) {
+TimeStamp RealDiskInterface::Stat(const string& path) const {
#ifdef _WIN32
// MSDN: "Naming Files, Paths, and Namespaces"
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx
diff --git a/src/disk_interface.h b/src/disk_interface.h
index b152a62..a13bced 100644
--- a/src/disk_interface.h
+++ b/src/disk_interface.h
@@ -30,7 +30,7 @@ struct DiskInterface {
/// stat() a file, returning the mtime, or 0 if missing and -1 on
/// other errors.
- virtual TimeStamp Stat(const string& path) = 0;
+ virtual TimeStamp Stat(const string& path) const = 0;
/// Create a directory, returning false on failure.
virtual bool MakeDir(const string& path) = 0;
@@ -62,7 +62,7 @@ struct RealDiskInterface : public DiskInterface {
#endif
{}
virtual ~RealDiskInterface() {}
- virtual TimeStamp Stat(const string& path);
+ virtual TimeStamp Stat(const string& path) const;
virtual bool MakeDir(const string& path);
virtual bool WriteFile(const string& path, const string& contents);
virtual string ReadFile(const string& path, string* err);
@@ -83,7 +83,7 @@ struct RealDiskInterface : public DiskInterface {
// TODO: Neither a map nor a hashmap seems ideal here. If the statcache
// works out, come up with a better data structure.
typedef map<string, DirCache> Cache;
- Cache cache_;
+ mutable Cache cache_;
#endif
};
diff --git a/src/disk_interface_test.cc b/src/disk_interface_test.cc
index 69fd1ab..f4e0bb0 100644
--- a/src/disk_interface_test.cc
+++ b/src/disk_interface_test.cc
@@ -147,7 +147,7 @@ struct StatTest : public StateTestWithBuiltinRules,
StatTest() : scan_(&state_, NULL, NULL, this) {}
// DiskInterface implementation.
- virtual TimeStamp Stat(const string& path);
+ virtual TimeStamp Stat(const string& path) const;
virtual bool WriteFile(const string& path, const string& contents) {
assert(false);
return true;
@@ -167,12 +167,12 @@ struct StatTest : public StateTestWithBuiltinRules,
DependencyScan scan_;
map<string, TimeStamp> mtimes_;
- vector<string> stats_;
+ mutable vector<string> stats_;
};
-TimeStamp StatTest::Stat(const string& path) {
+TimeStamp StatTest::Stat(const string& path) const {
stats_.push_back(path);
- map<string, TimeStamp>::iterator i = mtimes_.find(path);
+ map<string, TimeStamp>::const_iterator i = mtimes_.find(path);
if (i == mtimes_.end())
return 0; // File not found.
return i->second;
diff --git a/src/test.cc b/src/test.cc
index 45a9226..21015ed 100644
--- a/src/test.cc
+++ b/src/test.cc
@@ -105,8 +105,8 @@ void VirtualFileSystem::Create(const string& path,
files_created_.insert(path);
}
-TimeStamp VirtualFileSystem::Stat(const string& path) {
- FileMap::iterator i = files_.find(path);
+TimeStamp VirtualFileSystem::Stat(const string& path) const {
+ FileMap::const_iterator i = files_.find(path);
if (i != files_.end())
return i->second.mtime;
return 0;
diff --git a/src/test.h b/src/test.h
index 9f29e07..f34b877 100644
--- a/src/test.h
+++ b/src/test.h
@@ -59,7 +59,7 @@ struct VirtualFileSystem : public DiskInterface {
}
// DiskInterface
- virtual TimeStamp Stat(const string& path);
+ virtual TimeStamp Stat(const string& path) const;
virtual bool WriteFile(const string& path, const string& contents);
virtual bool MakeDir(const string& path);
virtual string ReadFile(const string& path, string* err);