summaryrefslogtreecommitdiffstats
path: root/Source/cmFileTimeComparison.cxx
diff options
context:
space:
mode:
authorKitware Robot <kwrobot@kitware.com>2016-05-16 14:34:04 (GMT)
committerBrad King <brad.king@kitware.com>2016-05-16 20:05:19 (GMT)
commitd9fd2f5402eeaa345691313658e02b51038f570b (patch)
treedca71b9a7e267f4c6300da3eb770415381726785 /Source/cmFileTimeComparison.cxx
parent82df6deaafb36cbbfd450202bb20b320f637751a (diff)
downloadCMake-d9fd2f5402eeaa345691313658e02b51038f570b.zip
CMake-d9fd2f5402eeaa345691313658e02b51038f570b.tar.gz
CMake-d9fd2f5402eeaa345691313658e02b51038f570b.tar.bz2
Revise C++ coding style using clang-format
Run the `Utilities/Scripts/clang-format.bash` script to update all our C++ code to a new style defined by `.clang-format`. Use `clang-format` version 3.8. * If you reached this commit for a line in `git blame`, re-run the blame operation starting at the parent of this commit to see older history for the content. * See the parent commit for instructions to rebase a change across this style transition commit.
Diffstat (limited to 'Source/cmFileTimeComparison.cxx')
-rw-r--r--Source/cmFileTimeComparison.cxx179
1 files changed, 64 insertions, 115 deletions
diff --git a/Source/cmFileTimeComparison.cxx b/Source/cmFileTimeComparison.cxx
index 88b5d99..7efe194 100644
--- a/Source/cmFileTimeComparison.cxx
+++ b/Source/cmFileTimeComparison.cxx
@@ -16,7 +16,7 @@
#ifdef CMake_HAVE_CXX11_UNORDERED_MAP
#include <unordered_map>
#else
-# include <cmsys/hash_map.hxx>
+#include <cmsys/hash_map.hxx>
#endif
#endif
@@ -24,12 +24,12 @@
// Use a platform-specific API to get file times efficiently.
#if !defined(_WIN32) || defined(__CYGWIN__)
-# define cmFileTimeComparison_Type struct stat
-# include <ctype.h>
-# include <sys/stat.h>
+#define cmFileTimeComparison_Type struct stat
+#include <ctype.h>
+#include <sys/stat.h>
#else
-# define cmFileTimeComparison_Type FILETIME
-# include <windows.h>
+#define cmFileTimeComparison_Type FILETIME
+#include <windows.h>
#endif
class cmFileTimeComparisonInternal
@@ -44,24 +44,22 @@ private:
#if defined(CMAKE_BUILD_WITH_CMAKE)
// Use a hash table to efficiently map from file name to modification time.
class HashString
- {
+ {
public:
- size_t operator()(const std::string& s) const
- {
- return h(s.c_str());
- }
+ size_t operator()(const std::string& s) const { return h(s.c_str()); }
#ifdef CMake_HAVE_CXX11_UNORDERED_MAP
std::hash<const char*> h;
#else
cmsys::hash<const char*> h;
#endif
- };
+ };
#ifdef CMake_HAVE_CXX11_UNORDERED_MAP
typedef std::unordered_map<std::string,
#else
typedef cmsys::hash_map<std::string,
#endif
- cmFileTimeComparison_Type, HashString> FileStatsMap;
+ cmFileTimeComparison_Type, HashString>
+ FileStatsMap;
FileStatsMap Files;
#endif
@@ -80,29 +78,26 @@ bool cmFileTimeComparisonInternal::Stat(const char* fname,
// Use the stored time if available.
cmFileTimeComparisonInternal::FileStatsMap::iterator fit =
this->Files.find(fname);
- if ( fit != this->Files.end() )
- {
+ if (fit != this->Files.end()) {
*st = fit->second;
return true;
- }
+ }
#endif
#if !defined(_WIN32) || defined(__CYGWIN__)
// POSIX version. Use the stat function.
int res = ::stat(fname, st);
- if ( res != 0 )
- {
+ if (res != 0) {
return false;
- }
+ }
#else
// Windows version. Get the modification time from extended file
// attributes.
WIN32_FILE_ATTRIBUTE_DATA fdata;
- if(!GetFileAttributesExW(cmsys::Encoding::ToWide(fname).c_str(),
- GetFileExInfoStandard, &fdata))
- {
+ if (!GetFileAttributesExW(cmsys::Encoding::ToWide(fname).c_str(),
+ GetFileExInfoStandard, &fdata)) {
return false;
- }
+ }
// Copy the file time to the output location.
*st = fdata.ftLastWriteTime;
@@ -126,8 +121,8 @@ cmFileTimeComparison::~cmFileTimeComparison()
delete this->Internals;
}
-bool cmFileTimeComparison::FileTimeCompare(const char* f1,
- const char* f2, int* result)
+bool cmFileTimeComparison::FileTimeCompare(const char* f1, const char* f2,
+ int* result)
{
return this->Internals->FileTimeCompare(f1, f2, result);
}
@@ -141,53 +136,36 @@ int cmFileTimeComparisonInternal::Compare(cmFileTimeComparison_Type* s1,
cmFileTimeComparison_Type* s2)
{
#if !defined(_WIN32) || defined(__CYGWIN__)
-# if CMake_STAT_HAS_ST_MTIM
+#if CMake_STAT_HAS_ST_MTIM
// Compare using nanosecond resolution.
- if(s1->st_mtim.tv_sec < s2->st_mtim.tv_sec)
- {
+ if (s1->st_mtim.tv_sec < s2->st_mtim.tv_sec) {
return -1;
- }
- else if(s1->st_mtim.tv_sec > s2->st_mtim.tv_sec)
- {
+ } else if (s1->st_mtim.tv_sec > s2->st_mtim.tv_sec) {
return 1;
- }
- else if(s1->st_mtim.tv_nsec < s2->st_mtim.tv_nsec)
- {
+ } else if (s1->st_mtim.tv_nsec < s2->st_mtim.tv_nsec) {
return -1;
- }
- else if(s1->st_mtim.tv_nsec > s2->st_mtim.tv_nsec)
- {
+ } else if (s1->st_mtim.tv_nsec > s2->st_mtim.tv_nsec) {
return 1;
- }
-# elif CMake_STAT_HAS_ST_MTIMESPEC
+ }
+#elif CMake_STAT_HAS_ST_MTIMESPEC
// Compare using nanosecond resolution.
- if(s1->st_mtimespec.tv_sec < s2->st_mtimespec.tv_sec)
- {
+ if (s1->st_mtimespec.tv_sec < s2->st_mtimespec.tv_sec) {
return -1;
- }
- else if(s1->st_mtimespec.tv_sec > s2->st_mtimespec.tv_sec)
- {
+ } else if (s1->st_mtimespec.tv_sec > s2->st_mtimespec.tv_sec) {
return 1;
- }
- else if(s1->st_mtimespec.tv_nsec < s2->st_mtimespec.tv_nsec)
- {
+ } else if (s1->st_mtimespec.tv_nsec < s2->st_mtimespec.tv_nsec) {
return -1;
- }
- else if(s1->st_mtimespec.tv_nsec > s2->st_mtimespec.tv_nsec)
- {
+ } else if (s1->st_mtimespec.tv_nsec > s2->st_mtimespec.tv_nsec) {
return 1;
- }
-# else
+ }
+#else
// Compare using 1 second resolution.
- if(s1->st_mtime < s2->st_mtime)
- {
+ if (s1->st_mtime < s2->st_mtime) {
return -1;
- }
- else if(s1->st_mtime > s2->st_mtime)
- {
+ } else if (s1->st_mtime > s2->st_mtime) {
return 1;
- }
-# endif
+ }
+#endif
// Files have the same time.
return 0;
#else
@@ -200,55 +178,40 @@ bool cmFileTimeComparisonInternal::TimesDiffer(cmFileTimeComparison_Type* s1,
cmFileTimeComparison_Type* s2)
{
#if !defined(_WIN32) || defined(__CYGWIN__)
-# if CMake_STAT_HAS_ST_MTIM
+#if CMake_STAT_HAS_ST_MTIM
// Times are integers in units of 1ns.
long long bil = 1000000000;
long long t1 = s1->st_mtim.tv_sec * bil + s1->st_mtim.tv_nsec;
long long t2 = s2->st_mtim.tv_sec * bil + s2->st_mtim.tv_nsec;
- if(t1 < t2)
- {
+ if (t1 < t2) {
return (t2 - t1) >= bil;
- }
- else if(t2 < t1)
- {
+ } else if (t2 < t1) {
return (t1 - t2) >= bil;
- }
- else
- {
+ } else {
return false;
- }
-# elif CMake_STAT_HAS_ST_MTIMESPEC
+ }
+#elif CMake_STAT_HAS_ST_MTIMESPEC
// Times are integers in units of 1ns.
long long bil = 1000000000;
long long t1 = s1->st_mtimespec.tv_sec * bil + s1->st_mtimespec.tv_nsec;
long long t2 = s2->st_mtimespec.tv_sec * bil + s2->st_mtimespec.tv_nsec;
- if(t1 < t2)
- {
+ if (t1 < t2) {
return (t2 - t1) >= bil;
- }
- else if(t2 < t1)
- {
+ } else if (t2 < t1) {
return (t1 - t2) >= bil;
- }
- else
- {
+ } else {
return false;
- }
-# else
+ }
+#else
// Times are integers in units of 1s.
- if(s1->st_mtime < s2->st_mtime)
- {
+ if (s1->st_mtime < s2->st_mtime) {
return (s2->st_mtime - s1->st_mtime) >= 1;
- }
- else if(s1->st_mtime > s2->st_mtime)
- {
+ } else if (s1->st_mtime > s2->st_mtime) {
return (s1->st_mtime - s2->st_mtime) >= 1;
- }
- else
- {
+ } else {
return false;
- }
-# endif
+ }
+#endif
#else
// Times are integers in units of 100ns.
LARGE_INTEGER t1;
@@ -257,41 +220,31 @@ bool cmFileTimeComparisonInternal::TimesDiffer(cmFileTimeComparison_Type* s1,
t1.HighPart = s1->dwHighDateTime;
t2.LowPart = s2->dwLowDateTime;
t2.HighPart = s2->dwHighDateTime;
- if(t1.QuadPart < t2.QuadPart)
- {
+ if (t1.QuadPart < t2.QuadPart) {
return (t2.QuadPart - t1.QuadPart) >= static_cast<LONGLONG>(10000000);
- }
- else if(t2.QuadPart < t1.QuadPart)
- {
+ } else if (t2.QuadPart < t1.QuadPart) {
return (t1.QuadPart - t2.QuadPart) >= static_cast<LONGLONG>(10000000);
- }
- else
- {
+ } else {
return false;
- }
+ }
#endif
}
bool cmFileTimeComparisonInternal::FileTimeCompare(const char* f1,
- const char* f2,
- int* result)
+ const char* f2, int* result)
{
// Get the modification time for each file.
cmFileTimeComparison_Type s1;
cmFileTimeComparison_Type s2;
- if(this->Stat(f1, &s1) &&
- this->Stat(f2, &s2))
- {
+ if (this->Stat(f1, &s1) && this->Stat(f2, &s2)) {
// Compare the two modification times.
*result = this->Compare(&s1, &s2);
return true;
- }
- else
- {
+ } else {
// No comparison available. Default to the same time.
*result = 0;
return false;
- }
+ }
}
bool cmFileTimeComparisonInternal::FileTimesDiffer(const char* f1,
@@ -300,15 +253,11 @@ bool cmFileTimeComparisonInternal::FileTimesDiffer(const char* f1,
// Get the modification time for each file.
cmFileTimeComparison_Type s1;
cmFileTimeComparison_Type s2;
- if(this->Stat(f1, &s1) &&
- this->Stat(f2, &s2))
- {
+ if (this->Stat(f1, &s1) && this->Stat(f2, &s2)) {
// Compare the two modification times.
return this->TimesDiffer(&s1, &s2);
- }
- else
- {
+ } else {
// No comparison available. Default to different times.
return true;
- }
+ }
}