summaryrefslogtreecommitdiffstats
path: root/Source/cmGeneratedFileStream.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/cmGeneratedFileStream.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/cmGeneratedFileStream.cxx')
-rw-r--r--Source/cmGeneratedFileStream.cxx118
1 files changed, 51 insertions, 67 deletions
diff --git a/Source/cmGeneratedFileStream.cxx b/Source/cmGeneratedFileStream.cxx
index 78d863c..2c05913 100644
--- a/Source/cmGeneratedFileStream.cxx
+++ b/Source/cmGeneratedFileStream.cxx
@@ -14,25 +14,25 @@
#include "cmSystemTools.h"
#if defined(CMAKE_BUILD_WITH_CMAKE)
-# include <cm_zlib.h>
+#include <cm_zlib.h>
#endif
-cmGeneratedFileStream::cmGeneratedFileStream():
- cmGeneratedFileStreamBase(), Stream()
+cmGeneratedFileStream::cmGeneratedFileStream()
+ : cmGeneratedFileStreamBase()
+ , Stream()
{
}
-cmGeneratedFileStream::cmGeneratedFileStream(const char* name, bool quiet):
- cmGeneratedFileStreamBase(name),
- Stream(TempName.c_str())
+cmGeneratedFileStream::cmGeneratedFileStream(const char* name, bool quiet)
+ : cmGeneratedFileStreamBase(name)
+ , Stream(TempName.c_str())
{
// Check if the file opened.
- if(!*this && !quiet)
- {
+ if (!*this && !quiet) {
cmSystemTools::Error("Cannot open file for write: ",
this->TempName.c_str());
cmSystemTools::ReportLastSystemError("");
- }
+ }
}
cmGeneratedFileStream::~cmGeneratedFileStream()
@@ -42,41 +42,36 @@ cmGeneratedFileStream::~cmGeneratedFileStream()
// stream will be destroyed which will close the temporary file.
// Finally the base destructor will be called to replace the
// destination file.
- this->Okay = (*this)?true:false;
+ this->Okay = (*this) ? true : false;
}
-cmGeneratedFileStream&
-cmGeneratedFileStream::Open(const char* name, bool quiet, bool binaryFlag)
+cmGeneratedFileStream& cmGeneratedFileStream::Open(const char* name,
+ bool quiet, bool binaryFlag)
{
// Store the file name and construct the temporary file name.
this->cmGeneratedFileStreamBase::Open(name);
// Open the temporary output file.
- if ( binaryFlag )
- {
+ if (binaryFlag) {
this->Stream::open(this->TempName.c_str(),
std::ios::out | std::ios::binary);
- }
- else
- {
+ } else {
this->Stream::open(this->TempName.c_str(), std::ios::out);
- }
+ }
// Check if the file opened.
- if(!*this && !quiet)
- {
+ if (!*this && !quiet) {
cmSystemTools::Error("Cannot open file for write: ",
this->TempName.c_str());
cmSystemTools::ReportLastSystemError("");
- }
+ }
return *this;
}
-bool
-cmGeneratedFileStream::Close()
+bool cmGeneratedFileStream::Close()
{
// Save whether the temporary output file is valid before closing.
- this->Okay = (*this)?true:false;
+ this->Okay = (*this) ? true : false;
// Close the temporary output file.
this->Stream::close();
@@ -100,23 +95,23 @@ void cmGeneratedFileStream::SetCompressionExtraExtension(bool ext)
this->CompressExtraExtension = ext;
}
-cmGeneratedFileStreamBase::cmGeneratedFileStreamBase():
- Name(),
- TempName(),
- CopyIfDifferent(false),
- Okay(false),
- Compress(false),
- CompressExtraExtension(true)
+cmGeneratedFileStreamBase::cmGeneratedFileStreamBase()
+ : Name()
+ , TempName()
+ , CopyIfDifferent(false)
+ , Okay(false)
+ , Compress(false)
+ , CompressExtraExtension(true)
{
}
-cmGeneratedFileStreamBase::cmGeneratedFileStreamBase(const char* name):
- Name(),
- TempName(),
- CopyIfDifferent(false),
- Okay(false),
- Compress(false),
- CompressExtraExtension(true)
+cmGeneratedFileStreamBase::cmGeneratedFileStreamBase(const char* name)
+ : Name()
+ , TempName()
+ , CopyIfDifferent(false)
+ , Okay(false)
+ , Compress(false)
+ , CompressExtraExtension(true)
{
this->Open(name);
}
@@ -151,36 +146,29 @@ bool cmGeneratedFileStreamBase::Close()
bool replaced = false;
std::string resname = this->Name;
- if ( this->Compress && this->CompressExtraExtension )
- {
+ if (this->Compress && this->CompressExtraExtension) {
resname += ".gz";
- }
+ }
// Only consider replacing the destination file if no error
// occurred.
- if(!this->Name.empty() &&
- this->Okay &&
- (!this->CopyIfDifferent ||
- cmSystemTools::FilesDiffer(this->TempName, resname)))
- {
+ if (!this->Name.empty() && this->Okay &&
+ (!this->CopyIfDifferent ||
+ cmSystemTools::FilesDiffer(this->TempName, resname))) {
// The destination is to be replaced. Rename the temporary to the
// destination atomically.
- if ( this->Compress )
- {
+ if (this->Compress) {
std::string gzname = this->TempName + ".temp.gz";
- if ( this->CompressFile(this->TempName.c_str(), gzname.c_str()) )
- {
+ if (this->CompressFile(this->TempName.c_str(), gzname.c_str())) {
this->RenameFile(gzname.c_str(), resname.c_str());
- }
- cmSystemTools::RemoveFile(gzname);
}
- else
- {
+ cmSystemTools::RemoveFile(gzname);
+ } else {
this->RenameFile(this->TempName.c_str(), resname.c_str());
- }
+ }
replaced = true;
- }
+ }
// Else, the destination was not replaced.
//
@@ -195,27 +183,23 @@ int cmGeneratedFileStreamBase::CompressFile(const char* oldname,
const char* newname)
{
gzFile gf = gzopen(newname, "w");
- if ( !gf )
- {
+ if (!gf) {
return 0;
- }
+ }
FILE* ifs = cmsys::SystemTools::Fopen(oldname, "r");
- if ( !ifs )
- {
+ if (!ifs) {
return 0;
- }
+ }
size_t res;
const size_t BUFFER_SIZE = 1024;
char buffer[BUFFER_SIZE];
- while ( (res = fread(buffer, 1, BUFFER_SIZE, ifs)) > 0 )
- {
- if ( !gzwrite(gf, buffer, static_cast<int>(res)) )
- {
+ while ((res = fread(buffer, 1, BUFFER_SIZE, ifs)) > 0) {
+ if (!gzwrite(gf, buffer, static_cast<int>(res))) {
fclose(ifs);
gzclose(gf);
return 0;
- }
}
+ }
fclose(ifs);
gzclose(gf);
return 1;